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_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>
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< OUString, OUString, 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 : OUString unitMMString( double fMM );
50 : OUString convertPixelToUnitString( double fPix );
51 :
52 0 : inline double convPx2mm( double fPix )
53 : {
54 0 : const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
55 0 : fPix *= px2mm;
56 0 : return fPix;
57 : }
58 :
59 0 : inline double convmm2Px( double fMM )
60 : {
61 0 : const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
62 0 : fMM *= mm2px;
63 0 : return fMM;
64 : }
65 :
66 0 : inline double convPx2mmPrec2( double fPix )
67 : {
68 0 : return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
69 : }
70 :
71 : /// Convert color to "#FEFEFE" color notation
72 : OUString getColorString( const ::com::sun::star::rendering::ARGBColor& );
73 :
74 : struct FontAttrHash
75 : {
76 0 : size_t operator()(const FontAttributes& rFont ) const
77 : {
78 0 : return (size_t)rFont.familyName.hashCode()
79 0 : ^ size_t(rFont.isBold ? 0xd47be593 : 0)
80 0 : ^ size_t(rFont.isItalic ? 0x1efd51a1 : 0)
81 0 : ^ size_t(rFont.isUnderline ? 0xf6bd325a : 0)
82 0 : ^ size_t(rFont.isOutline ? 0x12345678 : 0)
83 0 : ^ size_t(rFont.size)
84 : ;
85 : }
86 : };
87 :
88 0 : 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 0 : 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 0 : Clip()
118 0 : {}
119 :
120 0 : bool operator==(const GraphicsContext& rRight ) const
121 : {
122 0 : return LineColor.Red == rRight.LineColor.Red &&
123 0 : LineColor.Green == rRight.LineColor.Green &&
124 0 : LineColor.Blue == rRight.LineColor.Blue &&
125 0 : LineColor.Alpha == rRight.LineColor.Alpha &&
126 0 : FillColor.Red == rRight.FillColor.Red &&
127 0 : FillColor.Green == rRight.FillColor.Green &&
128 0 : FillColor.Blue == rRight.FillColor.Blue &&
129 0 : FillColor.Alpha == rRight.FillColor.Alpha &&
130 0 : LineJoin == rRight.LineJoin &&
131 0 : LineCap == rRight.LineCap &&
132 0 : BlendMode == rRight.BlendMode &&
133 0 : LineWidth == rRight.LineWidth &&
134 0 : Flatness == rRight.Flatness &&
135 0 : MiterLimit == rRight.MiterLimit &&
136 0 : DashArray == rRight.DashArray &&
137 0 : FontId == rRight.FontId &&
138 0 : TextRenderMode == rRight.TextRenderMode &&
139 0 : Transformation == rRight.Transformation &&
140 0 : Clip == rRight.Clip;
141 : }
142 :
143 0 : bool isRotatedOrSkewed() const
144 0 : { return Transformation.get( 0, 1 ) != 0.0 ||
145 0 : Transformation.get( 1, 0 ) != 0.0; }
146 : };
147 :
148 : struct GraphicsContextHash
149 : {
150 0 : size_t operator()(const GraphicsContext& rGC ) const
151 : {
152 : return size_t(rGC.LineColor.Red)
153 0 : ^ size_t(rGC.LineColor.Green)
154 0 : ^ size_t(rGC.LineColor.Blue)
155 0 : ^ size_t(rGC.LineColor.Alpha)
156 0 : ^ size_t(rGC.FillColor.Red)
157 0 : ^ size_t(rGC.FillColor.Green)
158 0 : ^ size_t(rGC.FillColor.Blue)
159 0 : ^ size_t(rGC.FillColor.Alpha)
160 0 : ^ size_t(rGC.LineJoin)
161 0 : ^ size_t(rGC.LineCap)
162 0 : ^ size_t(rGC.BlendMode)
163 0 : ^ size_t(rGC.LineWidth)
164 0 : ^ size_t(rGC.Flatness)
165 0 : ^ size_t(rGC.MiterLimit)
166 0 : ^ rGC.DashArray.size()
167 0 : ^ size_t(rGC.FontId)
168 0 : ^ size_t(rGC.TextRenderMode)
169 0 : ^ size_t(rGC.Transformation.get( 0, 0 ))
170 0 : ^ size_t(rGC.Transformation.get( 1, 0 ))
171 0 : ^ size_t(rGC.Transformation.get( 0, 1 ))
172 0 : ^ size_t(rGC.Transformation.get( 1, 1 ))
173 0 : ^ size_t(rGC.Transformation.get( 0, 2 ))
174 0 : ^ size_t(rGC.Transformation.get( 1, 2 ))
175 0 : ^ 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 : OUString& rOutPwd,
185 : bool bFirstTry,
186 : const OUString& rDocName
187 : );
188 :
189 : void reportUnsupportedEncryptionFormat(
190 : com::sun::star::uno::Reference<
191 : com::sun::star::task::XInteractionHandler > const & handler);
192 : }
193 :
194 : #endif
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|