LibreOffice Module sdext (master)  1
pdfihelper.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_PDFIHELPER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIHELPER_HXX
22 
23 #include "contentsink.hxx"
24 
25 #include <rtl/ustring.hxx>
26 #include <rtl/math.h>
30 #include <com/sun/star/rendering/PathCapType.hpp>
31 #include <com/sun/star/rendering/PathJoinType.hpp>
32 
33 #include <unordered_map>
34 #include <vector>
35 #include <boost/functional/hash.hpp>
36 
37 // virtual resolution of the PDF OutputDev in dpi
38 #define PDFI_OUTDEV_RESOLUTION 7200
39 
40 namespace com { namespace sun { namespace star { namespace task
41 { class XInteractionHandler; }}}}
42 
43 namespace pdfi
44 {
45  typedef std::unordered_map< OUString, OUString > PropertyMap;
46  typedef sal_Int32 ImageId;
47 
50 
51  OUString unitMMString( double fMM );
52  OUString convertPixelToUnitString( double fPix );
53 
54  inline double convPx2mm( double fPix )
55  {
56  const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
57  fPix *= px2mm;
58  return fPix;
59  }
60 
61  inline double convmm2Px( double fMM )
62  {
63  const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
64  fMM *= mm2px;
65  return fMM;
66  }
67 
68  inline double convPx2mmPrec2( double fPix )
69  {
70  return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
71  }
72 
74  OUString getColorString( const css::rendering::ARGBColor& );
75  OUString getPercentString(double value);
76 
78  void FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale);
79 
80  struct FontAttrHash
81  {
82  size_t operator()(const FontAttributes& rFont ) const
83  {
84  std::size_t seed = 0;
85  boost::hash_combine(seed, rFont.familyName.hashCode());
86  boost::hash_combine(seed, rFont.isBold);
87  boost::hash_combine(seed, rFont.isItalic);
88  boost::hash_combine(seed, rFont.isUnderline);
89  boost::hash_combine(seed, rFont.isOutline);
90  boost::hash_combine(seed, rFont.size);
91  return seed;
92  }
93  };
94 
96  {
97  css::rendering::ARGBColor LineColor;
98  css::rendering::ARGBColor FillColor;
102  double Flatness;
103  double LineWidth;
104  double MiterLimit;
105  std::vector<double> DashArray;
106  sal_Int32 FontId;
107  sal_Int32 TextRenderMode;
110 
112  LineColor(),
113  FillColor(),
114  LineJoin(0),
115  LineCap(0),
116  BlendMode(0),
117  Flatness(0.0),
118  LineWidth(1.0),
119  MiterLimit(10.0),
120  DashArray(),
121  FontId(0),
122  TextRenderMode(0),
123  Transformation(),
124  Clip()
125  {}
126 
127  bool operator==(const GraphicsContext& rRight ) const
128  {
129  return LineColor.Red == rRight.LineColor.Red &&
130  LineColor.Green == rRight.LineColor.Green &&
131  LineColor.Blue == rRight.LineColor.Blue &&
132  LineColor.Alpha == rRight.LineColor.Alpha &&
133  FillColor.Red == rRight.FillColor.Red &&
134  FillColor.Green == rRight.FillColor.Green &&
135  FillColor.Blue == rRight.FillColor.Blue &&
136  FillColor.Alpha == rRight.FillColor.Alpha &&
137  LineJoin == rRight.LineJoin &&
138  LineCap == rRight.LineCap &&
139  BlendMode == rRight.BlendMode &&
140  LineWidth == rRight.LineWidth &&
141  Flatness == rRight.Flatness &&
142  MiterLimit == rRight.MiterLimit &&
143  DashArray == rRight.DashArray &&
144  FontId == rRight.FontId &&
145  TextRenderMode == rRight.TextRenderMode &&
146  Transformation == rRight.Transformation &&
147  Clip == rRight.Clip;
148  }
149 
150  OUString GetLineJoinString() const
151  {
152  switch (LineJoin)
153  {
154  default:
155  case css::rendering::PathJoinType::MITER:
156  return "miter";
157  case css::rendering::PathJoinType::ROUND:
158  return "round";
159  case css::rendering::PathJoinType::BEVEL:
160  return "bevel";
161  }
162  }
163 
164  OUString GetLineCapString() const
165  {
166  switch (LineCap)
167  {
168  default:
169  case css::rendering::PathCapType::BUTT:
170  return "butt";
171  case css::rendering::PathCapType::ROUND:
172  return "round";
173  case css::rendering::PathCapType::SQUARE:
174  return "square";
175  }
176  }
177 
178  bool isRotatedOrSkewed() const
179  { return Transformation.get( 0, 1 ) != 0.0 ||
180  Transformation.get( 1, 0 ) != 0.0; }
181  };
182 
184  {
185  size_t operator()(const GraphicsContext& rGC ) const
186  {
187  std::size_t seed = 0;
188  boost::hash_combine(seed, rGC.LineColor.Red);
189  boost::hash_combine(seed, rGC.LineColor.Green);
190  boost::hash_combine(seed, rGC.LineColor.Blue);
191  boost::hash_combine(seed, rGC.LineColor.Alpha);
192  boost::hash_combine(seed, rGC.FillColor.Red);
193  boost::hash_combine(seed, rGC.FillColor.Green);
194  boost::hash_combine(seed, rGC.FillColor.Blue);
195  boost::hash_combine(seed, rGC.FillColor.Alpha);
196  boost::hash_combine(seed, rGC.LineJoin);
197  boost::hash_combine(seed, rGC.LineCap);
198  boost::hash_combine(seed, rGC.BlendMode);
199  boost::hash_combine(seed, rGC.LineWidth);
200  boost::hash_combine(seed, rGC.Flatness);
201  boost::hash_combine(seed, rGC.MiterLimit);
202  boost::hash_combine(seed, rGC.DashArray.size());
203  boost::hash_combine(seed, rGC.FontId);
204  boost::hash_combine(seed, rGC.TextRenderMode);
205  boost::hash_combine(seed, rGC.Transformation.get( 0, 0 ));
206  boost::hash_combine(seed, rGC.Transformation.get( 1, 0 ));
207  boost::hash_combine(seed, rGC.Transformation.get( 0, 1 ));
208  boost::hash_combine(seed, rGC.Transformation.get( 1, 1 ));
209  boost::hash_combine(seed, rGC.Transformation.get( 0, 2 ));
210  boost::hash_combine(seed, rGC.Transformation.get( 1, 2 ));
211  boost::hash_combine(seed, rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0);
212  return seed;
213  }
214  };
215 
218  bool getPassword( const css::uno::Reference<
219  css::task::XInteractionHandler >& xHandler,
220  OUString& rOutPwd,
221  bool bFirstTry,
222  const OUString& rDocName
223  );
224 
226  css::uno::Reference<
227  css::task::XInteractionHandler > const & handler);
228 }
229 
230 #endif
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::rendering::ARGBColor LineColor
Definition: pdfihelper.hxx:97
std::unordered_map< OUString, OUString > PropertyMap
Definition: pdfihelper.hxx:45
void reportUnsupportedEncryptionFormat(css::uno::Reference< css::task::XInteractionHandler > const &handler)
size_t operator()(const GraphicsContext &rGC) const
Definition: pdfihelper.hxx:185
bool isRotatedOrSkewed() const
Definition: pdfihelper.hxx:178
OUString unitMMString(double fMM)
Definition: pdfihelper.cxx:107
OUString getPercentString(double value)
Definition: pdfihelper.cxx:102
signed char sal_Int8
#define PDFI_OUTDEV_RESOLUTION
Definition: pdfihelper.hxx:38
double convmm2Px(double fMM)
Definition: pdfihelper.hxx:61
OUString convertPixelToUnitString(double fPix)
Definition: pdfihelper.cxx:116
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
basegfx::B2DPolyPolygon Clip
Definition: pdfihelper.hxx:109
css::rendering::ARGBColor FillColor
Definition: pdfihelper.hxx:98
double convPx2mm(double fPix)
Definition: pdfihelper.hxx:54
std::vector< double > DashArray
Definition: pdfihelper.hxx:105
PolygonAction
What to do with a polygon. values can be ORed together.
Definition: pdfihelper.hxx:49
sal_Int32 ImageId
Definition: pdfihelper.hxx:46
OUString GetLineJoinString() const
Definition: pdfihelper.hxx:150
double GetAverageTransformationScale(const basegfx::B2DHomMatrix &matrix)
Definition: pdfihelper.cxx:31
basegfx::B2DHomMatrix Transformation
Definition: pdfihelper.hxx:108
OUString getColorString(const css::rendering::ARGBColor &)
Convert color to "#FEFEFE" color notation.
size_t operator()(const FontAttributes &rFont) const
Definition: pdfihelper.hxx:82
bool getPassword(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, OUString &rOutPwd, bool bFirstTry, const OUString &rDocName)
retrieve password from user
void FillDashStyleProps(PropertyMap &props, const std::vector< double > &dashArray, double scale)
Definition: pdfihelper.cxx:39
sal_uInt32 count() const
double convPx2mmPrec2(double fPix)
Definition: pdfihelper.hxx:68
bool operator==(const GraphicsContext &rRight) const
Definition: pdfihelper.hxx:127
OUString GetLineCapString() const
Definition: pdfihelper.hxx:164
sal_uInt32 count() const