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 <o3tl/hash_combine.hxx>
36
37// virtual resolution of the PDF OutputDev in dpi
38#define PDFI_OUTDEV_RESOLUTION 7200
39
41
42namespace 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
68 inline double convPx2mmPrec2( double fPix )
69 {
70 constexpr double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
71 double mm = fPix * ( px2mm * 100);
72 return std::floor(mm) / 100;
73 }
74
76 OUString getColorString( const css::rendering::ARGBColor& );
77 OUString getPercentString(double value);
78
80 void FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale);
81
83 {
84 size_t operator()(const FontAttributes& rFont ) const
85 {
86 std::size_t seed = 0;
87 o3tl::hash_combine(seed, rFont.familyName.hashCode());
88 o3tl::hash_combine(seed, rFont.fontWeight);
89 o3tl::hash_combine(seed, rFont.isItalic);
91 o3tl::hash_combine(seed, rFont.isOutline);
92 o3tl::hash_combine(seed, rFont.size);
93 return seed;
94 }
95 };
96
98 {
99 css::rendering::ARGBColor LineColor;
100 css::rendering::ARGBColor FillColor;
104 double Flatness;
105 double LineWidth;
107 std::vector<double> DashArray;
108 sal_Int32 FontId;
109 sal_Int32 TextRenderMode;
112
114 LineColor(),
115 FillColor(),
116 LineJoin(0),
117 LineCap(0),
118 BlendMode(0),
119 Flatness(0.0),
120 LineWidth(1.0),
121 MiterLimit(10.0),
122 DashArray(),
123 FontId(0),
126 Clip()
127 {}
128
129 bool operator==(const GraphicsContext& rRight ) const
130 {
131 return LineColor.Red == rRight.LineColor.Red &&
132 LineColor.Green == rRight.LineColor.Green &&
133 LineColor.Blue == rRight.LineColor.Blue &&
134 LineColor.Alpha == rRight.LineColor.Alpha &&
135 FillColor.Red == rRight.FillColor.Red &&
136 FillColor.Green == rRight.FillColor.Green &&
137 FillColor.Blue == rRight.FillColor.Blue &&
138 FillColor.Alpha == rRight.FillColor.Alpha &&
139 LineJoin == rRight.LineJoin &&
140 LineCap == rRight.LineCap &&
141 BlendMode == rRight.BlendMode &&
142 LineWidth == rRight.LineWidth &&
143 Flatness == rRight.Flatness &&
144 MiterLimit == rRight.MiterLimit &&
145 DashArray == rRight.DashArray &&
146 FontId == rRight.FontId &&
147 TextRenderMode == rRight.TextRenderMode &&
148 Transformation == rRight.Transformation &&
149 Clip == rRight.Clip;
150 }
151
152 OUString GetLineJoinString() const
153 {
154 switch (LineJoin)
155 {
156 default:
157 case css::rendering::PathJoinType::MITER:
158 return "miter";
159 case css::rendering::PathJoinType::ROUND:
160 return "round";
161 case css::rendering::PathJoinType::BEVEL:
162 return "bevel";
163 }
164 }
165
166 OUString GetLineCapString() const
167 {
168 switch (LineCap)
169 {
170 default:
171 case css::rendering::PathCapType::BUTT:
172 return "butt";
173 case css::rendering::PathCapType::ROUND:
174 return "round";
175 case css::rendering::PathCapType::SQUARE:
176 return "square";
177 }
178 }
179
180 bool isRotatedOrSkewed() const
181 { return Transformation.get( 0, 1 ) != 0.0 ||
182 Transformation.get( 1, 0 ) != 0.0; }
183 };
184
186 {
187 size_t operator()(const GraphicsContext& rGC ) const
188 {
189 std::size_t seed = 0;
190 o3tl::hash_combine(seed, rGC.LineColor.Red);
191 o3tl::hash_combine(seed, rGC.LineColor.Green);
192 o3tl::hash_combine(seed, rGC.LineColor.Blue);
193 o3tl::hash_combine(seed, rGC.LineColor.Alpha);
194 o3tl::hash_combine(seed, rGC.FillColor.Red);
195 o3tl::hash_combine(seed, rGC.FillColor.Green);
196 o3tl::hash_combine(seed, rGC.FillColor.Blue);
197 o3tl::hash_combine(seed, rGC.FillColor.Alpha);
198 o3tl::hash_combine(seed, rGC.LineJoin);
199 o3tl::hash_combine(seed, rGC.LineCap);
200 o3tl::hash_combine(seed, rGC.BlendMode);
201 o3tl::hash_combine(seed, rGC.LineWidth);
202 o3tl::hash_combine(seed, rGC.Flatness);
204 o3tl::hash_combine(seed, rGC.DashArray.size());
205 o3tl::hash_combine(seed, rGC.FontId);
207 o3tl::hash_combine(seed, rGC.Transformation.get( 0, 0 ));
208 o3tl::hash_combine(seed, rGC.Transformation.get( 1, 0 ));
209 o3tl::hash_combine(seed, rGC.Transformation.get( 0, 1 ));
210 o3tl::hash_combine(seed, rGC.Transformation.get( 1, 1 ));
211 o3tl::hash_combine(seed, rGC.Transformation.get( 0, 2 ));
212 o3tl::hash_combine(seed, rGC.Transformation.get( 1, 2 ));
213 o3tl::hash_combine(seed, rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0);
214 return seed;
215 }
216 };
217
220 bool getPassword( const css::uno::Reference<
221 css::task::XInteractionHandler >& xHandler,
222 OUString& rOutPwd,
223 bool bFirstTry,
224 const OUString& rDocName
225 );
226
228 css::uno::Reference<
229 css::task::XInteractionHandler > const & handler);
230}
231
232#endif
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
sal_uInt32 count() const
sal_uInt32 count() const
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
OUString convertPixelToUnitString(double fPix)
Definition: pdfihelper.cxx:113
OUString getColorString(const css::rendering::ARGBColor &)
Convert color to "#FEFEFE" color notation.
double convmm2Px(double fMM)
Definition: pdfihelper.hxx:60
double convPx2mm(double fPix)
Definition: pdfihelper.hxx:53
OUString getPercentString(double value)
Definition: pdfihelper.cxx:103
double GetAverageTransformationScale(const basegfx::B2DHomMatrix &matrix)
Definition: pdfihelper.cxx:32
OUString unitMMString(double fMM)
Definition: pdfihelper.cxx:108
std::unordered_map< OUString, OUString > PropertyMap
Definition: pdfihelper.hxx:44
double convPx2mmPrec2(double fPix)
round to 2 decimal places
Definition: pdfihelper.hxx:68
bool getPassword(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, OUString &rOutPwd, bool bFirstTry, const OUString &rDocName)
retrieve password from user
void reportUnsupportedEncryptionFormat(css::uno::Reference< css::task::XInteractionHandler > const &handler)
PolygonAction
What to do with a polygon. values can be ORed together.
Definition: pdfihelper.hxx:48
@ PATH_EOFILL
Definition: pdfihelper.hxx:48
@ PATH_STROKE
Definition: pdfihelper.hxx:48
@ PATH_FILL
Definition: pdfihelper.hxx:48
sal_Int32 ImageId
Definition: pdfihelper.hxx:45
void FillDashStyleProps(PropertyMap &props, const std::vector< double > &dashArray, double scale)
Definition: pdfihelper.cxx:40
#define PDFI_OUTDEV_RESOLUTION
Definition: pdfihelper.hxx:38
size_t operator()(const FontAttributes &rFont) const
Definition: pdfihelper.hxx:84
size_t operator()(const GraphicsContext &rGC) const
Definition: pdfihelper.hxx:187
css::rendering::ARGBColor FillColor
Definition: pdfihelper.hxx:100
css::rendering::ARGBColor LineColor
Definition: pdfihelper.hxx:99
bool operator==(const GraphicsContext &rRight) const
Definition: pdfihelper.hxx:129
bool isRotatedOrSkewed() const
Definition: pdfihelper.hxx:180
basegfx::B2DHomMatrix Transformation
Definition: pdfihelper.hxx:110
OUString GetLineCapString() const
Definition: pdfihelper.hxx:166
OUString GetLineJoinString() const
Definition: pdfihelper.hxx:152
std::vector< double > DashArray
Definition: pdfihelper.hxx:107
basegfx::B2DPolyPolygon Clip
Definition: pdfihelper.hxx:111
signed char sal_Int8