LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillpropertiesgroupcontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 143 165 86.7 %
Date: 2015-06-13 12:38:46 Functions: 29 33 87.9 %
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       10658 : SolidFillContext::SolidFillContext( ContextHandler2Helper& rParent,
      39             :         const AttributeList&, FillProperties& rFillProps ) :
      40       10658 :     ColorContext( rParent, rFillProps.maFillColor )
      41             : {
      42       10658 : }
      43             : 
      44        5611 : GradientFillContext::GradientFillContext( ContextHandler2Helper& rParent,
      45             :         const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) :
      46             :     ContextHandler2( rParent ),
      47        5611 :     mrGradientProps( rGradientProps )
      48             : {
      49        5611 :     mrGradientProps.moShadeFlip = rAttribs.getToken( XML_flip );
      50        5611 :     mrGradientProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
      51        5611 : }
      52             : 
      53       29268 : ContextHandlerRef GradientFillContext::onCreateContext(
      54             :         sal_Int32 nElement, const AttributeList& rAttribs )
      55             : {
      56       29268 :     switch( nElement )
      57             :     {
      58             :         case A_TOKEN( gsLst ):
      59        5611 :             return this;    // for gs elements
      60             : 
      61             :         case A_TOKEN( gs ):
      62       15498 :             if( rAttribs.hasAttribute( XML_pos ) )
      63             :             {
      64       15498 :                 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
      65       15498 :                 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
      66             :             }
      67           0 :         break;
      68             : 
      69             :         case A_TOKEN( lin ):
      70        3085 :             mrGradientProps.moShadeAngle = rAttribs.getInteger( XML_ang );
      71        3085 :             mrGradientProps.moShadeScaled = rAttribs.getBool( XML_scaled );
      72        3085 :         break;
      73             : 
      74             :         case A_TOKEN( path ):
      75             :             // always set a path type, this disables linear gradient in conversion
      76        2526 :             mrGradientProps.moGradientPath = rAttribs.getToken( XML_path, XML_rect );
      77        2526 :             return this;    // for fillToRect element
      78             : 
      79             :         case A_TOKEN( fillToRect ):
      80        2525 :             mrGradientProps.moFillToRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      81        2525 :         break;
      82             : 
      83             :         case A_TOKEN( tileRect ):
      84          23 :             mrGradientProps.moTileRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      85          23 :         break;
      86             :     }
      87        5633 :     return 0;
      88             : }
      89             : 
      90          97 : PatternFillContext::PatternFillContext( ContextHandler2Helper& rParent,
      91             :         const AttributeList& rAttribs, PatternFillProperties& rPatternProps ) :
      92             :     ContextHandler2( rParent ),
      93          97 :     mrPatternProps( rPatternProps )
      94             : {
      95          97 :     mrPatternProps.moPattPreset = rAttribs.getToken( XML_prst );
      96          97 : }
      97             : 
      98         194 : ContextHandlerRef PatternFillContext::onCreateContext(
      99             :         sal_Int32 nElement, const AttributeList& )
     100             : {
     101         194 :     switch( nElement )
     102             :     {
     103             :         case A_TOKEN( bgClr ):
     104          97 :             return new ColorContext( *this, mrPatternProps.maPattBgColor );
     105             :         case A_TOKEN( fgClr ):
     106          97 :             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         447 : BlipContext::BlipContext( ContextHandler2Helper& rParent,
     141             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     142             :     ContextHandler2( rParent ),
     143         447 :     mrBlipProps( rBlipProps )
     144             : {
     145         447 :     if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     146             :     {
     147             :         // internal picture URL
     148         435 :         OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     149         435 :         if( !aFragmentPath.isEmpty() )
     150         421 :             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           8 :         OUString aRelId = rAttribs.getString( R_TOKEN( link ), OUString() );
     160          16 :         OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
     161          16 :         SfxMedium xMed( aTargetLink, STREAM_STD_READ );
     162           8 :         xMed.Download();
     163          16 :         Reference< io::XInputStream > xInStrm = xMed.GetInputStream();
     164           8 :         if ( xInStrm.is() )
     165           9 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importGraphic( xInStrm );
     166             :     }
     167         447 : }
     168             : 
     169         222 : ContextHandlerRef BlipContext::onCreateContext(
     170             :         sal_Int32 nElement, const AttributeList& rAttribs )
     171             : {
     172         222 :     switch( nElement )
     173             :     {
     174             :         case A_TOKEN( biLevel ):
     175             :         case A_TOKEN( grayscl ):
     176           5 :             mrBlipProps.moColorEffect = getBaseToken( nElement );
     177           5 :         break;
     178             : 
     179             :         case A_TOKEN( clrChange ):
     180           0 :             return new ColorChangeContext( *this, rAttribs, mrBlipProps );
     181             : 
     182             :         case A_TOKEN( duotone ):
     183          21 :             return new DuotoneContext( *this, rAttribs, mrBlipProps );
     184             : 
     185             :         case A_TOKEN( extLst ):
     186         184 :             return new BlipExtensionContext( *this, mrBlipProps );
     187             : 
     188             :         case A_TOKEN( lum ):
     189           8 :             mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
     190           8 :             mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
     191           8 :         break;
     192             :     }
     193          17 :     return 0;
     194             : }
     195             : 
     196          21 : DuotoneContext::DuotoneContext( ContextHandler2Helper& rParent,
     197             :         const AttributeList& /*rAttribs*/, BlipFillProperties& rBlipProps ) :
     198             :     ContextHandler2( rParent ),
     199             :     mrBlipProps( rBlipProps ),
     200          21 :     mnColorIndex( 0 )
     201             : {
     202          21 :     mrBlipProps.maDuotoneColors[0].setUnused();
     203          21 :     mrBlipProps.maDuotoneColors[1].setUnused();
     204          21 : }
     205             : 
     206          42 : DuotoneContext::~DuotoneContext()
     207             : {
     208          42 : }
     209             : 
     210          42 : ::oox::core::ContextHandlerRef DuotoneContext::onCreateContext(
     211             :         sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
     212             : {
     213          42 :     if( mnColorIndex < 2 )
     214          42 :         return new ColorValueContext( *this, mrBlipProps.maDuotoneColors[mnColorIndex++] );
     215           0 :     return 0;
     216             : }
     217             : 
     218         452 : BlipFillContext::BlipFillContext( ContextHandler2Helper& rParent,
     219             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     220             :     ContextHandler2( rParent ),
     221         452 :     mrBlipProps( rBlipProps )
     222             : {
     223         452 :     mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
     224         452 : }
     225             : 
     226        1421 : ContextHandlerRef BlipFillContext::onCreateContext(
     227             :         sal_Int32 nElement, const AttributeList& rAttribs )
     228             : {
     229        1421 :     switch( nElement )
     230             :     {
     231             :         case A_TOKEN( blip ):
     232         447 :             return new BlipContext( *this, rAttribs, mrBlipProps );
     233             : 
     234             :         case A_TOKEN( srcRect ):
     235         176 :             mrBlipProps.moClipRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     236         176 :         break;
     237             : 
     238             :         case A_TOKEN( tile ):
     239          26 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     240          26 :             mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
     241          26 :             mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
     242          26 :             mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
     243          26 :             mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
     244          26 :             mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
     245          26 :             mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
     246          26 :         break;
     247             : 
     248             :         case A_TOKEN( stretch ):
     249         417 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     250         417 :             return this;    // for fillRect element
     251             : 
     252             :         case A_TOKEN( fillRect ):
     253         355 :             mrBlipProps.moFillRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     254         355 :         break;
     255             :     }
     256         557 :     return 0;
     257             : }
     258             : 
     259         211 : FillPropertiesContext::FillPropertiesContext( ContextHandler2Helper& rParent, FillProperties& rFillProps ) :
     260             :     ContextHandler2( rParent ),
     261         211 :     mrFillProps( rFillProps )
     262             : {
     263         211 : }
     264             : 
     265         211 : ContextHandlerRef FillPropertiesContext::onCreateContext(
     266             :         sal_Int32 nElement, const AttributeList& rAttribs )
     267             : {
     268         211 :     return createFillContext( *this, nElement, rAttribs, mrFillProps );
     269             : }
     270             : 
     271       18873 : ContextHandlerRef FillPropertiesContext::createFillContext(
     272             :         ContextHandler2Helper& rParent, sal_Int32 nElement,
     273             :         const AttributeList& rAttribs, FillProperties& rFillProps )
     274             : {
     275       18873 :     switch( nElement )
     276             :     {
     277        2133 :         case A_TOKEN( noFill ):     { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
     278       10658 :         case A_TOKEN( solidFill ):  { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rAttribs, rFillProps ); };
     279        5610 :         case A_TOKEN( gradFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
     280          97 :         case A_TOKEN( pattFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
     281         120 :         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         255 :     return 0;
     285             : }
     286             : 
     287         119 : SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler2Helper& rParent, Color& rColor ) :
     288             :     FillPropertiesContext( rParent, *this ),
     289         119 :     mrColor( rColor )
     290             : {
     291         119 : }
     292             : 
     293         357 : SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
     294             : {
     295         119 :     mrColor = getBestSolidColor();
     296         238 : }
     297             : 
     298         381 : BlipExtensionContext::BlipExtensionContext( ContextHandler2Helper& rParent, BlipFillProperties& rBlipProps ) :
     299             :     ContextHandler2( rParent ),
     300         381 :     mrBlipProps( rBlipProps )
     301             : {
     302         381 : }
     303             : 
     304         762 : BlipExtensionContext::~BlipExtensionContext()
     305             : {
     306         762 : }
     307             : 
     308         216 : ContextHandlerRef BlipExtensionContext::onCreateContext(
     309             :         sal_Int32 nElement, const AttributeList& )
     310             : {
     311         216 :     switch( nElement )
     312             :     {
     313             :         case A_TOKEN( ext ):
     314         197 :             return new BlipExtensionContext( *this, mrBlipProps );
     315             : 
     316             :         case OOX_TOKEN( a14, imgProps ):
     317          19 :             return new ArtisticEffectContext( *this, mrBlipProps.maEffect );
     318             :     }
     319           0 :     return 0;
     320             : }
     321             : 
     322          57 : ArtisticEffectContext::ArtisticEffectContext( ContextHandler2Helper& rParent, ArtisticEffectProperties& rEffect ) :
     323             :     ContextHandler2( rParent ),
     324          57 :     maEffect( rEffect )
     325             : {
     326          57 : }
     327             : 
     328         114 : ArtisticEffectContext::~ArtisticEffectContext()
     329             : {
     330         114 : }
     331             : 
     332          57 : ContextHandlerRef ArtisticEffectContext::onCreateContext(
     333             :         sal_Int32 nElement, const AttributeList& rAttribs )
     334             : {
     335             :     // containers
     336          57 :     if( nElement == OOX_TOKEN( a14, imgLayer ) )
     337             :     {
     338          19 :         if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     339             :         {
     340          19 :             OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     341          19 :             if( !aFragmentPath.isEmpty() )
     342             :             {
     343          19 :                 getFilter().importBinaryData( maEffect.mrOleObjectInfo.maEmbeddedData, aFragmentPath );
     344          19 :                 maEffect.mrOleObjectInfo.maProgId = aFragmentPath;
     345          19 :             }
     346             :         }
     347          19 :         return new ArtisticEffectContext( *this, maEffect );
     348             :     }
     349          38 :     if( nElement == OOX_TOKEN( a14, imgEffect ) )
     350          19 :         return new ArtisticEffectContext( *this, maEffect );
     351             : 
     352             :     // effects
     353          19 :     maEffect.msName = ArtisticEffectProperties::getEffectString( nElement );
     354          19 :     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          19 :     };
     364         380 :     for( sal_Int32 i=0; i<19; ++i )
     365             :     {
     366         361 :         if( rAttribs.hasAttribute( aAttribs[i] ) )
     367             :         {
     368          27 :             OUString sName = ArtisticEffectProperties::getEffectString( aAttribs[i] );
     369          27 :             if( !sName.isEmpty() )
     370          27 :                 maEffect.maAttribs[sName] = uno::makeAny( rAttribs.getInteger( aAttribs[i], 0 ) );
     371             :         }
     372             :     }
     373             : 
     374          19 :     return 0;
     375             : }
     376             : 
     377             : } // namespace drawingml
     378         246 : } // namespace oox
     379             : 
     380             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11