1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIHELPER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIHELPER_HXX
23 #include "contentsink.hxx"
25 #include <rtl/ustring.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/vector/b2enums.hxx>
31 #include <com/sun/star/rendering/PathCapType.hpp>
33 #include <unordered_map>
35 #include <o3tl/hash_combine.hxx>
37 // virtual resolution of the PDF OutputDev in dpi
38 #define PDFI_OUTDEV_RESOLUTION 7200
40 namespace com::sun::star::task
{ class XInteractionHandler
; }
44 typedef std::unordered_map
< OUString
, OUString
> PropertyMap
;
45 typedef sal_Int32 ImageId
;
47 /// What to do with a polygon. values can be ORed together
48 enum PolygonAction
{ PATH_STROKE
=1, PATH_FILL
=2, PATH_EOFILL
=4 };
50 OUString
unitMMString( double fMM
);
51 OUString
convertPixelToUnitString( double fPix
);
53 inline double convPx2mm( double fPix
)
55 const double px2mm
= 25.4/PDFI_OUTDEV_RESOLUTION
;
60 inline double convmm2Px( double fMM
)
62 const double mm2px
= PDFI_OUTDEV_RESOLUTION
/25.4;
67 /// round to 2 decimal places
68 inline double convPx2mmPrec2( double fPix
)
70 constexpr double px2mm
= 25.4/PDFI_OUTDEV_RESOLUTION
;
71 double mm
= fPix
* ( px2mm
* 100);
72 return std::floor(mm
) / 100;
75 /// Convert color to "#FEFEFE" color notation
76 OUString
getColorString( const css::rendering::ARGBColor
& );
77 OUString
getPercentString(double value
);
79 double GetAverageTransformationScale(const basegfx::B2DHomMatrix
& matrix
);
80 void FillDashStyleProps(PropertyMap
& props
, const std::vector
<double>& dashArray
, double scale
);
84 size_t operator()(const FontAttributes
& rFont
) const
87 o3tl::hash_combine(seed
, rFont
.familyName
.hashCode());
88 o3tl::hash_combine(seed
, rFont
.fontWeight
);
89 o3tl::hash_combine(seed
, rFont
.isItalic
);
90 o3tl::hash_combine(seed
, rFont
.isUnderline
);
91 o3tl::hash_combine(seed
, rFont
.isOutline
);
92 o3tl::hash_combine(seed
, rFont
.size
);
97 struct GraphicsContext
99 css::rendering::ARGBColor LineColor
;
100 css::rendering::ARGBColor FillColor
;
101 basegfx::B2DLineJoin LineJoin
;
107 std::vector
<double> DashArray
;
109 sal_Int32 TextRenderMode
;
110 basegfx::B2DHomMatrix Transformation
;
111 basegfx::B2DPolyPolygon Clip
;
116 LineJoin(basegfx::B2DLineJoin::NONE
),
129 bool operator==(const GraphicsContext
& rRight
) const
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
&&
152 OUString
GetLineJoinString() const
157 case basegfx::B2DLineJoin::Miter
:
158 return u
"miter"_ustr
;
159 case basegfx::B2DLineJoin::Round
:
160 return u
"round"_ustr
;
161 case basegfx::B2DLineJoin::Bevel
:
162 return u
"bevel"_ustr
;
166 OUString
GetLineCapString() const
171 case css::rendering::PathCapType::BUTT
:
173 case css::rendering::PathCapType::ROUND
:
174 return u
"round"_ustr
;
175 case css::rendering::PathCapType::SQUARE
:
176 return u
"square"_ustr
;
180 bool isRotatedOrSkewed() const
181 { return Transformation
.get( 0, 1 ) != 0.0 ||
182 Transformation
.get( 1, 0 ) != 0.0; }
185 struct GraphicsContextHash
187 size_t operator()(const GraphicsContext
& rGC
) const
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
);
203 o3tl::hash_combine(seed
, rGC
.MiterLimit
);
204 o3tl::hash_combine(seed
, rGC
.DashArray
.size());
205 o3tl::hash_combine(seed
, rGC
.FontId
);
206 o3tl::hash_combine(seed
, rGC
.TextRenderMode
);
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);
218 /** retrieve password from user
220 bool getPassword( const css::uno::Reference
<
221 css::task::XInteractionHandler
>& xHandler
,
224 const OUString
& rDocName
227 void reportUnsupportedEncryptionFormat(
229 css::task::XInteractionHandler
> const & handler
);
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */