LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillpropertiesgroupcontext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 128 0.0 %
Date: 2014-04-14 Functions: 0 25 0.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           0 : SolidFillContext::SolidFillContext( ContextHandler2Helper& rParent,
      39             :         const AttributeList&, FillProperties& rFillProps ) :
      40           0 :     ColorContext( rParent, rFillProps.maFillColor )
      41             : {
      42           0 : }
      43             : 
      44           0 : GradientFillContext::GradientFillContext( ContextHandler2Helper& rParent,
      45             :         const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) :
      46             :     ContextHandler2( rParent ),
      47           0 :     mrGradientProps( rGradientProps )
      48             : {
      49           0 :     mrGradientProps.moShadeFlip = rAttribs.getToken( XML_flip );
      50           0 :     mrGradientProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
      51           0 : }
      52             : 
      53           0 : ContextHandlerRef GradientFillContext::onCreateContext(
      54             :         sal_Int32 nElement, const AttributeList& rAttribs )
      55             : {
      56           0 :     switch( nElement )
      57             :     {
      58             :         case A_TOKEN( gsLst ):
      59           0 :             return this;    // for gs elements
      60             : 
      61             :         case A_TOKEN( gs ):
      62           0 :             if( rAttribs.hasAttribute( XML_pos ) )
      63             :             {
      64           0 :                 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
      65           0 :                 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
      66             :             }
      67           0 :         break;
      68             : 
      69             :         case A_TOKEN( lin ):
      70           0 :             mrGradientProps.moShadeAngle = rAttribs.getInteger( XML_ang );
      71           0 :             mrGradientProps.moShadeScaled = rAttribs.getBool( XML_scaled );
      72           0 :         break;
      73             : 
      74             :         case A_TOKEN( path ):
      75             :             // always set a path type, this disables linear gradient in conversion
      76           0 :             mrGradientProps.moGradientPath = rAttribs.getToken( XML_path, XML_rect );
      77           0 :             return this;    // for fillToRect element
      78             : 
      79             :         case A_TOKEN( fillToRect ):
      80           0 :             mrGradientProps.moFillToRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      81           0 :         break;
      82             : 
      83             :         case A_TOKEN( tileRect ):
      84           0 :             mrGradientProps.moTileRect = GetRelativeRect( rAttribs.getFastAttributeList() );
      85           0 :         break;
      86             :     }
      87           0 :     return 0;
      88             : }
      89             : 
      90           0 : PatternFillContext::PatternFillContext( ContextHandler2Helper& rParent,
      91             :         const AttributeList& rAttribs, PatternFillProperties& rPatternProps ) :
      92             :     ContextHandler2( rParent ),
      93           0 :     mrPatternProps( rPatternProps )
      94             : {
      95           0 :     mrPatternProps.moPattPreset = rAttribs.getToken( XML_prst );
      96           0 : }
      97             : 
      98           0 : ContextHandlerRef PatternFillContext::onCreateContext(
      99             :         sal_Int32 nElement, const AttributeList& )
     100             : {
     101           0 :     switch( nElement )
     102             :     {
     103             :         case A_TOKEN( bgClr ):
     104           0 :             return new ColorContext( *this, mrPatternProps.maPattBgColor );
     105             :         case A_TOKEN( fgClr ):
     106           0 :             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           0 : BlipContext::BlipContext( ContextHandler2Helper& rParent,
     141             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     142             :     ContextHandler2( rParent ),
     143           0 :     mrBlipProps( rBlipProps )
     144             : {
     145           0 :     if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
     146             :     {
     147             :         // internal picture URL
     148           0 :         OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
     149           0 :         if( !aFragmentPath.isEmpty() )
     150           0 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath );
     151             :     }
     152           0 :     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           0 :         OUString aRelId = rAttribs.getString( R_TOKEN( link ), OUString() );
     160           0 :         OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
     161           0 :         SfxMedium xMed( aTargetLink, STREAM_STD_READ );
     162           0 :         xMed.Download();
     163           0 :         Reference< io::XInputStream > xInStrm = xMed.GetInputStream();
     164           0 :         if ( xInStrm.is() )
     165           0 :             mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importGraphic( xInStrm );
     166             :     }
     167           0 : }
     168             : 
     169           0 : ContextHandlerRef BlipContext::onCreateContext(
     170             :         sal_Int32 nElement, const AttributeList& rAttribs )
     171             : {
     172           0 :     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           0 :             return new DuotoneContext( *this, rAttribs, mrBlipProps );
     184             : 
     185             :         case A_TOKEN( lum ):
     186           0 :             mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
     187           0 :             mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
     188           0 :         break;
     189             :     }
     190           0 :     return 0;
     191             : }
     192             : 
     193           0 : DuotoneContext::DuotoneContext( ContextHandler2Helper& rParent,
     194             :         const AttributeList& /*rAttribs*/, BlipFillProperties& rBlipProps ) :
     195             :     ContextHandler2( rParent ),
     196             :     mrBlipProps( rBlipProps ),
     197           0 :     mnColorIndex( 0 )
     198             : {
     199           0 :     mrBlipProps.maDuotoneColors[0].setUnused();
     200           0 :     mrBlipProps.maDuotoneColors[1].setUnused();
     201           0 : }
     202             : 
     203           0 : DuotoneContext::~DuotoneContext()
     204             : {
     205           0 : }
     206             : 
     207           0 : ::oox::core::ContextHandlerRef DuotoneContext::onCreateContext(
     208             :         sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
     209             : {
     210           0 :     if( mnColorIndex < 2 )
     211           0 :         return new ColorValueContext( *this, mrBlipProps.maDuotoneColors[mnColorIndex++] );
     212           0 :     return 0;
     213             : }
     214             : 
     215           0 : BlipFillContext::BlipFillContext( ContextHandler2Helper& rParent,
     216             :         const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
     217             :     ContextHandler2( rParent ),
     218           0 :     mrBlipProps( rBlipProps )
     219             : {
     220           0 :     mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
     221           0 : }
     222             : 
     223           0 : ContextHandlerRef BlipFillContext::onCreateContext(
     224             :         sal_Int32 nElement, const AttributeList& rAttribs )
     225             : {
     226           0 :     switch( nElement )
     227             :     {
     228             :         case A_TOKEN( blip ):
     229           0 :             return new BlipContext( *this, rAttribs, mrBlipProps );
     230             : 
     231             :         case A_TOKEN( srcRect ):
     232           0 :             mrBlipProps.moClipRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     233           0 :         break;
     234             : 
     235             :         case A_TOKEN( tile ):
     236           0 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     237           0 :             mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
     238           0 :             mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
     239           0 :             mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
     240           0 :             mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
     241           0 :             mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
     242           0 :             mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
     243           0 :         break;
     244             : 
     245             :         case A_TOKEN( stretch ):
     246           0 :             mrBlipProps.moBitmapMode = getBaseToken( nElement );
     247           0 :             return this;    // for fillRect element
     248             : 
     249             :         case A_TOKEN( fillRect ):
     250           0 :             mrBlipProps.moFillRect = GetRelativeRect( rAttribs.getFastAttributeList() );
     251           0 :         break;
     252             :     }
     253           0 :     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           0 : ContextHandlerRef FillPropertiesContext::createFillContext(
     269             :         ContextHandler2Helper& rParent, sal_Int32 nElement,
     270             :         const AttributeList& rAttribs, FillProperties& rFillProps )
     271             : {
     272           0 :     switch( nElement )
     273             :     {
     274           0 :         case A_TOKEN( noFill ):     { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
     275           0 :         case A_TOKEN( solidFill ):  { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rAttribs, rFillProps ); };
     276           0 :         case A_TOKEN( gradFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
     277           0 :         case A_TOKEN( pattFill ):   { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
     278           0 :         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           0 :     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           0 : } // namespace oox
     297             : 
     298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10