1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pdfihelper.hxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef INCLUDED_PDFI_HELPER_HXX
33 #define INCLUDED_PDFI_HELPER_HXX
35 #include "contentsink.hxx"
37 #include <rtl/ustring.hxx>
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
42 #include <com/sun/star/rendering/XColorSpace.hpp>
47 // virtual resolution of the PDF OutputDev in dpi
48 #define PDFI_OUTDEV_RESOLUTION 7200
50 namespace com
{ namespace sun
{ namespace star
{ namespace task
51 { class XInteractionHandler
; }}}}
55 typedef std::hash_map
< rtl::OUString
, rtl::OUString
, rtl::OUStringHash
> PropertyMap
;
56 typedef sal_Int32 ImageId
;
58 /// What to do with a polygon. values can be ORed together
59 enum PolygonAction
{ PATH_STROKE
=1, PATH_FILL
=2, PATH_EOFILL
=4 };
61 rtl::OUString
unitMMString( double fMM
);
62 rtl::OUString
convertPixelToUnitString( double fPix
);
64 inline double convPx2mm( double fPix
)
66 const double px2mm
= 25.4/PDFI_OUTDEV_RESOLUTION
;
71 inline double convmm2Px( double fMM
)
73 const double mm2px
= PDFI_OUTDEV_RESOLUTION
/25.4;
78 inline double convPx2mmPrec2( double fPix
)
80 return rtl_math_round( convPx2mm( fPix
), 2, rtl_math_RoundingMode_Floor
);
83 /// Convert color to "#FEFEFE" color notation
84 rtl::OUString
getColorString( const ::com::sun::star::rendering::ARGBColor
& );
88 size_t operator()(const FontAttributes
& rFont
) const
90 return (size_t)rFont
.familyName
.hashCode()
91 ^ size_t(rFont
.isBold
? 0xd47be593 : 0)
92 ^ size_t(rFont
.isItalic
? 0x1efd51a1 : 0)
93 ^ size_t(rFont
.isUnderline
? 0xf6bd325a : 0)
94 ^ size_t(rFont
.isOutline
? 0x12345678 : 0)
100 struct GraphicsContext
102 ::com::sun::star::rendering::ARGBColor LineColor
;
103 ::com::sun::star::rendering::ARGBColor FillColor
;
110 std::vector
<double> DashArray
;
112 sal_Int32 TextRenderMode
;
113 basegfx::B2DHomMatrix Transformation
;
114 basegfx::B2DPolyPolygon Clip
;
132 bool operator==(const GraphicsContext
& rRight
) const
134 return LineColor
.Red
== rRight
.LineColor
.Red
&&
135 LineColor
.Green
== rRight
.LineColor
.Green
&&
136 LineColor
.Blue
== rRight
.LineColor
.Blue
&&
137 LineColor
.Alpha
== rRight
.LineColor
.Alpha
&&
138 FillColor
.Red
== rRight
.FillColor
.Red
&&
139 FillColor
.Green
== rRight
.FillColor
.Green
&&
140 FillColor
.Blue
== rRight
.FillColor
.Blue
&&
141 FillColor
.Alpha
== rRight
.FillColor
.Alpha
&&
142 LineJoin
== rRight
.LineJoin
&&
143 LineCap
== rRight
.LineCap
&&
144 BlendMode
== rRight
.BlendMode
&&
145 LineWidth
== rRight
.LineWidth
&&
146 Flatness
== rRight
.Flatness
&&
147 MiterLimit
== rRight
.MiterLimit
&&
148 DashArray
== rRight
.DashArray
&&
149 FontId
== rRight
.FontId
&&
150 TextRenderMode
== rRight
.TextRenderMode
&&
151 Transformation
== rRight
.Transformation
&&
155 bool isRotatedOrSkewed() const
156 { return Transformation
.get( 0, 1 ) != 0.0 ||
157 Transformation
.get( 1, 0 ) != 0.0; }
160 struct GraphicsContextHash
162 size_t operator()(const GraphicsContext
& rGC
) const
164 return size_t(rGC
.LineColor
.Red
)
165 ^ size_t(rGC
.LineColor
.Green
)
166 ^ size_t(rGC
.LineColor
.Blue
)
167 ^ size_t(rGC
.LineColor
.Alpha
)
168 ^ size_t(rGC
.FillColor
.Red
)
169 ^ size_t(rGC
.FillColor
.Green
)
170 ^ size_t(rGC
.FillColor
.Blue
)
171 ^ size_t(rGC
.FillColor
.Alpha
)
172 ^ size_t(rGC
.LineJoin
)
173 ^ size_t(rGC
.LineCap
)
174 ^ size_t(rGC
.BlendMode
)
175 ^ size_t(rGC
.LineWidth
)
176 ^ size_t(rGC
.Flatness
)
177 ^ size_t(rGC
.MiterLimit
)
178 ^ rGC
.DashArray
.size()
180 ^ size_t(rGC
.TextRenderMode
)
181 ^ size_t(rGC
.Transformation
.get( 0, 0 ))
182 ^ size_t(rGC
.Transformation
.get( 1, 0 ))
183 ^ size_t(rGC
.Transformation
.get( 0, 1 ))
184 ^ size_t(rGC
.Transformation
.get( 1, 1 ))
185 ^ size_t(rGC
.Transformation
.get( 0, 2 ))
186 ^ size_t(rGC
.Transformation
.get( 1, 2 ))
187 ^ size_t(rGC
.Clip
.count() ? rGC
.Clip
.getB2DPolygon(0).count() : 0)
192 /** retrieve password from user
194 bool getPassword( const ::com::sun::star::uno::Reference
<
195 ::com::sun::star::task::XInteractionHandler
>& xHandler
,
196 rtl::OUString
& rOutPwd
,
200 #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )