1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_HXX
21 #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_HXX
23 #include <com/sun/star/drawing/LineJoint.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <com/sun/star/task/XStatusIndicator.hpp>
26 #include <com/sun/star/geometry/RealSize2D.hpp>
27 #include <com/sun/star/geometry/RealRectangle2D.hpp>
28 #include <com/sun/star/geometry/Matrix2D.hpp>
30 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <rtl/ustring.hxx>
35 #include <unordered_map>
37 #include "imagecontainer.hxx"
38 #include "contentsink.hxx"
39 #include "treevisitorfactory.hxx"
40 #include "genericelements.hxx"
47 struct DocumentElement
;
53 /** Main entry from the parser
55 Creates the internal DOM tree from the render calls
57 class PDFIProcessor final
: public ContentSink
61 css::uno::XComponentContext
> m_xContext
;
62 basegfx::B2DHomMatrix prevTextMatrix
;
65 explicit PDFIProcessor( const css::uno::Reference
< css::task::XStatusIndicator
>& xStat
,
66 css::uno::Reference
< css::uno::XComponentContext
> const & xContext
) ;
68 void emit( XmlEmitter
& rEmitter
,
69 const TreeVisitorFactory
& rVisitorFactory
);
71 sal_Int32
getGCId( const GraphicsContext
& rGC
);
72 const GraphicsContext
& getGraphicsContext( sal_Int32 nGCId
) const;
73 GraphicsContext
& getCurrentContext() { return m_aGCStack
.back(); }
74 const GraphicsContext
& getCurrentContext() const { return m_aGCStack
.back(); }
75 const ImageContainer
& getImages() const { return m_aImages
; };
77 const css::uno::Reference
< css::task::XStatusIndicator
>& getStatusIndicator() const
78 { return m_xStatusIndicator
; }
80 const FontAttributes
& getFont( sal_Int32 nFontId
) const;
81 sal_Int32
getFontId( const FontAttributes
& rAttr
) const;
83 static void sortElements( Element
* pElement
);
85 static OUString
SubstituteBidiMirrored(std::u16string_view rString
);
88 void processGlyphLine();
90 // ContentSink interface implementation
92 virtual void setPageNum( sal_Int32 nNumPages
) override
;
93 virtual void startPage( const css::geometry::RealSize2D
& rSize
) override
;
94 virtual void endPage() override
;
96 virtual void hyperLink( const css::geometry::RealRectangle2D
& rBounds
,
97 const OUString
& rURI
) override
;
98 virtual void pushState() override
;
99 virtual void popState() override
;
100 virtual void setFlatness( double ) override
;
101 virtual void setTransformation( const css::geometry::AffineMatrix2D
& rMatrix
) override
;
102 virtual void setLineDash( const css::uno::Sequence
<double>& dashes
,
103 double start
) override
;
104 virtual void setLineJoin(basegfx::B2DLineJoin
) override
;
105 virtual void setLineCap(sal_Int8
) override
;
106 virtual void setMiterLimit(double) override
;
107 virtual void setLineWidth(double) override
;
108 virtual void setFillColor( const css::rendering::ARGBColor
& rColor
) override
;
109 virtual void setStrokeColor( const css::rendering::ARGBColor
& rColor
) override
;
110 virtual void setFont( const FontAttributes
& rFont
) override
;
111 virtual void setTextRenderMode( sal_Int32
) override
;
113 virtual void strokePath( const css::uno::Reference
<
114 css::rendering::XPolyPolygon2D
>& rPath
) override
;
115 virtual void fillPath( const css::uno::Reference
<
116 css::rendering::XPolyPolygon2D
>& rPath
) override
;
117 virtual void eoFillPath( const css::uno::Reference
<
118 css::rendering::XPolyPolygon2D
>& rPath
) override
;
120 virtual void intersectClip(const css::uno::Reference
<
121 css::rendering::XPolyPolygon2D
>& rPath
) override
;
122 virtual void intersectClipToStroke(const css::uno::Reference
<
123 css::rendering::XPolyPolygon2D
>& rPath
) override
;
124 virtual void intersectEoClip(const css::uno::Reference
<
125 css::rendering::XPolyPolygon2D
>& rPath
) override
;
127 virtual void drawGlyphs( const OUString
& rGlyphs
,
128 const css::geometry::RealRectangle2D
& rRect
,
129 const css::geometry::Matrix2D
& rFontMatrix
,
130 double fontSize
) override
;
131 virtual void endText() override
;
133 virtual void drawMask(const css::uno::Sequence
<
134 css::beans::PropertyValue
>& xBitmap
,
135 bool bInvert
) override
;
136 /// Given image must already be color-mapped and normalized to sRGB.
137 virtual void drawImage(const css::uno::Sequence
<
138 css::beans::PropertyValue
>& xBitmap
) override
;
139 /** Given image must already be color-mapped and normalized to sRGB.
141 maskColors must contain two sequences of color components
143 virtual void drawColorMaskedImage(const css::uno::Sequence
<
144 css::beans::PropertyValue
>& xBitmap
,
145 const css::uno::Sequence
<
146 css::uno::Any
>& xMaskColors
) override
;
147 virtual void drawMaskedImage(const css::uno::Sequence
<
148 css::beans::PropertyValue
>& xBitmap
,
149 const css::uno::Sequence
<
150 css::beans::PropertyValue
>& xMask
,
151 bool bInvertMask
) override
;
152 virtual void drawAlphaMaskedImage(const css::uno::Sequence
<
153 css::beans::PropertyValue
>& xImage
,
154 const css::uno::Sequence
<
155 css::beans::PropertyValue
>& xMask
) override
;
157 virtual void tilingPatternFill(int nX0
, int nY0
, int nX1
, int nY1
,
158 double nxStep
, double nyStep
,
160 css::geometry::AffineMatrix2D
& rMat
,
161 const css::uno::Sequence
<css::beans::PropertyValue
>& xTile
) override
;
163 void startIndicator( const OUString
& rText
);
166 void setupImage(ImageId nImage
);
168 typedef std::unordered_map
<sal_Int32
,FontAttributes
> IdToFontMap
;
169 typedef std::unordered_map
<FontAttributes
,sal_Int32
,FontAttrHash
> FontToIdMap
;
171 typedef std::unordered_map
<sal_Int32
,GraphicsContext
> IdToGCMap
;
172 typedef std::unordered_map
<GraphicsContext
, sal_Int32
, GraphicsContextHash
> GCToIdMap
;
174 typedef std::vector
<GraphicsContext
> GraphicsContextStack
;
176 std::vector
<CharGlyph
> m_GlyphsList
;
178 std::shared_ptr
<DocumentElement
> m_pDocument
;
179 PageElement
* m_pCurPage
;
180 Element
* m_pCurElement
;
181 sal_Int32 m_nNextFontId
;
182 IdToFontMap m_aIdToFont
;
183 FontToIdMap m_aFontToId
;
185 GraphicsContextStack m_aGCStack
;
186 sal_Int32 m_nNextGCId
;
190 ImageContainer m_aImages
;
193 sal_Int32 m_nNextZOrder
;
194 css::uno::Reference
< css::task::XStatusIndicator
>
197 class CharGlyph final
200 CharGlyph(Element
* pCurElement
, const GraphicsContext
& rCurrentContext
,
201 double width
, double prevSpaceWidth
, const OUString
& rGlyphs
)
202 : m_pCurElement(pCurElement
), m_rCurrentContext(rCurrentContext
),
203 m_Width(width
), m_PrevSpaceWidth(prevSpaceWidth
), m_rGlyphs(rGlyphs
) {};
205 OUString
& getGlyph(){ return m_rGlyphs
; }
206 double getWidth() const { return m_Width
; }
207 double getPrevSpaceWidth() const { return m_PrevSpaceWidth
; }
208 GraphicsContext
& getGC(){ return m_rCurrentContext
; }
209 Element
* getCurElement(){ return m_pCurElement
; }
212 Element
* m_pCurElement
;
213 GraphicsContext m_rCurrentContext
;
215 double m_PrevSpaceWidth
;
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */