tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sdext / source / pdfimport / inc / pdfihelper.hxx
bloba4414cd4809d5493f454a9609377638aa925f44d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <rtl/math.h>
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>
34 #include <vector>
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; }
42 namespace pdfi
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;
56 fPix *= px2mm;
57 return fPix;
60 inline double convmm2Px( double fMM )
62 const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
63 fMM *= mm2px;
64 return fMM;
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);
82 struct FontAttrHash
84 size_t operator()(const FontAttributes& rFont ) const
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);
90 o3tl::hash_combine(seed, rFont.isUnderline);
91 o3tl::hash_combine(seed, rFont.isOutline);
92 o3tl::hash_combine(seed, rFont.size);
93 return seed;
97 struct GraphicsContext
99 css::rendering::ARGBColor LineColor;
100 css::rendering::ARGBColor FillColor;
101 basegfx::B2DLineJoin LineJoin;
102 sal_Int8 LineCap;
103 sal_Int8 BlendMode;
104 double Flatness;
105 double LineWidth;
106 double MiterLimit;
107 std::vector<double> DashArray;
108 sal_Int32 FontId;
109 sal_Int32 TextRenderMode;
110 basegfx::B2DHomMatrix Transformation;
111 basegfx::B2DPolyPolygon Clip;
113 GraphicsContext() :
114 LineColor(),
115 FillColor(),
116 LineJoin(basegfx::B2DLineJoin::NONE),
117 LineCap(0),
118 BlendMode(0),
119 Flatness(0.0),
120 LineWidth(1.0),
121 MiterLimit(10.0),
122 DashArray(),
123 FontId(0),
124 TextRenderMode(0),
125 Transformation(),
126 Clip()
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 &&
149 Clip == rRight.Clip;
152 OUString GetLineJoinString() const
154 switch (LineJoin)
156 default:
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
168 switch (LineCap)
170 default:
171 case css::rendering::PathCapType::BUTT:
172 return u"butt"_ustr;
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);
214 return seed;
218 /** retrieve password from user
220 bool getPassword( const css::uno::Reference<
221 css::task::XInteractionHandler >& xHandler,
222 OUString& rOutPwd,
223 bool bFirstTry,
224 const OUString& rDocName
227 void reportUnsupportedEncryptionFormat(
228 css::uno::Reference<
229 css::task::XInteractionHandler > const & handler);
232 #endif
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */