Line data Source code
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_TREE_PDFIPROCESSOR_HXX
21 : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_PDFIPROCESSOR_HXX
22 :
23 : #include <com/sun/star/util/XStringMapping.hpp>
24 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
25 : #include <com/sun/star/task/XStatusIndicator.hpp>
26 : #include <com/sun/star/rendering/XVolatileBitmap.hpp>
27 : #include <com/sun/star/geometry/RealSize2D.hpp>
28 : #include <com/sun/star/geometry/RealPoint2D.hpp>
29 : #include <com/sun/star/geometry/RealRectangle2D.hpp>
30 : #include <com/sun/star/geometry/Matrix2D.hpp>
31 :
32 : #include <basegfx/polygon/b2dpolypolygon.hxx>
33 : #include <basegfx/polygon/b2dpolygon.hxx>
34 : #include <basegfx/matrix/b2dhommatrix.hxx>
35 : #include <basegfx/range/b2drange.hxx>
36 :
37 : #include <rtl/ustring.hxx>
38 : #include <rtl/ustrbuf.hxx>
39 :
40 : #include <boost/shared_ptr.hpp>
41 : #include <list>
42 : #include <unordered_map>
43 :
44 : #include "imagecontainer.hxx"
45 : #include "contentsink.hxx"
46 : #include "treevisitorfactory.hxx"
47 : #include "genericelements.hxx"
48 :
49 : namespace pdfi
50 : {
51 :
52 : class PDFIProcessor;
53 : struct Element;
54 : struct DocumentElement;
55 : struct PageElement;
56 : class ElementFactory;
57 : class XmlEmitter;
58 : class CharGlyph;
59 :
60 : /** Main entry from the parser
61 :
62 : Creates the internal DOM tree from the render calls
63 : */
64 8 : class PDFIProcessor : public ContentSink
65 : {
66 : public:
67 : css::uno::Reference<
68 : css::uno::XComponentContext > m_xContext;
69 : basegfx::B2DHomMatrix prevTextMatrix;
70 : double prevCharWidth;
71 : enum DocumentTextDirecion { LrTb, RlTb, TbLr };
72 :
73 : explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat,
74 : css::uno::Reference< css::uno::XComponentContext > xContext) ;
75 :
76 : /// TEMP - enable writer-like text:p on doc level
77 : void enableToplevelText();
78 :
79 : void emit( XmlEmitter& rEmitter,
80 : const TreeVisitorFactory& rVisitorFactory );
81 :
82 : sal_Int32 getGCId( const GraphicsContext& rGC );
83 : const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
84 1289 : GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
85 0 : const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
86 :
87 : ImageContainer& getImages() { return m_aImages; }
88 : boost::shared_ptr<ElementFactory> getElementFactory() const { return m_pElFactory; }
89 :
90 8 : const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const
91 8 : { return m_xStatusIndicator; }
92 : void setStatusIndicator( const css::uno::Reference< css::task::XStatusIndicator >& xStatus )
93 : { m_xStatusIndicator = xStatus; }
94 :
95 : const FontAttributes& getFont( sal_Int32 nFontId ) const;
96 : sal_Int32 getFontId( const FontAttributes& rAttr ) const;
97 :
98 : void sortElements( Element* pElement, bool bDeep = false );
99 :
100 : static OUString mirrorString( const OUString& i_rInString );
101 :
102 : private:
103 : void processGlyphLine();
104 :
105 : // ContentSink interface implementation
106 :
107 : virtual void setPageNum( sal_Int32 nNumPages ) SAL_OVERRIDE;
108 : virtual void startPage( const css::geometry::RealSize2D& rSize ) SAL_OVERRIDE;
109 : virtual void endPage() SAL_OVERRIDE;
110 :
111 : virtual void hyperLink( const css::geometry::RealRectangle2D& rBounds,
112 : const OUString& rURI ) SAL_OVERRIDE;
113 : virtual void pushState() SAL_OVERRIDE;
114 : virtual void popState() SAL_OVERRIDE;
115 : virtual void setFlatness( double ) SAL_OVERRIDE;
116 : virtual void setTransformation( const css::geometry::AffineMatrix2D& rMatrix ) SAL_OVERRIDE;
117 : virtual void setLineDash( const css::uno::Sequence<double>& dashes,
118 : double start ) SAL_OVERRIDE;
119 : virtual void setLineJoin(sal_Int8) SAL_OVERRIDE;
120 : virtual void setLineCap(sal_Int8) SAL_OVERRIDE;
121 : virtual void setMiterLimit(double) SAL_OVERRIDE;
122 : virtual void setLineWidth(double) SAL_OVERRIDE;
123 : virtual void setFillColor( const css::rendering::ARGBColor& rColor ) SAL_OVERRIDE;
124 : virtual void setStrokeColor( const css::rendering::ARGBColor& rColor ) SAL_OVERRIDE;
125 : virtual void setBlendMode(sal_Int8) SAL_OVERRIDE;
126 : virtual void setFont( const FontAttributes& rFont ) SAL_OVERRIDE;
127 : virtual void setTextRenderMode( sal_Int32 ) SAL_OVERRIDE;
128 :
129 : virtual void strokePath( const css::uno::Reference<
130 : css::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
131 : virtual void fillPath( const css::uno::Reference<
132 : css::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
133 : virtual void eoFillPath( const css::uno::Reference<
134 : css::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
135 :
136 : virtual void intersectClip(const css::uno::Reference<
137 : css::rendering::XPolyPolygon2D >& rPath) SAL_OVERRIDE;
138 : virtual void intersectEoClip(const css::uno::Reference<
139 : css::rendering::XPolyPolygon2D >& rPath) SAL_OVERRIDE;
140 :
141 : virtual void drawGlyphs( const OUString& rGlyphs,
142 : const css::geometry::RealRectangle2D& rRect,
143 : const css::geometry::Matrix2D& rFontMatrix,
144 : double fontSize) SAL_OVERRIDE;
145 : virtual void endText() SAL_OVERRIDE;
146 :
147 : virtual void drawMask(const css::uno::Sequence<
148 : css::beans::PropertyValue>& xBitmap,
149 : bool bInvert ) SAL_OVERRIDE;
150 : /// Given image must already be color-mapped and normalized to sRGB.
151 : virtual void drawImage(const css::uno::Sequence<
152 : css::beans::PropertyValue>& xBitmap ) SAL_OVERRIDE;
153 : /** Given image must already be color-mapped and normalized to sRGB.
154 :
155 : maskColors must contain two sequences of color components
156 : */
157 : virtual void drawColorMaskedImage(const css::uno::Sequence<
158 : css::beans::PropertyValue>& xBitmap,
159 : const css::uno::Sequence<
160 : css::uno::Any>& xMaskColors ) SAL_OVERRIDE;
161 : virtual void drawMaskedImage(const css::uno::Sequence<
162 : css::beans::PropertyValue>& xBitmap,
163 : const css::uno::Sequence<
164 : css::beans::PropertyValue>& xMask,
165 : bool bInvertMask) SAL_OVERRIDE;
166 : virtual void drawAlphaMaskedImage(const css::uno::Sequence<
167 : css::beans::PropertyValue>& xImage,
168 : const css::uno::Sequence<
169 : css::beans::PropertyValue>& xMask) SAL_OVERRIDE;
170 :
171 : /// nElements == -1 means fill in number of pages
172 : void startIndicator( const OUString& rText, sal_Int32 nElements = -1 );
173 : void endIndicator();
174 :
175 : void setupImage(ImageId nImage);
176 :
177 : typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
178 : typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
179 :
180 : typedef std::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
181 : typedef std::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
182 :
183 : typedef std::vector<GraphicsContext> GraphicsContextStack;
184 :
185 : std::vector<CharGlyph> m_GlyphsList;
186 :
187 : boost::shared_ptr<ElementFactory> m_pElFactory;
188 : boost::shared_ptr<DocumentElement> m_pDocument;
189 : PageElement* m_pCurPage;
190 : Element* m_pCurElement;
191 : sal_Int32 m_nNextFontId;
192 : IdToFontMap m_aIdToFont;
193 : FontToIdMap m_aFontToId;
194 :
195 : GraphicsContextStack m_aGCStack;
196 : GraphicsContext m_prev_aGC;
197 : sal_Int32 m_nNextGCId;
198 : IdToGCMap m_aIdToGC;
199 : GCToIdMap m_aGCToId;
200 :
201 : ImageContainer m_aImages;
202 :
203 : DocumentTextDirecion m_eTextDirection;
204 :
205 : sal_Int32 m_nPages;
206 : sal_Int32 m_nNextZOrder;
207 : css::uno::Reference<
208 : css::task::XStatusIndicator >
209 : m_xStatusIndicator;
210 :
211 : bool m_bHaveTextOnDocLevel;
212 : };
213 474 : class CharGlyph
214 : {
215 : public:
216 286 : CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext,
217 : double width, double prevSpaceWidth, const OUString& rGlyphs )
218 : : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
219 286 : m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {};
220 :
221 760 : virtual ~CharGlyph(){};
222 386 : OUString& getGlyph(){ return m_rGlyphs; }
223 24 : double getWidth(){ return m_Width; }
224 262 : double getPrevSpaceWidth(){ return m_PrevSpaceWidth; }
225 954 : GraphicsContext& getGC(){ return m_rCurrentContext; }
226 24 : Element* getCurElement(){ return m_pCurElement; }
227 :
228 : private:
229 : Element* m_pCurElement ;
230 : GraphicsContext m_rCurrentContext ;
231 : double m_Width ;
232 : double m_PrevSpaceWidth ;
233 : OUString m_rGlyphs ;
234 : };
235 : }
236 :
237 : #endif
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|