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/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>
27 
29 
30 #include <rtl/ustring.hxx>
31 
32 #include <memory>
33 #include <unordered_map>
34 
35 #include "imagecontainer.hxx"
36 #include "contentsink.hxx"
37 #include "treevisitorfactory.hxx"
38 #include "genericelements.hxx"
39 
40 #include <boost/bimap/bimap.hpp>
41 #include <boost/bimap/unordered_set_of.hpp>
42 
43 namespace pdfi
44 {
45 
46  class PDFIProcessor;
47  struct Element;
48  struct DocumentElement;
49  struct PageElement;
50  class ElementFactory;
51  class XmlEmitter;
52  class CharGlyph;
53 
58  class PDFIProcessor : public ContentSink
59  {
60  public:
61  css::uno::Reference<
62  css::uno::XComponentContext > m_xContext;
64  double prevCharWidth;
65 
66  explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat,
67  css::uno::Reference< css::uno::XComponentContext > const & xContext) ;
68 
69  void emit( XmlEmitter& rEmitter,
70  const TreeVisitorFactory& rVisitorFactory );
71 
72  sal_Int32 getGCId( const GraphicsContext& rGC );
73  const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
75  const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
76 
77  const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const
78  { return m_xStatusIndicator; }
79 
80  const FontAttributes& getFont( sal_Int32 nFontId ) const;
81  sal_Int32 getFontId( const FontAttributes& rAttr ) const;
82 
83  static void sortElements( Element* pElement );
84 
85  static OUString mirrorString( const OUString& i_rInString );
86 
87  private:
88  void processGlyphLine();
89 
90  // ContentSink interface implementation
91 
92  virtual void setPageNum( sal_Int32 nNumPages ) override;
93  virtual void startPage( const css::geometry::RealSize2D& rSize ) override;
94  virtual void endPage() override;
95 
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;
112 
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;
119 
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;
124 
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;
130 
131  virtual void drawMask(const css::uno::Sequence<
132  css::beans::PropertyValue>& xBitmap,
133  bool bInvert ) override;
135  virtual void drawImage(const css::uno::Sequence<
136  css::beans::PropertyValue>& xBitmap ) override;
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;
154 
155  void startIndicator( const OUString& rText );
156  void endIndicator();
157 
158  void setupImage(ImageId nImage);
159 
160  typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
161  typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
162 
163  typedef boost::bimaps::bimap<
164  boost::bimaps::unordered_set_of<GraphicsContext, GraphicsContextHash>,
165  boost::bimaps::unordered_set_of<sal_Int32>
167 
168  typedef std::vector<GraphicsContext> GraphicsContextStack;
169 
170  std::vector<CharGlyph> m_GlyphsList;
171 
172  std::shared_ptr<DocumentElement> m_pDocument;
175  sal_Int32 m_nNextFontId;
176  IdToFontMap m_aIdToFont;
177  FontToIdMap m_aFontToId;
178 
179  GraphicsContextStack m_aGCStack;
180  sal_Int32 m_nNextGCId;
182 
184 
185  sal_Int32 m_nPages;
186  sal_Int32 m_nNextZOrder;
187  css::uno::Reference< css::task::XStatusIndicator >
189  };
190  class CharGlyph final
191  {
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) {};
197 
198  OUString& getGlyph(){ return m_rGlyphs; }
199  double getWidth() const { return m_Width; }
200  double getPrevSpaceWidth() const { return m_PrevSpaceWidth; }
203 
204  private:
207  double const m_Width ;
208  double const m_PrevSpaceWidth ;
209  OUString m_rGlyphs ;
210  };
211 }
212 
213 #endif
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > m_xContext
double const m_Width
virtual void endText() override
issued when a sequence of associated glyphs is drawn
std::unordered_map< FontAttributes, sal_Int32, FontAttrHash > FontToIdMap
static OUString mirrorString(const OUString &i_rInString)
signed char sal_Int8
PageElement * m_pCurPage
GraphicsContext m_rCurrentContext
Main entry from the parser.
ImageContainer m_aImages
const FontAttributes & getFont(sal_Int32 nFontId) const
virtual void setFillColor(const css::rendering::ARGBColor &rColor) override
void setupImage(ImageId nImage)
virtual void pushState() override
virtual void intersectClip(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
double getPrevSpaceWidth() const
const GraphicsContext & getGraphicsContext(sal_Int32 nGCId) const
virtual void setLineWidth(double) override
sal_Int32 ImageId
Definition: pdfihelper.hxx:46
std::shared_ptr< DocumentElement > m_pDocument
double const m_PrevSpaceWidth
sal_Int32 getGCId(const GraphicsContext &rGC)
virtual void setStrokeColor(const css::rendering::ARGBColor &rColor) override
OUString & getGlyph()
void startIndicator(const OUString &rText)
virtual void drawMaskedImage(const css::uno::Sequence< css::beans::PropertyValue > &xBitmap, const css::uno::Sequence< css::beans::PropertyValue > &xMask, bool bInvertMask) 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)
std::vector< GraphicsContext > GraphicsContextStack
virtual void setTextRenderMode(sal_Int32) override
virtual void setPageNum(sal_Int32 nNumPages) override
Total number of pages for upcoming document.
std::unordered_map< sal_Int32, FontAttributes > IdToFontMap
css::uno::Reference< css::task::XStatusIndicator > m_xStatusIndicator
Output interface to ODF.
Definition: xmlemitter.hxx:32
virtual void setMiterLimit(double) override
Tree manipulation factory.
virtual void setLineJoin(sal_Int8) override
std::vector< CharGlyph > m_GlyphsList
virtual void setLineCap(sal_Int8) override
Element *const m_pCurElement
virtual void drawAlphaMaskedImage(const css::uno::Sequence< css::beans::PropertyValue > &xImage, const css::uno::Sequence< css::beans::PropertyValue > &xMask) override
GraphicsContext & getGC()
void emit(XmlEmitter &rEmitter, const TreeVisitorFactory &rVisitorFactory)
(preliminary) API wrapper around xpdf
const css::uno::Reference< css::task::XStatusIndicator > & getStatusIndicator() const
virtual void setTransformation(const css::geometry::AffineMatrix2D &rMatrix) override
boost::bimaps::bimap< boost::bimaps::unordered_set_of< GraphicsContext, GraphicsContextHash >, boost::bimaps::unordered_set_of< sal_Int32 > > GCToIdBiMap
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 endPage() override
virtual void startPage(const css::geometry::RealSize2D &rSize) override
GraphicsContext & getCurrentContext()
Element * getCurElement()
double getWidth() const
sal_Int32 getFontId(const FontAttributes &rAttr) const
static void sortElements(Element *pElement)
virtual void intersectEoClip(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
virtual void setFlatness(double) override
const GraphicsContext & getCurrentContext() const
virtual void strokePath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
CharGlyph(Element *pCurElement, const GraphicsContext &rCurrentContext, double width, double prevSpaceWidth, const OUString &rGlyphs)
GraphicsContextStack m_aGCStack
virtual void eoFillPath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
virtual void drawGlyphs(const OUString &rGlyphs, const css::geometry::RealRectangle2D &rRect, const css::geometry::Matrix2D &rFontMatrix, double fontSize) override
virtual void popState() override
virtual void setLineDash(const css::uno::Sequence< double > &dashes, double start) override
virtual void hyperLink(const css::geometry::RealRectangle2D &rBounds, const OUString &rURI) override
virtual void setFont(const FontAttributes &rFont) 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.
virtual void fillPath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &rPath) override
PDFIProcessor(const css::uno::Reference< css::task::XStatusIndicator > &xStat, css::uno::Reference< css::uno::XComponentContext > const &xContext)
basegfx::B2DHomMatrix prevTextMatrix