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/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>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <rtl/ustring.hxx>
34 #include <unordered_map>
36 #include "imagecontainer.hxx"
37 #include "contentsink.hxx"
38 #include "treevisitorfactory.hxx"
39 #include "genericelements.hxx"
46 struct DocumentElement
;
52 /** Main entry from the parser
54 Creates the internal DOM tree from the render calls
56 class PDFIProcessor final
: public ContentSink
60 css::uno::XComponentContext
> m_xContext
;
61 basegfx::B2DHomMatrix prevTextMatrix
;
64 explicit PDFIProcessor( const css::uno::Reference
< css::task::XStatusIndicator
>& xStat
,
65 css::uno::Reference
< css::uno::XComponentContext
> const & xContext
) ;
67 void emit( XmlEmitter
& rEmitter
,
68 const TreeVisitorFactory
& rVisitorFactory
);
70 sal_Int32
getGCId( const GraphicsContext
& rGC
);
71 const GraphicsContext
& getGraphicsContext( sal_Int32 nGCId
) const;
72 GraphicsContext
& getCurrentContext() { return m_aGCStack
.back(); }
73 const GraphicsContext
& getCurrentContext() const { return m_aGCStack
.back(); }
75 const css::uno::Reference
< css::task::XStatusIndicator
>& getStatusIndicator() const
76 { return m_xStatusIndicator
; }
78 const FontAttributes
& getFont( sal_Int32 nFontId
) const;
79 sal_Int32
getFontId( const FontAttributes
& rAttr
) const;
81 static void sortElements( Element
* pElement
);
83 static OUString
SubstituteBidiMirrored(const OUString
& rString
);
86 void processGlyphLine();
88 // ContentSink interface implementation
90 virtual void setPageNum( sal_Int32 nNumPages
) override
;
91 virtual void startPage( const css::geometry::RealSize2D
& rSize
) override
;
92 virtual void endPage() override
;
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
;
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
;
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
;
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
;
129 virtual void drawMask(const css::uno::Sequence
<
130 css::beans::PropertyValue
>& xBitmap
,
131 bool bInvert
) override
;
132 /// Given image must already be color-mapped and normalized to sRGB.
133 virtual void drawImage(const css::uno::Sequence
<
134 css::beans::PropertyValue
>& xBitmap
) override
;
135 /** Given image must already be color-mapped and normalized to sRGB.
137 maskColors must contain two sequences of color components
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
;
153 void startIndicator( const OUString
& rText
);
156 void setupImage(ImageId nImage
);
158 typedef std::unordered_map
<sal_Int32
,FontAttributes
> IdToFontMap
;
159 typedef std::unordered_map
<FontAttributes
,sal_Int32
,FontAttrHash
> FontToIdMap
;
161 typedef std::unordered_map
<sal_Int32
,GraphicsContext
> IdToGCMap
;
162 typedef std::unordered_map
<GraphicsContext
, sal_Int32
, GraphicsContextHash
> GCToIdMap
;
164 typedef std::vector
<GraphicsContext
> GraphicsContextStack
;
166 std::vector
<CharGlyph
> m_GlyphsList
;
168 std::shared_ptr
<DocumentElement
> m_pDocument
;
169 PageElement
* m_pCurPage
;
170 Element
* m_pCurElement
;
171 sal_Int32 m_nNextFontId
;
172 IdToFontMap m_aIdToFont
;
173 FontToIdMap m_aFontToId
;
175 GraphicsContextStack m_aGCStack
;
176 sal_Int32 m_nNextGCId
;
180 ImageContainer m_aImages
;
183 sal_Int32 m_nNextZOrder
;
184 css::uno::Reference
< css::task::XStatusIndicator
>
187 class CharGlyph final
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
) {};
195 OUString
& getGlyph(){ return m_rGlyphs
; }
196 double getWidth() const { return m_Width
; }
197 double getPrevSpaceWidth() const { return m_PrevSpaceWidth
; }
198 GraphicsContext
& getGC(){ return m_rCurrentContext
; }
199 Element
* getCurElement(){ return m_pCurElement
; }
202 Element
* m_pCurElement
;
203 GraphicsContext m_rCurrentContext
;
205 double m_PrevSpaceWidth
;
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */