LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillpropertiesgroupcontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 137 165 83.0 %
Date: 2014-11-03 Functions: 26 33 78.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "drawingml/fillpropertiesgroupcontext.hxx"
      21             : #include "oox/helper/attributelist.hxx"
      22             : #include "oox/helper/graphichelper.hxx"
      23             : #include "oox/core/xmlfilterbase.hxx"
      24             : #include "oox/drawingml/drawingmltypes.hxx"
      25             : #include "oox/drawingml/fillproperties.hxx"
      26             : #include <sfx2/docfile.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::xml::sax;
      31             : using ::oox::core::ContextHandler2;
      32             : using ::oox::core::XmlFilterBase;
      33             : using ::oox::core::ContextHandlerRef;
      34             : 
      35             : namespace oox {
      36             : namespace drawingml {
      37             : 
      38       18540 : SolidFillContext::SolidFillContext( ContextHandler2Helper& rParent,
      39             :         const AttributeList&, FillProperties& rFillProps ) :
      40       18540 :     ColorContext( rParent, rFillProps.maFillColor )
      41             : {
      42       18540 : }
      43             : 
      44       10266 : GradientFillContext::GradientFillContext( ContextHandler2Helper& rParent,
      45             :         const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) :
      46             :     ContextHandler2( rParent ),
      47       10266 :     mrGradientProps( rGradientProps )
      48             : {
      49       10266 :     mrGradientProps.moShadeFlip = rAttribs.getToken( XML_flip );
      50       10266 :     mrGradientProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
      51       10266 : }
      52             : 
      53       53596 : ContextHandlerRef GradientFillContext::onCreateContext(
      54             :         sal_Int32 nElement, const AttributeList& rAttribs )
      55             : {
      56       53596 :     switch( nElement )
      57             :     {
      58             :         case A_TOKEN( gsLst ):
      59       10266 :             return this;    // for gs elements
      60             : 
      61             :         case A_TOKEN( gs ):
      62       28320 :             if( rAttribs.hasAttribute( XML_pos ) )
      63             :             {
      64       28320 :                 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
      65       28320 :                 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
      66             :             }
      67           0 :         break;
      68             : 
      69             :         case A_TOKEN( lin ):
      70        5558 :             mrGradientProps.moShadeAngle = rAttribs.getInteger( XML_ang );
      71        5558 :             mrGradientProps.moShadeScaled = rAttribs.getBool( XML_scaled );
      72        5558 :         break;
      73             : 
      74             :         case A_TOKEN( path ):
      75             :             // always set a path type, this disables linear gradient in conversion
      76        4708 :             mrGradientProps.moGradientPath = rAttribs.getToken( XML_path, XML_rect );
      77        4708 :             return this;    // for fillToRect element
      78             : 
      79             :         case A_TOKEN( fillToRect ):
      80        4708 :             mrGradientProps.moFillToRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      81        4708 :         break;
      82             : 
      83             :         case A_TOKEN( tileRect ):
      84          36 :             mrGradientProps.moTileRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      85          36 :         break;
      86             :     }
      87       10302 :     return 0;
      88             : }
      89             : 
      90         194 : PatternFillContext::PatternFillContext( ContextHandler2Helper& rParent,
      91             :         const AttributeList& rAttribs, PatternFillProperties& rPatternProps ) :
      92             :     ContextHandler2( rParent ),
      93         194 :     mrPatternProps( rPatternProps )
      94             : {
      95         194 :     mrPatternProps.moPattPreset = rAttribs.getToken( XML_prst );
      96         194 : }
      97             : 
      98         388 : ContextHandlerRef PatternFillContext::onCreateContext(
      99             :         sal_Int32 nElement, const AttributeList& )
     100             : {
     101         388 :     switch( nElement )
     102             :     {
     103             :         case A_TOKEN( bgClr ):
     104         194 :             return new ColorContext( *this, mrPatternProps.maPattBgColor );
     105             :         case A_TOKEN( fgClr ):
     106         194 :             return new ColorContext( *this, mrPatternProps.maPattFgColor );
     107             :     }
     108           0 :     return 0;
     109             : }
     110             : 
     111           0 : ColorChangeContext::ColorChangeContext( ContextHandler2Helper& rParent,
     112             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     113             :     ContextHandler2( rParent ),
     114           0 :     mrBlipProps( rBlipProps )
     115             : {
     116           0 :     mrBlipProps.maColorChangeFrom.setUnused();
     117           0 :     mrBlipProps.maColorChangeTo.setUnused();
     118           0 :     mbUseAlpha = rAttribs.getBool( XML_useA, true );
     119           0 : }
     120             : 
     121           0 : ColorChangeContext::~ColorChangeContext()
     122             : {
     123           0 :     if( !mbUseAlpha )
     124           0 :         mrBlipProps.maColorChangeTo.clearTransparence();
     125           0 : }
     126             : 
     127           0 : ContextHandlerRef ColorChangeContext::onCreateContext(
     128             :         sal_Int32 nElement, const AttributeList& )
     129             : {
     130           0 :     switch( nElement )
     131             :     {
     132             :         case A_TOKEN( clrFrom ):
     133           0 :             return new ColorContext( *this, mrBlipProps.maColorChangeFrom );
     134             :         case A_TOKEN( clrTo ):
     135           0 :             return new ColorContext( *this, mrBlipProps.maColorChangeTo );
     136             :     }
     137           0 :     return 0;
     138             : }
     139             : 
     140         744 : BlipContext::BlipContext( ContextHandler2Helper& rParent,
     141             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     142             :     ContextHandler2( rParent ),
     143         744 :     mrBlipProps( rBlipProps )
     144             : {
     145         744 :     if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     146             :     {
     147             :         // internal picture URL
     148         732 :         OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     149         732 :         if( !aFragmentPath.isEmpty() )
     150         708 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath );
     151             :     }
     152          12 :     else if( rAttribs.hasAttribute( R_TOKEN( link ) ) )
     153             :     {
     154             :         // external URL
     155             : 
     156             :         // we will embed this link, this is better than just doing nothing..
     157             :         // TODO: import this graphic as real link, but this requires some
     158             :         // code rework.
     159           4 :         OUString aRelId = rAttribs.getString( R_TOKEN( link ), OUString() );
     160           8 :         OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
     161           8 :         SfxMedium xMed( aTargetLink, STREAM_STD_READ );
     162           4 :         xMed.Download();
     163           8 :         Reference< io::XInputStream > xInStrm = xMed.GetInputStream();
     164           4 :         if ( xInStrm.is() )
     165           4 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importGraphic( xInStrm );
     166             :     }
     167         744 : }
     168             : 
     169         426 : ContextHandlerRef BlipContext::onCreateContext(
     170             :         sal_Int32 nElement, const AttributeList& rAttribs )
     171             : {
     172         426 :     switch( nElement )
     173             :     {
     174             :         case A_TOKEN( biLevel ):
     175             :         case A_TOKEN( grayscl ):
     176           2 :             mrBlipProps.moColorEffect = getBaseToken( nElement );
     177           2 :         break;
     178             : 
     179             :         case A_TOKEN( clrChange ):
     180           0 :             return new ColorChangeContext( *this, rAttribs, mrBlipProps );
     181             : 
     182             :         case A_TOKEN( duotone ):
     183          42 :             return new DuotoneContext( *this, rAttribs, mrBlipProps );
     184             : 
     185             :         case A_TOKEN( extLst ):
     186         360 :             return new BlipExtensionContext( *this, mrBlipProps );
     187             : 
     188             :         case A_TOKEN( lum ):
     189          14 :             mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
     190          14 :             mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
     191          14 :         break;
     192             :     }
     193          24 :     return 0;
     194             : }
     195             : 
     196          42 : DuotoneContext::DuotoneContext( ContextHandler2Helper& rParent,
     197             :         const AttributeList& /*rAttribs*/, BlipFillProperties& rBlipProps ) :
     198             :     ContextHandler2( rParent ),
     199             :     mrBlipProps( rBlipProps ),
     200          42 :     mnColorIndex( 0 )
     201             : {
     202          42 :     mrBlipProps.maDuotoneColors[0].setUnused();
     203          42 :     mrBlipProps.maDuotoneColors[1].setUnused();
     204          42 : }
     205             : 
     206          84 : DuotoneContext::~DuotoneContext()
     207             : {
     208          84 : }
     209             : 
     210          84 : ::oox::core::ContextHandlerRef DuotoneContext::onCreateContext(
     211             :         sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
     212             : {
     213          84 :     if( mnColorIndex < 2 )
     214          84 :         return new ColorValueContext( *this, mrBlipProps.maDuotoneColors[mnColorIndex++] );
     215           0 :     return 0;
     216             : }
     217             : 
     218         748 : BlipFillContext::BlipFillContext( ContextHandler2Helper& rParent,
     219             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     220             :     ContextHandler2( rParent ),
     221         748 :     mrBlipProps( rBlipProps )
     222             : {
     223         748 :     mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
     224         748 : }
     225             : 
     226        2450 : ContextHandlerRef BlipFillContext::onCreateContext(
     227             :         sal_Int32 nElement, const AttributeList& rAttribs )
     228             : {
     229        2450 :     switch( nElement )
     230             :     {
     231             :         case A_TOKEN( blip ):
     232         744 :             return new BlipContext( *this, rAttribs, mrBlipProps );
     233             : 
     234             :         case A_TOKEN( srcRect ):
     235         338 :             mrBlipProps.moClipRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     236         338 :         break;
     237             : 
     238             :         case A_TOKEN( tile ):
     239          44 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     240          44 :             mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
     241          44 :             mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
     242          44 :             mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
     243          44 :             mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
     244          44 :             mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
     245          44 :             mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
     246          44 :         break;
     247             : 
     248             :         case A_TOKEN( stretch ):
     249         704 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     250         704 :             return this;    // for fillRect element
     251             : 
     252             :         case A_TOKEN( fillRect ):
     253         620 :             mrBlipProps.moFillRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     254         620 :         break;
     255             :     }
     256        1002 :     return 0;
     257             : }
     258             : 
     259          48 : FillPropertiesContext::FillPropertiesContext( ContextHandler2Helper& rParent, FillProperties& rFillProps ) :
     260             :     ContextHandler2( rParent ),
     261          48 :     mrFillProps( rFillProps )
     262             : {
     263          48 : }
     264             : 
     265          48 : ContextHandlerRef FillPropertiesContext::onCreateContext(
     266             :         sal_Int32 nElement, const AttributeList& rAttribs )
     267             : {
     268          48 :     return createFillContext( *this, nElement, rAttribs, mrFillProps );
     269             : }
     270             : 
     271       33124 : ContextHandlerRef FillPropertiesContext::createFillContext(
     272             :         ContextHandler2Helper& rParent, sal_Int32 nElement,
     273             :         const AttributeList& rAttribs, FillProperties& rFillProps )
     274             : {
     275       33124 :     switch( nElement )
     276             :     {
     277        3428 :         case A_TOKEN( noFill ):     { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
     278       18540 :         case A_TOKEN( solidFill ):  { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rAttribs, rFillProps ); };
     279       10264 :         case A_TOKEN( gradFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
     280         194 :         case A_TOKEN( pattFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
     281         232 :         case A_TOKEN( blipFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); };
     282           0 :         case A_TOKEN( grpFill ):    { rFillProps.moFillType = getBaseToken( nElement ); return 0; };    // TODO
     283             :     }
     284         466 :     return 0;
     285             : }
     286             : 
     287           0 : SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler2Helper& rParent, Color& rColor ) :
     288             :     FillPropertiesContext( rParent, *this ),
     289           0 :     mrColor( rColor )
     290             : {
     291           0 : }
     292             : 
     293           0 : SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
     294             : {
     295           0 :     mrColor = getBestSolidColor();
     296           0 : }
     297             : 
     298         746 : BlipExtensionContext::BlipExtensionContext( ContextHandler2Helper& rParent, BlipFillProperties& rBlipProps ) :
     299             :     ContextHandler2( rParent ),
     300         746 :     mrBlipProps( rBlipProps )
     301             : {
     302         746 : }
     303             : 
     304        1492 : BlipExtensionContext::~BlipExtensionContext()
     305             : {
     306        1492 : }
     307             : 
     308         424 : ContextHandlerRef BlipExtensionContext::onCreateContext(
     309             :         sal_Int32 nElement, const AttributeList& )
     310             : {
     311         424 :     switch( nElement )
     312             :     {
     313             :         case A_TOKEN( ext ):
     314         386 :             return new BlipExtensionContext( *this, mrBlipProps );
     315             : 
     316             :         case OOX_TOKEN( a14, imgProps ):
     317          38 :             return new ArtisticEffectContext( *this, mrBlipProps.maEffect );
     318             :     }
     319           0 :     return 0;
     320             : }
     321             : 
     322         114 : ArtisticEffectContext::ArtisticEffectContext( ContextHandler2Helper& rParent, ArtisticEffectProperties& rEffect ) :
     323             :     ContextHandler2( rParent ),
     324         114 :     maEffect( rEffect )
     325             : {
     326         114 : }
     327             : 
     328         228 : ArtisticEffectContext::~ArtisticEffectContext()
     329             : {
     330         228 : }
     331             : 
     332         114 : ContextHandlerRef ArtisticEffectContext::onCreateContext(
     333             :         sal_Int32 nElement, const AttributeList& rAttribs )
     334             : {
     335             :     // containers
     336         114 :     if( nElement == OOX_TOKEN( a14, imgLayer ) )
     337             :     {
     338          38 :         if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     339             :         {
     340          38 :             OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     341          38 :             if( !aFragmentPath.isEmpty() )
     342             :             {
     343          38 :                 getFilter().importBinaryData( maEffect.mrOleObjectInfo.maEmbeddedData, aFragmentPath );
     344          38 :                 maEffect.mrOleObjectInfo.maProgId = aFragmentPath;
     345          38 :             }
     346             :         }
     347          38 :         return new ArtisticEffectContext( *this, maEffect );
     348             :     }
     349          76 :     if( nElement == OOX_TOKEN( a14, imgEffect ) )
     350          38 :         return new ArtisticEffectContext( *this, maEffect );
     351             : 
     352             :     // effects
     353          38 :     maEffect.msName = ArtisticEffectProperties::getEffectString( nElement );
     354          38 :     if( maEffect.isEmpty() )
     355           0 :         return 0;
     356             : 
     357             :     // effect attributes
     358             :     sal_Int32 aAttribs[19] = {
     359             :             XML_visible, XML_trans, XML_crackSpacing, XML_pressure, XML_numberOfShades,
     360             :             XML_grainSize, XML_intensity, XML_smoothness, XML_gridSize, XML_pencilSize,
     361             :             XML_size, XML_brushSize, XML_scaling, XML_detail, XML_bright, XML_contrast,
     362             :             XML_colorTemp, XML_sat, XML_amount
     363          38 :     };
     364         760 :     for( sal_Int32 i=0; i<19; ++i )
     365             :     {
     366         722 :         if( rAttribs.hasAttribute( aAttribs[i] ) )
     367             :         {
     368          54 :             OUString sName = ArtisticEffectProperties::getEffectString( aAttribs[i] );
     369          54 :             if( !sName.isEmpty() )
     370          54 :                 maEffect.maAttribs[sName] = uno::makeAny( rAttribs.getInteger( aAttribs[i], 0 ) );
     371             :         }
     372             :     }
     373             : 
     374          38 :     return 0;
     375             : }
     376             : 
     377             : } // namespace drawingml
     378         408 : } // namespace oox
     379             : 
     380             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10