vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / pdfimport / inc / pdfiprocessor.hxx
blob89f9d601b7b0844b78feef996b01fb8b1687927b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/task/XStatusIndicator.hpp>
24 #include <com/sun/star/geometry/RealSize2D.hpp>
25 #include <com/sun/star/geometry/RealRectangle2D.hpp>
26 #include <com/sun/star/geometry/Matrix2D.hpp>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <rtl/ustring.hxx>
32 #include <memory>
33 #include <unordered_map>
35 #include "imagecontainer.hxx"
36 #include "contentsink.hxx"
37 #include "treevisitorfactory.hxx"
38 #include "genericelements.hxx"
40 #include <boost/bimap/bimap.hpp>
41 #include <boost/bimap/unordered_set_of.hpp>
43 namespace pdfi
46 class PDFIProcessor;
47 struct Element;
48 struct DocumentElement;
49 struct PageElement;
50 class ElementFactory;
51 class XmlEmitter;
52 class CharGlyph;
54 /** Main entry from the parser
56 Creates the internal DOM tree from the render calls
58 class PDFIProcessor : public ContentSink
60 public:
61 css::uno::Reference<
62 css::uno::XComponentContext > m_xContext;
63 basegfx::B2DHomMatrix prevTextMatrix;
64 double prevCharWidth;
66 explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat,
67 css::uno::Reference< css::uno::XComponentContext > const & xContext) ;
69 void emit( XmlEmitter& rEmitter,
70 const TreeVisitorFactory& rVisitorFactory );
72 sal_Int32 getGCId( const GraphicsContext& rGC );
73 const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
74 GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
75 const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
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 mirrorString( const OUString& i_rInString );
87 private:
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(sal_Int8) 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 intersectEoClip(const css::uno::Reference<
123 css::rendering::XPolyPolygon2D >& rPath) override;
125 virtual void drawGlyphs( const OUString& rGlyphs,
126 const css::geometry::RealRectangle2D& rRect,
127 const css::geometry::Matrix2D& rFontMatrix,
128 double fontSize) override;
129 virtual void endText() override;
131 virtual void drawMask(const css::uno::Sequence<
132 css::beans::PropertyValue>& xBitmap,
133 bool bInvert ) override;
134 /// Given image must already be color-mapped and normalized to sRGB.
135 virtual void drawImage(const css::uno::Sequence<
136 css::beans::PropertyValue>& xBitmap ) override;
137 /** Given image must already be color-mapped and normalized to sRGB.
139 maskColors must contain two sequences of color components
141 virtual void drawColorMaskedImage(const css::uno::Sequence<
142 css::beans::PropertyValue>& xBitmap,
143 const css::uno::Sequence<
144 css::uno::Any>& xMaskColors ) override;
145 virtual void drawMaskedImage(const css::uno::Sequence<
146 css::beans::PropertyValue>& xBitmap,
147 const css::uno::Sequence<
148 css::beans::PropertyValue>& xMask,
149 bool bInvertMask) override;
150 virtual void drawAlphaMaskedImage(const css::uno::Sequence<
151 css::beans::PropertyValue>& xImage,
152 const css::uno::Sequence<
153 css::beans::PropertyValue>& xMask) override;
155 void startIndicator( const OUString& rText );
156 void endIndicator();
158 void setupImage(ImageId nImage);
160 typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
161 typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
163 typedef boost::bimaps::bimap<
164 boost::bimaps::unordered_set_of<GraphicsContext, GraphicsContextHash>,
165 boost::bimaps::unordered_set_of<sal_Int32>
166 > GCToIdBiMap;
168 typedef std::vector<GraphicsContext> GraphicsContextStack;
170 std::vector<CharGlyph> m_GlyphsList;
172 std::shared_ptr<DocumentElement> m_pDocument;
173 PageElement* m_pCurPage;
174 Element* m_pCurElement;
175 sal_Int32 m_nNextFontId;
176 IdToFontMap m_aIdToFont;
177 FontToIdMap m_aFontToId;
179 GraphicsContextStack m_aGCStack;
180 sal_Int32 m_nNextGCId;
181 GCToIdBiMap m_aGCToId;
183 ImageContainer m_aImages;
185 sal_Int32 m_nPages;
186 sal_Int32 m_nNextZOrder;
187 css::uno::Reference< css::task::XStatusIndicator >
188 m_xStatusIndicator;
190 class CharGlyph final
192 public:
193 CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext,
194 double width, double prevSpaceWidth, const OUString& rGlyphs )
195 : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
196 m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {};
198 OUString& getGlyph(){ return m_rGlyphs; }
199 double getWidth() const { return m_Width; }
200 double getPrevSpaceWidth() const { return m_PrevSpaceWidth; }
201 GraphicsContext& getGC(){ return m_rCurrentContext; }
202 Element* getCurElement(){ return m_pCurElement; }
204 private:
205 Element* const m_pCurElement ;
206 GraphicsContext m_rCurrentContext ;
207 double const m_Width ;
208 double const m_PrevSpaceWidth ;
209 OUString m_rGlyphs ;
213 #endif
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */