merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / pdfimport / inc / pdfihelper.hxx
blobc27913399cb08d6abff20c52fd55eeb8042bebe3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pdfihelper.hxx,v $
11 * $Revision: 1.2 $
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>
38 #include <rtl/math.h>
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>
44 #include <vector>
45 #include <hash_map>
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; }}}}
53 namespace pdfi
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;
67 fPix *= px2mm;
68 return fPix;
71 inline double convmm2Px( double fMM )
73 const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
74 fMM *= mm2px;
75 return fMM;
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& );
86 struct FontAttrHash
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)
95 ^ size_t(rFont.size)
100 struct GraphicsContext
102 ::com::sun::star::rendering::ARGBColor LineColor;
103 ::com::sun::star::rendering::ARGBColor FillColor;
104 sal_Int8 LineJoin;
105 sal_Int8 LineCap;
106 sal_Int8 BlendMode;
107 double Flatness;
108 double LineWidth;
109 double MiterLimit;
110 std::vector<double> DashArray;
111 sal_Int32 FontId;
112 sal_Int32 TextRenderMode;
113 basegfx::B2DHomMatrix Transformation;
114 basegfx::B2DPolyPolygon Clip;
116 GraphicsContext() :
117 LineColor(),
118 FillColor(),
119 LineJoin(0),
120 LineCap(0),
121 BlendMode(0),
122 Flatness(0.0),
123 LineWidth(1.0),
124 MiterLimit(10.0),
125 DashArray(),
126 FontId(0),
127 TextRenderMode(0),
128 Transformation(),
129 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 &&
152 Clip == rRight.Clip;
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()
179 ^ size_t(rGC.FontId)
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,
197 bool bFirstTry );
200 #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
202 #endif