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