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 #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 29*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 30*cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx" 31*cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx" 32*cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx" 33*cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using ::rtl::OUString; 36*cdf0e10cSrcweir using namespace ::com::sun::star; 37*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 38*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 39*cdf0e10cSrcweir using ::oox::core::ContextHandler; 40*cdf0e10cSrcweir using ::oox::core::XmlFilterBase; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace oox { 43*cdf0e10cSrcweir namespace drawingml { 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // ============================================================================ 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir SolidFillContext::SolidFillContext( ContextHandler& rParent, 48*cdf0e10cSrcweir const Reference< XFastAttributeList >&, FillProperties& rFillProps ) : 49*cdf0e10cSrcweir ColorContext( rParent, rFillProps.maFillColor ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // ============================================================================ 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir GradientFillContext::GradientFillContext( ContextHandler& rParent, 56*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, GradientFillProperties& rGradientProps ) : 57*cdf0e10cSrcweir ContextHandler( rParent ), 58*cdf0e10cSrcweir mrGradientProps( rGradientProps ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 61*cdf0e10cSrcweir mrGradientProps.moShadeFlip = aAttribs.getToken( XML_flip ); 62*cdf0e10cSrcweir mrGradientProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape ); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir Reference< XFastContextHandler > GradientFillContext::createFastChildContext( 66*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 69*cdf0e10cSrcweir switch( nElement ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir case A_TOKEN( gsLst ): 72*cdf0e10cSrcweir return this; // for gs elements 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir case A_TOKEN( gs ): 75*cdf0e10cSrcweir if( aAttribs.hasAttribute( XML_pos ) ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir double fPosition = getLimitedValue< double >( aAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 ); 78*cdf0e10cSrcweir return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] ); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir break; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir case A_TOKEN( lin ): 83*cdf0e10cSrcweir mrGradientProps.moShadeAngle = aAttribs.getInteger( XML_ang ); 84*cdf0e10cSrcweir mrGradientProps.moShadeScaled = aAttribs.getBool( XML_scaled ); 85*cdf0e10cSrcweir break; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir case A_TOKEN( path ): 88*cdf0e10cSrcweir // always set a path type, this disables linear gradient in conversion 89*cdf0e10cSrcweir mrGradientProps.moGradientPath = aAttribs.getToken( XML_path, XML_rect ); 90*cdf0e10cSrcweir return this; // for fillToRect element 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir case A_TOKEN( fillToRect ): 93*cdf0e10cSrcweir mrGradientProps.moFillToRect = GetRelativeRect( rxAttribs ); 94*cdf0e10cSrcweir break; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir case A_TOKEN( tileRect ): 97*cdf0e10cSrcweir mrGradientProps.moTileRect = GetRelativeRect( rxAttribs ); 98*cdf0e10cSrcweir break; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir return 0; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // ============================================================================ 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir PatternFillContext::PatternFillContext( ContextHandler& rParent, 106*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, PatternFillProperties& rPatternProps ) : 107*cdf0e10cSrcweir ContextHandler( rParent ), 108*cdf0e10cSrcweir mrPatternProps( rPatternProps ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 111*cdf0e10cSrcweir mrPatternProps.moPattPreset = aAttribs.getToken( XML_prst ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir Reference< XFastContextHandler > PatternFillContext::createFastChildContext( 115*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir switch( nElement ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir case A_TOKEN( bgClr ): 120*cdf0e10cSrcweir return new ColorContext( *this, mrPatternProps.maPattBgColor ); 121*cdf0e10cSrcweir case A_TOKEN( fgClr ): 122*cdf0e10cSrcweir return new ColorContext( *this, mrPatternProps.maPattFgColor ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir return 0; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // ============================================================================ 128*cdf0e10cSrcweir // ============================================================================ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ColorChangeContext::ColorChangeContext( ContextHandler& rParent, 131*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) : 132*cdf0e10cSrcweir ContextHandler( rParent ), 133*cdf0e10cSrcweir mrBlipProps( rBlipProps ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir mrBlipProps.maColorChangeFrom.setUnused(); 136*cdf0e10cSrcweir mrBlipProps.maColorChangeTo.setUnused(); 137*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 138*cdf0e10cSrcweir mbUseAlpha = aAttribs.getBool( XML_useA, true ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir ColorChangeContext::~ColorChangeContext() 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir if( !mbUseAlpha ) 144*cdf0e10cSrcweir mrBlipProps.maColorChangeTo.clearTransparence(); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir Reference< XFastContextHandler > ColorChangeContext::createFastChildContext( 148*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir switch( nElement ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir case A_TOKEN( clrFrom ): 153*cdf0e10cSrcweir return new ColorContext( *this, mrBlipProps.maColorChangeFrom ); 154*cdf0e10cSrcweir case A_TOKEN( clrTo ): 155*cdf0e10cSrcweir return new ColorContext( *this, mrBlipProps.maColorChangeTo ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir return 0; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // ============================================================================ 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir BlipContext::BlipContext( ContextHandler& rParent, 163*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) : 164*cdf0e10cSrcweir ContextHandler( rParent ), 165*cdf0e10cSrcweir mrBlipProps( rBlipProps ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 168*cdf0e10cSrcweir if( aAttribs.hasAttribute( R_TOKEN( embed ) ) ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir // internal picture URL 171*cdf0e10cSrcweir OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( embed ), OUString() ) ); 172*cdf0e10cSrcweir if( aFragmentPath.getLength() > 0 ) 173*cdf0e10cSrcweir mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir else if( aAttribs.hasAttribute( R_TOKEN( link ) ) ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir // external URL 178*cdf0e10cSrcweir OUString aRelId = aAttribs.getString( R_TOKEN( link ), OUString() ); 179*cdf0e10cSrcweir OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) ); 180*cdf0e10cSrcweir // TODO: load external picture 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir Reference< XFastContextHandler > BlipContext::createFastChildContext( 185*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 188*cdf0e10cSrcweir switch( nElement ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir case A_TOKEN( biLevel ): 191*cdf0e10cSrcweir case A_TOKEN( grayscl ): 192*cdf0e10cSrcweir mrBlipProps.moColorEffect = getBaseToken( nElement ); 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir case A_TOKEN( clrChange ): 196*cdf0e10cSrcweir return new ColorChangeContext( *this, rxAttribs, mrBlipProps ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir case A_TOKEN( lum ): 199*cdf0e10cSrcweir mrBlipProps.moBrightness = aAttribs.getInteger( XML_bright ); 200*cdf0e10cSrcweir mrBlipProps.moContrast = aAttribs.getInteger( XML_contrast ); 201*cdf0e10cSrcweir break; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir return 0; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // ============================================================================ 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir BlipFillContext::BlipFillContext( ContextHandler& rParent, 209*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) : 210*cdf0e10cSrcweir ContextHandler( rParent ), 211*cdf0e10cSrcweir mrBlipProps( rBlipProps ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 214*cdf0e10cSrcweir mrBlipProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape ); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir Reference< XFastContextHandler > BlipFillContext::createFastChildContext( 218*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 221*cdf0e10cSrcweir switch( nElement ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir case A_TOKEN( blip ): 224*cdf0e10cSrcweir return new BlipContext( *this, rxAttribs, mrBlipProps ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir case A_TOKEN( srcRect ): 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir rtl::OUString aDefault( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) ); 229*cdf0e10cSrcweir ::com::sun::star::geometry::IntegerRectangle2D aClipRect; 230*cdf0e10cSrcweir aClipRect.X1 = GetPercent( aAttribs.getString( XML_l, aDefault ) ); 231*cdf0e10cSrcweir aClipRect.Y1 = GetPercent( aAttribs.getString( XML_t, aDefault ) ); 232*cdf0e10cSrcweir aClipRect.X2 = GetPercent( aAttribs.getString( XML_r, aDefault ) ); 233*cdf0e10cSrcweir aClipRect.Y2 = GetPercent( aAttribs.getString( XML_b, aDefault ) ); 234*cdf0e10cSrcweir mrBlipProps.moClipRect = aClipRect; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir break; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir case A_TOKEN( tile ): 239*cdf0e10cSrcweir mrBlipProps.moBitmapMode = getBaseToken( nElement ); 240*cdf0e10cSrcweir mrBlipProps.moTileOffsetX = aAttribs.getInteger( XML_tx ); 241*cdf0e10cSrcweir mrBlipProps.moTileOffsetY = aAttribs.getInteger( XML_ty ); 242*cdf0e10cSrcweir mrBlipProps.moTileScaleX = aAttribs.getInteger( XML_sx ); 243*cdf0e10cSrcweir mrBlipProps.moTileScaleY = aAttribs.getInteger( XML_sy ); 244*cdf0e10cSrcweir mrBlipProps.moTileAlign = aAttribs.getToken( XML_algn ); 245*cdf0e10cSrcweir mrBlipProps.moTileFlip = aAttribs.getToken( XML_flip ); 246*cdf0e10cSrcweir break; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir case A_TOKEN( stretch ): 249*cdf0e10cSrcweir mrBlipProps.moBitmapMode = getBaseToken( nElement ); 250*cdf0e10cSrcweir return this; // for fillRect element 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir case A_TOKEN( fillRect ): 253*cdf0e10cSrcweir mrBlipProps.moFillRect = GetRelativeRect( rxAttribs ); 254*cdf0e10cSrcweir break; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir return 0; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // ============================================================================ 260*cdf0e10cSrcweir // ============================================================================ 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir FillPropertiesContext::FillPropertiesContext( ContextHandler& rParent, FillProperties& rFillProps ) : 263*cdf0e10cSrcweir ContextHandler( rParent ), 264*cdf0e10cSrcweir mrFillProps( rFillProps ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir Reference< XFastContextHandler > FillPropertiesContext::createFastChildContext( 269*cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) 270*cdf0e10cSrcweir throw ( SAXException, RuntimeException ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir return createFillContext( *this, nElement, rxAttribs, mrFillProps ); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir /*static*/ Reference< XFastContextHandler > FillPropertiesContext::createFillContext( 276*cdf0e10cSrcweir ContextHandler& rParent, sal_Int32 nElement, 277*cdf0e10cSrcweir const Reference< XFastAttributeList >& rxAttribs, FillProperties& rFillProps ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir switch( nElement ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; }; 282*cdf0e10cSrcweir case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rxAttribs, rFillProps ); }; 283*cdf0e10cSrcweir case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rxAttribs, rFillProps.maGradientProps ); }; 284*cdf0e10cSrcweir case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rxAttribs, rFillProps.maPatternProps ); }; 285*cdf0e10cSrcweir case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rxAttribs, rFillProps.maBlipProps ); }; 286*cdf0e10cSrcweir case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; }; // TODO 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir return 0; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir // ============================================================================ 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler& rParent, Color& rColor ) : 294*cdf0e10cSrcweir FillPropertiesContext( rParent, *this ), 295*cdf0e10cSrcweir mrColor( rColor ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir SimpleFillPropertiesContext::~SimpleFillPropertiesContext() 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir mrColor = getBestSolidColor(); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // ============================================================================ 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir } // namespace drawingml 307*cdf0e10cSrcweir } // namespace oox 308*cdf0e10cSrcweir 309