Line data Source code
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_PDFI_HELPER_HXX
21 : #define INCLUDED_PDFI_HELPER_HXX
22 :
23 : #include "contentsink.hxx"
24 :
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 <com/sun/star/rendering/XColorSpace.hpp>
31 :
32 : #include <vector>
33 : #include <boost/unordered_map.hpp>
34 :
35 : // virtual resolution of the PDF OutputDev in dpi
36 : #define PDFI_OUTDEV_RESOLUTION 7200
37 :
38 : namespace com { namespace sun { namespace star { namespace task
39 : { class XInteractionHandler; }}}}
40 :
41 : namespace pdfi
42 : {
43 : typedef boost::unordered_map< rtl::OUString, rtl::OUString, rtl::OUStringHash > PropertyMap;
44 : typedef sal_Int32 ImageId;
45 :
46 : /// What to do with a polygon. values can be ORed together
47 : enum PolygonAction { PATH_STROKE=1, PATH_FILL=2, PATH_EOFILL=4 };
48 :
49 : rtl::OUString unitMMString( double fMM );
50 : rtl::OUString convertPixelToUnitString( double fPix );
51 :
52 304 : inline double convPx2mm( double fPix )
53 : {
54 304 : const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
55 304 : fPix *= px2mm;
56 304 : return fPix;
57 : }
58 :
59 8 : inline double convmm2Px( double fMM )
60 : {
61 8 : const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
62 8 : fMM *= mm2px;
63 8 : return fMM;
64 : }
65 :
66 124 : inline double convPx2mmPrec2( double fPix )
67 : {
68 124 : return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
69 : }
70 :
71 : /// Convert color to "#FEFEFE" color notation
72 : rtl::OUString getColorString( const ::com::sun::star::rendering::ARGBColor& );
73 :
74 : struct FontAttrHash
75 : {
76 46 : size_t operator()(const FontAttributes& rFont ) const
77 : {
78 46 : return (size_t)rFont.familyName.hashCode()
79 : ^ size_t(rFont.isBold ? 0xd47be593 : 0)
80 : ^ size_t(rFont.isItalic ? 0x1efd51a1 : 0)
81 : ^ size_t(rFont.isUnderline ? 0xf6bd325a : 0)
82 : ^ size_t(rFont.isOutline ? 0x12345678 : 0)
83 46 : ^ size_t(rFont.size)
84 : ;
85 : }
86 : };
87 :
88 1699 : struct GraphicsContext
89 : {
90 : ::com::sun::star::rendering::ARGBColor LineColor;
91 : ::com::sun::star::rendering::ARGBColor FillColor;
92 : sal_Int8 LineJoin;
93 : sal_Int8 LineCap;
94 : sal_Int8 BlendMode;
95 : double Flatness;
96 : double LineWidth;
97 : double MiterLimit;
98 : std::vector<double> DashArray;
99 : sal_Int32 FontId;
100 : sal_Int32 TextRenderMode;
101 : basegfx::B2DHomMatrix Transformation;
102 : basegfx::B2DPolyPolygon Clip;
103 :
104 231 : GraphicsContext() :
105 : LineColor(),
106 : FillColor(),
107 : LineJoin(0),
108 : LineCap(0),
109 : BlendMode(0),
110 : Flatness(0.0),
111 : LineWidth(1.0),
112 : MiterLimit(10.0),
113 : DashArray(),
114 : FontId(0),
115 : TextRenderMode(0),
116 : Transformation(),
117 231 : Clip()
118 231 : {}
119 :
120 458 : bool operator==(const GraphicsContext& rRight ) const
121 : {
122 : return LineColor.Red == rRight.LineColor.Red &&
123 : LineColor.Green == rRight.LineColor.Green &&
124 : LineColor.Blue == rRight.LineColor.Blue &&
125 : LineColor.Alpha == rRight.LineColor.Alpha &&
126 : FillColor.Red == rRight.FillColor.Red &&
127 : FillColor.Green == rRight.FillColor.Green &&
128 : FillColor.Blue == rRight.FillColor.Blue &&
129 : FillColor.Alpha == rRight.FillColor.Alpha &&
130 : LineJoin == rRight.LineJoin &&
131 : LineCap == rRight.LineCap &&
132 : BlendMode == rRight.BlendMode &&
133 : LineWidth == rRight.LineWidth &&
134 : Flatness == rRight.Flatness &&
135 : MiterLimit == rRight.MiterLimit &&
136 450 : DashArray == rRight.DashArray &&
137 : FontId == rRight.FontId &&
138 : TextRenderMode == rRight.TextRenderMode &&
139 450 : Transformation == rRight.Transformation &&
140 1358 : Clip == rRight.Clip;
141 : }
142 :
143 197 : bool isRotatedOrSkewed() const
144 197 : { return Transformation.get( 0, 1 ) != 0.0 ||
145 197 : Transformation.get( 1, 0 ) != 0.0; }
146 : };
147 :
148 : struct GraphicsContextHash
149 : {
150 484 : size_t operator()(const GraphicsContext& rGC ) const
151 : {
152 : return size_t(rGC.LineColor.Red)
153 : ^ size_t(rGC.LineColor.Green)
154 : ^ size_t(rGC.LineColor.Blue)
155 : ^ size_t(rGC.LineColor.Alpha)
156 : ^ size_t(rGC.FillColor.Red)
157 : ^ size_t(rGC.FillColor.Green)
158 : ^ size_t(rGC.FillColor.Blue)
159 : ^ size_t(rGC.FillColor.Alpha)
160 : ^ size_t(rGC.LineJoin)
161 : ^ size_t(rGC.LineCap)
162 : ^ size_t(rGC.BlendMode)
163 : ^ size_t(rGC.LineWidth)
164 : ^ size_t(rGC.Flatness)
165 : ^ size_t(rGC.MiterLimit)
166 484 : ^ rGC.DashArray.size()
167 : ^ size_t(rGC.FontId)
168 : ^ size_t(rGC.TextRenderMode)
169 484 : ^ size_t(rGC.Transformation.get( 0, 0 ))
170 484 : ^ size_t(rGC.Transformation.get( 1, 0 ))
171 484 : ^ size_t(rGC.Transformation.get( 0, 1 ))
172 484 : ^ size_t(rGC.Transformation.get( 1, 1 ))
173 484 : ^ size_t(rGC.Transformation.get( 0, 2 ))
174 484 : ^ size_t(rGC.Transformation.get( 1, 2 ))
175 3872 : ^ size_t(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0)
176 : ;
177 : }
178 : };
179 :
180 : /** retrieve password from user
181 : */
182 : bool getPassword( const ::com::sun::star::uno::Reference<
183 : ::com::sun::star::task::XInteractionHandler >& xHandler,
184 : rtl::OUString& rOutPwd,
185 : bool bFirstTry,
186 : const rtl::OUString& rDocName
187 : );
188 :
189 : void reportUnsupportedEncryptionFormat(
190 : com::sun::star::uno::Reference<
191 : com::sun::star::task::XInteractionHandler > const & handler);
192 : }
193 :
194 : #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
195 :
196 : #endif
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|