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