Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_PDFI_HELPER_HXX
30 : : #define INCLUDED_PDFI_HELPER_HXX
31 : :
32 : : #define BASEGFX_STATICLIBRARY
33 : :
34 : : #include "contentsink.hxx"
35 : :
36 : : #include <rtl/ustring.hxx>
37 : : #include <rtl/math.h>
38 : : #include <basegfx/matrix/b2dhommatrix.hxx>
39 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
40 : : #include <basegfx/polygon/b2dpolygon.hxx>
41 : : #include <com/sun/star/rendering/XColorSpace.hpp>
42 : :
43 : : #include <vector>
44 : : #include <boost/unordered_map.hpp>
45 : :
46 : : // virtual resolution of the PDF OutputDev in dpi
47 : : #define PDFI_OUTDEV_RESOLUTION 7200
48 : :
49 : : namespace com { namespace sun { namespace star { namespace task
50 : : { class XInteractionHandler; }}}}
51 : :
52 : : namespace pdfi
53 : : {
54 : : typedef boost::unordered_map< rtl::OUString, rtl::OUString, rtl::OUStringHash > PropertyMap;
55 : : typedef sal_Int32 ImageId;
56 : :
57 : : /// What to do with a polygon. values can be ORed together
58 : : enum PolygonAction { PATH_STROKE=1, PATH_FILL=2, PATH_EOFILL=4 };
59 : :
60 : : rtl::OUString unitMMString( double fMM );
61 : : rtl::OUString convertPixelToUnitString( double fPix );
62 : :
63 : 912 : inline double convPx2mm( double fPix )
64 : : {
65 : 912 : const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
66 : 912 : fPix *= px2mm;
67 : 912 : return fPix;
68 : : }
69 : :
70 : 24 : inline double convmm2Px( double fMM )
71 : : {
72 : 24 : const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
73 : 24 : fMM *= mm2px;
74 : 24 : return fMM;
75 : : }
76 : :
77 : 372 : inline double convPx2mmPrec2( double fPix )
78 : : {
79 : 372 : return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
80 : : }
81 : :
82 : : /// Convert color to "#FEFEFE" color notation
83 : : rtl::OUString getColorString( const ::com::sun::star::rendering::ARGBColor& );
84 : :
85 : : struct FontAttrHash
86 : : {
87 : 138 : size_t operator()(const FontAttributes& rFont ) const
88 : : {
89 : 138 : return (size_t)rFont.familyName.hashCode()
90 : : ^ size_t(rFont.isBold ? 0xd47be593 : 0)
91 : : ^ size_t(rFont.isItalic ? 0x1efd51a1 : 0)
92 : : ^ size_t(rFont.isUnderline ? 0xf6bd325a : 0)
93 : : ^ size_t(rFont.isOutline ? 0x12345678 : 0)
94 [ - + ][ - + ]: 138 : ^ size_t(rFont.size)
[ - + ][ - + ]
95 : : ;
96 : : }
97 : : };
98 : :
99 [ + - # ]: 5097 : struct GraphicsContext
[ + - # ]
[ # + - ]
[ # + - ]
[ # # ][ # # ]
100 : : {
101 : : ::com::sun::star::rendering::ARGBColor LineColor;
102 : : ::com::sun::star::rendering::ARGBColor FillColor;
103 : : sal_Int8 LineJoin;
104 : : sal_Int8 LineCap;
105 : : sal_Int8 BlendMode;
106 : : double Flatness;
107 : : double LineWidth;
108 : : double MiterLimit;
109 : : std::vector<double> DashArray;
110 : : sal_Int32 FontId;
111 : : sal_Int32 TextRenderMode;
112 : : basegfx::B2DHomMatrix Transformation;
113 : : basegfx::B2DPolyPolygon Clip;
114 : :
115 : 693 : GraphicsContext() :
116 : : LineColor(),
117 : : FillColor(),
118 : : LineJoin(0),
119 : : LineCap(0),
120 : : BlendMode(0),
121 : : Flatness(0.0),
122 : : LineWidth(1.0),
123 : : MiterLimit(10.0),
124 : : DashArray(),
125 : : FontId(0),
126 : : TextRenderMode(0),
127 : : Transformation(),
128 [ + - ][ + - ]: 693 : Clip()
129 : 693 : {}
130 : :
131 : 1374 : bool operator==(const GraphicsContext& rRight ) const
132 : : {
133 : : return LineColor.Red == rRight.LineColor.Red &&
134 : : LineColor.Green == rRight.LineColor.Green &&
135 : : LineColor.Blue == rRight.LineColor.Blue &&
136 : : LineColor.Alpha == rRight.LineColor.Alpha &&
137 : : FillColor.Red == rRight.FillColor.Red &&
138 : : FillColor.Green == rRight.FillColor.Green &&
139 : : FillColor.Blue == rRight.FillColor.Blue &&
140 : : FillColor.Alpha == rRight.FillColor.Alpha &&
141 : : LineJoin == rRight.LineJoin &&
142 : : LineCap == rRight.LineCap &&
143 : : BlendMode == rRight.BlendMode &&
144 : : LineWidth == rRight.LineWidth &&
145 : : Flatness == rRight.Flatness &&
146 : : MiterLimit == rRight.MiterLimit &&
147 : 1350 : DashArray == rRight.DashArray &&
148 : : FontId == rRight.FontId &&
149 : : TextRenderMode == rRight.TextRenderMode &&
150 : 1350 : Transformation == rRight.Transformation &&
151 [ + - ][ + - ]: 4074 : Clip == rRight.Clip;
[ + - ][ + - ]
[ + + ][ + - ]
[ + + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
[ + - + - ]
[ + - ]
[ + - + - ]
[ + - ]
152 : : }
153 : :
154 : 591 : bool isRotatedOrSkewed() const
155 : 591 : { return Transformation.get( 0, 1 ) != 0.0 ||
156 [ - + ][ + - ]: 591 : Transformation.get( 1, 0 ) != 0.0; }
157 : : };
158 : :
159 : : struct GraphicsContextHash
160 : : {
161 : 1452 : size_t operator()(const GraphicsContext& rGC ) const
162 : : {
163 : : return size_t(rGC.LineColor.Red)
164 : : ^ size_t(rGC.LineColor.Green)
165 : : ^ size_t(rGC.LineColor.Blue)
166 : : ^ size_t(rGC.LineColor.Alpha)
167 : : ^ size_t(rGC.FillColor.Red)
168 : : ^ size_t(rGC.FillColor.Green)
169 : : ^ size_t(rGC.FillColor.Blue)
170 : : ^ size_t(rGC.FillColor.Alpha)
171 : : ^ size_t(rGC.LineJoin)
172 : : ^ size_t(rGC.LineCap)
173 : : ^ size_t(rGC.BlendMode)
174 : : ^ size_t(rGC.LineWidth)
175 : : ^ size_t(rGC.Flatness)
176 : : ^ size_t(rGC.MiterLimit)
177 : 1452 : ^ rGC.DashArray.size()
178 : : ^ size_t(rGC.FontId)
179 : : ^ size_t(rGC.TextRenderMode)
180 : 1452 : ^ size_t(rGC.Transformation.get( 0, 0 ))
181 : 1452 : ^ size_t(rGC.Transformation.get( 1, 0 ))
182 : 1452 : ^ size_t(rGC.Transformation.get( 0, 1 ))
183 : 1452 : ^ size_t(rGC.Transformation.get( 1, 1 ))
184 : 1452 : ^ size_t(rGC.Transformation.get( 0, 2 ))
185 : 1452 : ^ size_t(rGC.Transformation.get( 1, 2 ))
186 [ + - ][ + - ]: 1452 : ^ size_t(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0)
[ + + ][ # # ]
[ + + ]
187 : : ;
188 : : }
189 : : };
190 : :
191 : : /** retrieve password from user
192 : : */
193 : : bool getPassword( const ::com::sun::star::uno::Reference<
194 : : ::com::sun::star::task::XInteractionHandler >& xHandler,
195 : : rtl::OUString& rOutPwd,
196 : : bool bFirstTry,
197 : : const rtl::OUString& rDocName
198 : : );
199 : : }
200 : :
201 : : #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
202 : :
203 : : #endif
204 : :
205 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|