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