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 namespace pdfi
41 {
42 
43  class PDFIProcessor;
44  struct Element;
45  struct DocumentElement;
46  struct PageElement;
47  class ElementFactory;
48  class XmlEmitter;
49  class CharGlyph;
50 
55  class PDFIProcessor : public ContentSink
56  {
57  public:
58  css::uno::Reference<
59  css::uno::XComponentContext > m_xContext;
61  double prevCharWidth;
62 
63  explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat,
64  css::uno::Reference< css::uno::XComponentContext > const & xContext) ;
65 
66  void emit( XmlEmitter& rEmitter,
67  const TreeVisitorFactory& rVisitorFactory );
68 
69  sal_Int32 getGCId( const GraphicsContext& rGC );
70  const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
72  const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
73 
74  const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const
75  { return m_xStatusIndicator; }
76 
77  const FontAttributes& getFont( sal_Int32 nFontId ) const;
78  sal_Int32 getFontId( const FontAttributes& rAttr ) const;
79 
80  static void sortElements( Element* pElement );
81 
82  static OUString mirrorString( const OUString& i_rInString );
83 
84  private:
85  void processGlyphLine();
86 
87  // ContentSink interface implementation
88 
89  virtual void setPageNum( sal_Int32 nNumPages ) override;
90  virtual void startPage( const css::geometry::RealSize2D& rSize ) override;
91  virtual void endPage() override;
92 
93  virtual void hyperLink( const css::geometry::RealRectangle2D& rBounds,
94  const OUString& rURI ) override;
95  virtual void pushState() override;
96  virtual void popState() override;
97  virtual void setFlatness( double ) override;
98  virtual void setTransformation( const css::geometry::AffineMatrix2D& rMatrix ) override;
99  virtual void setLineDash( const css::uno::Sequence<double>& dashes,
100  double start ) override;
101  virtual void setLineJoin(sal_Int8) override;
102  virtual void setLineCap(sal_Int8) override;
103  virtual void setMiterLimit(double) override;
104  virtual void setLineWidth(double) override;
105  virtual void setFillColor( const css::rendering::ARGBColor& rColor ) override;
106  virtual void setStrokeColor( const css::rendering::ARGBColor& rColor ) override;
107  virtual void setFont( const FontAttributes& rFont ) override;
108  virtual void setTextRenderMode( sal_Int32 ) override;
109 
110  virtual void strokePath( const css::uno::Reference<
111  css::rendering::XPolyPolygon2D >& rPath ) override;
112  virtual void fillPath( const css::uno::Reference<
113  css::rendering::XPolyPolygon2D >& rPath ) override;
114  virtual void eoFillPath( const css::uno::Reference<
115  css::rendering::XPolyPolygon2D >& rPath ) override;
116 
117  virtual void intersectClip(const css::uno::Reference<
118  css::rendering::XPolyPolygon2D >& rPath) override;
119  virtual void intersectEoClip(const css::uno::Reference<
120  css::rendering::XPolyPolygon2D >& rPath) override;
121 
122  virtual void drawGlyphs( const OUString& rGlyphs,
123  const css::geometry::RealRectangle2D& rRect,
124  const css::geometry::Matrix2D& rFontMatrix,
125  double fontSize) override;
126  virtual void endText() override;
127 
128  virtual void drawMask(const css::uno::Sequence<
129  css::beans::PropertyValue>& xBitmap,
130  bool bInvert ) override;
132  virtual void drawImage(const css::uno::Sequence<
133  css::beans::PropertyValue>& xBitmap ) override;
138  virtual void drawColorMaskedImage(const css::uno::Sequence<
139  css::beans::PropertyValue>& xBitmap,
140  const css::uno::Sequence<
141  css::uno::Any>& xMaskColors ) override;
142  virtual void drawMaskedImage(const css::uno::Sequence<
143  css::beans::PropertyValue>& xBitmap,
144  const css::uno::Sequence<
145  css::beans::PropertyValue>& xMask,
146  bool bInvertMask) override;
147  virtual void drawAlphaMaskedImage(const css::uno::Sequence<
148  css::beans::PropertyValue>& xImage,
149  const css::uno::Sequence<
150  css::beans::PropertyValue>& xMask) override;
151 
152  void startIndicator( const OUString& rText );
153  void endIndicator();
154 
155  void setupImage(ImageId nImage);
156 
157  typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
158  typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
159 
160  typedef std::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
161  typedef std::unordered_map<GraphicsContext, sal_Int32, GraphicsContextHash> GCToIdMap;
162 
163  typedef std::vector<GraphicsContext> GraphicsContextStack;
164 
165  std::vector<CharGlyph> m_GlyphsList;
166 
167  std::shared_ptr<DocumentElement> m_pDocument;
170  sal_Int32 m_nNextFontId;
171  IdToFontMap m_aIdToFont;
172  FontToIdMap m_aFontToId;
173 
174  GraphicsContextStack m_aGCStack;
175  sal_Int32 m_nNextGCId;
176  IdToGCMap m_aIdToGC;
177  GCToIdMap m_aGCToId;
178 
180 
181  sal_Int32 m_nPages;
182  sal_Int32 m_nNextZOrder;
183  css::uno::Reference< css::task::XStatusIndicator >
185  };
186  class CharGlyph final
187  {
188  public:
189  CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext,
190  double width, double prevSpaceWidth, const OUString& rGlyphs )
191  : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
192  m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {};
193 
194  OUString& getGlyph(){ return m_rGlyphs; }
195  double getWidth() const { return m_Width; }
196  double getPrevSpaceWidth() const { return m_PrevSpaceWidth; }
199 
200  private:
203  double m_Width ;
205  OUString m_rGlyphs ;
206  };
207 }
208 
209 #endif
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > m_xContext
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
std::unordered_map< sal_Int32, GraphicsContext > IdToGCMap
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
Element * m_pCurElement
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
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
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
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
std::unordered_map< GraphicsContext, sal_Int32, GraphicsContextHash > GCToIdMap
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