LibreOffice Module sdext (master) 1
pdfiprocessor.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_HXX
21#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_HXX
22
23#include <com/sun/star/uno/XComponentContext.hpp>
24#include <com/sun/star/task/XStatusIndicator.hpp>
25#include <com/sun/star/geometry/RealSize2D.hpp>
26#include <com/sun/star/geometry/RealRectangle2D.hpp>
27#include <com/sun/star/geometry/Matrix2D.hpp>
28
30
31#include <rtl/ustring.hxx>
32
33#include <memory>
34#include <unordered_map>
35
36#include "imagecontainer.hxx"
37#include "contentsink.hxx"
39#include "genericelements.hxx"
40
41namespace pdfi
42{
43
44 class PDFIProcessor;
45 struct Element;
46 struct DocumentElement;
47 struct PageElement;
48 class ElementFactory;
49 class XmlEmitter;
50 class CharGlyph;
51
56 class PDFIProcessor final : public ContentSink
57 {
58 public:
59 css::uno::Reference<
60 css::uno::XComponentContext > m_xContext;
63
64 explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat,
65 css::uno::Reference< css::uno::XComponentContext > const & xContext) ;
66
67 void emit( XmlEmitter& rEmitter,
68 const TreeVisitorFactory& rVisitorFactory );
69
70 sal_Int32 getGCId( const GraphicsContext& rGC );
71 const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
73 const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
74
75 const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const
76 { return m_xStatusIndicator; }
77
78 const FontAttributes& getFont( sal_Int32 nFontId ) const;
79 sal_Int32 getFontId( const FontAttributes& rAttr ) const;
80
81 static void sortElements( Element* pElement );
82
83 static OUString SubstituteBidiMirrored(const OUString& rString);
84
85 private:
86 void processGlyphLine();
87
88 // ContentSink interface implementation
89
90 virtual void setPageNum( sal_Int32 nNumPages ) override;
91 virtual void startPage( const css::geometry::RealSize2D& rSize ) override;
92 virtual void endPage() override;
93
94 virtual void hyperLink( const css::geometry::RealRectangle2D& rBounds,
95 const OUString& rURI ) override;
96 virtual void pushState() override;
97 virtual void popState() override;
98 virtual void setFlatness( double ) override;
99 virtual void setTransformation( const css::geometry::AffineMatrix2D& rMatrix ) override;
100 virtual void setLineDash( const css::uno::Sequence<double>& dashes,
101 double start ) override;
102 virtual void setLineJoin(sal_Int8) override;
103 virtual void setLineCap(sal_Int8) override;
104 virtual void setMiterLimit(double) override;
105 virtual void setLineWidth(double) override;
106 virtual void setFillColor( const css::rendering::ARGBColor& rColor ) override;
107 virtual void setStrokeColor( const css::rendering::ARGBColor& rColor ) override;
108 virtual void setFont( const FontAttributes& rFont ) override;
109 virtual void setTextRenderMode( sal_Int32 ) override;
110
111 virtual void strokePath( const css::uno::Reference<
112 css::rendering::XPolyPolygon2D >& rPath ) override;
113 virtual void fillPath( const css::uno::Reference<
114 css::rendering::XPolyPolygon2D >& rPath ) override;
115 virtual void eoFillPath( const css::uno::Reference<
116 css::rendering::XPolyPolygon2D >& rPath ) override;
117
118 virtual void intersectClip(const css::uno::Reference<
119 css::rendering::XPolyPolygon2D >& rPath) override;
120 virtual void intersectEoClip(const css::uno::Reference<
121 css::rendering::XPolyPolygon2D >& rPath) override;
122
123 virtual void drawGlyphs( const OUString& rGlyphs,
124 const css::geometry::RealRectangle2D& rRect,
125 const css::geometry::Matrix2D& rFontMatrix,
126 double fontSize) override;
127 virtual void endText() override;
128
129 virtual void drawMask(const css::uno::Sequence<
130 css::beans::PropertyValue>& xBitmap,
131 bool bInvert ) override;
133 virtual void drawImage(const css::uno::Sequence<
134 css::beans::PropertyValue>& xBitmap ) override;
139 virtual void drawColorMaskedImage(const css::uno::Sequence<
140 css::beans::PropertyValue>& xBitmap,
141 const css::uno::Sequence<
142 css::uno::Any>& xMaskColors ) override;
143 virtual void drawMaskedImage(const css::uno::Sequence<
144 css::beans::PropertyValue>& xBitmap,
145 const css::uno::Sequence<
146 css::beans::PropertyValue>& xMask,
147 bool bInvertMask) override;
148 virtual void drawAlphaMaskedImage(const css::uno::Sequence<
149 css::beans::PropertyValue>& xImage,
150 const css::uno::Sequence<
151 css::beans::PropertyValue>& xMask) override;
152
153 void startIndicator( const OUString& rText );
154 void endIndicator();
155
156 void setupImage(ImageId nImage);
157
158 typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
159 typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
160
161 typedef std::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
162 typedef std::unordered_map<GraphicsContext, sal_Int32, GraphicsContextHash> GCToIdMap;
163
164 typedef std::vector<GraphicsContext> GraphicsContextStack;
165
166 std::vector<CharGlyph> m_GlyphsList;
167
168 std::shared_ptr<DocumentElement> m_pDocument;
171 sal_Int32 m_nNextFontId;
174
176 sal_Int32 m_nNextGCId;
179
181
182 sal_Int32 m_nPages;
183 sal_Int32 m_nNextZOrder;
184 css::uno::Reference< css::task::XStatusIndicator >
186 };
187 class CharGlyph final
188 {
189 public:
190 CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext,
191 double width, double prevSpaceWidth, const OUString& rGlyphs )
192 : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
193 m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {};
194
195 OUString& getGlyph(){ return m_rGlyphs; }
196 double getWidth() const { return m_Width; }
197 double getPrevSpaceWidth() const { return m_PrevSpaceWidth; }
200
201 private:
204 double m_Width ;
206 OUString m_rGlyphs ;
207 };
208}
209
210#endif
211
212/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CharGlyph(Element *pCurElement, const GraphicsContext &rCurrentContext, double width, double prevSpaceWidth, const OUString &rGlyphs)
Element * m_pCurElement
GraphicsContext m_rCurrentContext
double getWidth() const
OUString & getGlyph()
double getPrevSpaceWidth() const
Element * getCurElement()
GraphicsContext & getGC()
Main entry from the parser.
ImageContainer m_aImages
void startIndicator(const OUString &rText)
std::unordered_map< FontAttributes, sal_Int32, FontAttrHash > FontToIdMap
std::vector< CharGlyph > m_GlyphsList
virtual void setLineWidth(double) override
virtual void drawColorMaskedImage(const css::uno::Sequence< css::beans::PropertyValue > &xBitmap, const css::uno::Sequence< css::uno::Any > &xMaskColors) override
Given image must already be color-mapped and normalized to sRGB.
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void setFlatness(double) override
virtual void setTransformation(const css::geometry::AffineMatrix2D &rMatrix) override
virtual void setMiterLimit(double) override
const GraphicsContext & getGraphicsContext(sal_Int32 nGCId) const
virtual void intersectClip(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
std::unordered_map< sal_Int32, GraphicsContext > IdToGCMap
virtual void setLineDash(const css::uno::Sequence< double > &dashes, double start) override
virtual void popState() override
virtual void hyperLink(const css::geometry::RealRectangle2D &rBounds, const OUString &rURI) override
basegfx::B2DHomMatrix prevTextMatrix
const FontAttributes & getFont(sal_Int32 nFontId) const
virtual void setPageNum(sal_Int32 nNumPages) override
Total number of pages for upcoming document.
virtual void strokePath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
sal_Int32 getFontId(const FontAttributes &rAttr) const
virtual void setLineCap(sal_Int8) override
const css::uno::Reference< css::task::XStatusIndicator > & getStatusIndicator() const
virtual void pushState() override
std::unordered_map< sal_Int32, FontAttributes > IdToFontMap
void setupImage(ImageId nImage)
static void sortElements(Element *pElement)
PDFIProcessor(const css::uno::Reference< css::task::XStatusIndicator > &xStat, css::uno::Reference< css::uno::XComponentContext > const &xContext)
const GraphicsContext & getCurrentContext() const
virtual void endPage() override
std::vector< GraphicsContext > GraphicsContextStack
virtual void intersectEoClip(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
virtual void drawMask(const css::uno::Sequence< css::beans::PropertyValue > &xBitmap, bool bInvert) override
draws given bitmap as a mask (using current fill color)
virtual void setStrokeColor(const css::rendering::ARGBColor &rColor) override
PageElement * m_pCurPage
virtual void drawMaskedImage(const css::uno::Sequence< css::beans::PropertyValue > &xBitmap, const css::uno::Sequence< css::beans::PropertyValue > &xMask, bool bInvertMask) override
static OUString SubstituteBidiMirrored(const OUString &rString)
GraphicsContext & getCurrentContext()
virtual void setLineJoin(sal_Int8) override
virtual void setFillColor(const css::rendering::ARGBColor &rColor) override
std::unordered_map< GraphicsContext, sal_Int32, GraphicsContextHash > GCToIdMap
GraphicsContextStack m_aGCStack
std::shared_ptr< DocumentElement > m_pDocument
virtual void setTextRenderMode(sal_Int32) override
virtual void eoFillPath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
sal_Int32 getGCId(const GraphicsContext &rGC)
virtual void drawGlyphs(const OUString &rGlyphs, const css::geometry::RealRectangle2D &rRect, const css::geometry::Matrix2D &rFontMatrix, double fontSize) override
virtual void drawAlphaMaskedImage(const css::uno::Sequence< css::beans::PropertyValue > &xImage, const css::uno::Sequence< css::beans::PropertyValue > &xMask) override
css::uno::Reference< css::task::XStatusIndicator > m_xStatusIndicator
virtual void startPage(const css::geometry::RealSize2D &rSize) override
virtual void endText() override
issued when a sequence of associated glyphs is drawn
virtual void setFont(const FontAttributes &rFont) override
virtual void drawImage(const css::uno::Sequence< css::beans::PropertyValue > &xBitmap) override
Given image must already be color-mapped and normalized to sRGB.
virtual void fillPath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
void emit(XmlEmitter &rEmitter, const TreeVisitorFactory &rVisitorFactory)
Output interface to ODF.
Definition: xmlemitter.hxx:33
sal_Int32 ImageId
Definition: pdfihelper.hxx:45
(preliminary) API wrapper around xpdf
Tree manipulation factory.
signed char sal_Int8