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

Generated by: LCOV version 1.10