LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillpropertiesgroupcontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 95 128 74.2 %
Date: 2014-04-11 Functions: 16 25 64.0 %
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 "oox/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        6343 : SolidFillContext::SolidFillContext( ContextHandler2Helper& rParent,
      39             :         const AttributeList&, FillProperties& rFillProps ) :
      40        6343 :     ColorContext( rParent, rFillProps.maFillColor )
      41             : {
      42        6343 : }
      43             : 
      44        3302 : GradientFillContext::GradientFillContext( ContextHandler2Helper& rParent,
      45             :         const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) :
      46             :     ContextHandler2( rParent ),
      47        3302 :     mrGradientProps( rGradientProps )
      48             : {
      49        3302 :     mrGradientProps.moShadeFlip = rAttribs.getToken( XML_flip );
      50        3302 :     mrGradientProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
      51        3302 : }
      52             : 
      53       17249 : ContextHandlerRef GradientFillContext::onCreateContext(
      54             :         sal_Int32 nElement, const AttributeList& rAttribs )
      55             : {
      56       17249 :     switch( nElement )
      57             :     {
      58             :         case A_TOKEN( gsLst ):
      59        3302 :             return this;    // for gs elements
      60             : 
      61             :         case A_TOKEN( gs ):
      62        9121 :             if( rAttribs.hasAttribute( XML_pos ) )
      63             :             {
      64        9121 :                 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
      65        9121 :                 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
      66             :             }
      67           0 :         break;
      68             : 
      69             :         case A_TOKEN( lin ):
      70        1796 :             mrGradientProps.moShadeAngle = rAttribs.getInteger( XML_ang );
      71        1796 :             mrGradientProps.moShadeScaled = rAttribs.getBool( XML_scaled );
      72        1796 :         break;
      73             : 
      74             :         case A_TOKEN( path ):
      75             :             // always set a path type, this disables linear gradient in conversion
      76        1506 :             mrGradientProps.moGradientPath = rAttribs.getToken( XML_path, XML_rect );
      77        1506 :             return this;    // for fillToRect element
      78             : 
      79             :         case A_TOKEN( fillToRect ):
      80        1506 :             mrGradientProps.moFillToRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      81        1506 :         break;
      82             : 
      83             :         case A_TOKEN( tileRect ):
      84          18 :             mrGradientProps.moTileRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      85          18 :         break;
      86             :     }
      87        3320 :     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         211 : BlipContext::BlipContext( ContextHandler2Helper& rParent,
     141             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     142             :     ContextHandler2( rParent ),
     143         211 :     mrBlipProps( rBlipProps )
     144             : {
     145         211 :     if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     146             :     {
     147             :         // internal picture URL
     148         208 :         OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     149         208 :         if( !aFragmentPath.isEmpty() )
     150         199 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath );
     151             :     }
     152           3 :     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           2 :         OUString aRelId = rAttribs.getString( R_TOKEN( link ), OUString() );
     160           4 :         OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
     161           4 :         SfxMedium xMed( aTargetLink, STREAM_STD_READ );
     162           2 :         xMed.Download();
     163           4 :         Reference< io::XInputStream > xInStrm = xMed.GetInputStream();
     164           2 :         if ( xInStrm.is() )
     165           2 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importGraphic( xInStrm );
     166             :     }
     167         211 : }
     168             : 
     169          69 : ContextHandlerRef BlipContext::onCreateContext(
     170             :         sal_Int32 nElement, const AttributeList& rAttribs )
     171             : {
     172          69 :     switch( nElement )
     173             :     {
     174             :         case A_TOKEN( biLevel ):
     175             :         case A_TOKEN( grayscl ):
     176           0 :             mrBlipProps.moColorEffect = getBaseToken( nElement );
     177           0 :         break;
     178             : 
     179             :         case A_TOKEN( clrChange ):
     180           0 :             return new ColorChangeContext( *this, rAttribs, mrBlipProps );
     181             : 
     182             :         case A_TOKEN( duotone ):
     183           9 :             return new DuotoneContext( *this, rAttribs, mrBlipProps );
     184             : 
     185             :         case A_TOKEN( lum ):
     186           2 :             mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
     187           2 :             mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
     188           2 :         break;
     189             :     }
     190          60 :     return 0;
     191             : }
     192             : 
     193           9 : DuotoneContext::DuotoneContext( ContextHandler2Helper& rParent,
     194             :         const AttributeList& /*rAttribs*/, BlipFillProperties& rBlipProps ) :
     195             :     ContextHandler2( rParent ),
     196             :     mrBlipProps( rBlipProps ),
     197           9 :     mnColorIndex( 0 )
     198             : {
     199           9 :     mrBlipProps.maDuotoneColors[0].setUnused();
     200           9 :     mrBlipProps.maDuotoneColors[1].setUnused();
     201           9 : }
     202             : 
     203          18 : DuotoneContext::~DuotoneContext()
     204             : {
     205          18 : }
     206             : 
     207          18 : ::oox::core::ContextHandlerRef DuotoneContext::onCreateContext(
     208             :         sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
     209             : {
     210          18 :     if( mnColorIndex < 2 )
     211          18 :         return new ColorValueContext( *this, mrBlipProps.maDuotoneColors[mnColorIndex++] );
     212           0 :     return 0;
     213             : }
     214             : 
     215         211 : BlipFillContext::BlipFillContext( ContextHandler2Helper& rParent,
     216             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     217             :     ContextHandler2( rParent ),
     218         211 :     mrBlipProps( rBlipProps )
     219             : {
     220         211 :     mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
     221         211 : }
     222             : 
     223         696 : ContextHandlerRef BlipFillContext::onCreateContext(
     224             :         sal_Int32 nElement, const AttributeList& rAttribs )
     225             : {
     226         696 :     switch( nElement )
     227             :     {
     228             :         case A_TOKEN( blip ):
     229         211 :             return new BlipContext( *this, rAttribs, mrBlipProps );
     230             : 
     231             :         case A_TOKEN( srcRect ):
     232          97 :             mrBlipProps.moClipRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     233          97 :         break;
     234             : 
     235             :         case A_TOKEN( tile ):
     236           8 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     237           8 :             mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
     238           8 :             mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
     239           8 :             mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
     240           8 :             mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
     241           8 :             mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
     242           8 :             mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
     243           8 :         break;
     244             : 
     245             :         case A_TOKEN( stretch ):
     246         203 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     247         203 :             return this;    // for fillRect element
     248             : 
     249             :         case A_TOKEN( fillRect ):
     250         177 :             mrBlipProps.moFillRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     251         177 :         break;
     252             :     }
     253         282 :     return 0;
     254             : }
     255             : 
     256           0 : FillPropertiesContext::FillPropertiesContext( ContextHandler2Helper& rParent, FillProperties& rFillProps ) :
     257             :     ContextHandler2( rParent ),
     258           0 :     mrFillProps( rFillProps )
     259             : {
     260           0 : }
     261             : 
     262           0 : ContextHandlerRef FillPropertiesContext::onCreateContext(
     263             :         sal_Int32 nElement, const AttributeList& rAttribs )
     264             : {
     265           0 :     return createFillContext( *this, nElement, rAttribs, mrFillProps );
     266             : }
     267             : 
     268       11302 : ContextHandlerRef FillPropertiesContext::createFillContext(
     269             :         ContextHandler2Helper& rParent, sal_Int32 nElement,
     270             :         const AttributeList& rAttribs, FillProperties& rFillProps )
     271             : {
     272       11302 :     switch( nElement )
     273             :     {
     274        1217 :         case A_TOKEN( noFill ):     { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
     275        6343 :         case A_TOKEN( solidFill ):  { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rAttribs, rFillProps ); };
     276        3301 :         case A_TOKEN( gradFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
     277          97 :         case A_TOKEN( pattFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
     278          44 :         case A_TOKEN( blipFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); };
     279           0 :         case A_TOKEN( grpFill ):    { rFillProps.moFillType = getBaseToken( nElement ); return 0; };    // TODO
     280             :     }
     281         300 :     return 0;
     282             : }
     283             : 
     284           0 : SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler2Helper& rParent, Color& rColor ) :
     285             :     FillPropertiesContext( rParent, *this ),
     286           0 :     mrColor( rColor )
     287             : {
     288           0 : }
     289             : 
     290           0 : SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
     291             : {
     292           0 :     mrColor = getBestSolidColor();
     293           0 : }
     294             : 
     295             : } // namespace drawingml
     296         177 : } // namespace oox
     297             : 
     298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10