LCOV - code coverage report
Current view: top level - oox/source/vml - vmlshapecontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 260 293 88.7 %
Date: 2014-11-03 Functions: 32 32 100.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/vml/vmlshapecontext.hxx"
      21             : 
      22             : #include "oox/core/xmlfilterbase.hxx"
      23             : #include "oox/vml/vmldrawing.hxx"
      24             : #include "oox/vml/vmlshape.hxx"
      25             : #include "oox/vml/vmlshapecontainer.hxx"
      26             : #include "oox/vml/vmltextboxcontext.hxx"
      27             : 
      28             : namespace oox {
      29             : namespace vml {
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : using ::oox::core::ContextHandler2;
      34             : using ::oox::core::ContextHandler2Helper;
      35             : using ::oox::core::ContextHandlerRef;
      36             : 
      37             : namespace {
      38             : 
      39             : /** Returns the boolean value from the specified VML attribute (if present).
      40             :  */
      41        7956 : OptValue< bool > lclDecodeBool( const AttributeList& rAttribs, sal_Int32 nToken )
      42             : {
      43        7956 :     OptValue< OUString > oValue = rAttribs.getString( nToken );
      44        7956 :     if( oValue.has() ) return OptValue< bool >( ConversionHelper::decodeBool( oValue.get() ) );
      45        6098 :     return OptValue< bool >();
      46             : }
      47             : 
      48             : /** Returns the percentage value from the specified VML attribute (if present).
      49             :     The value will be normalized (1.0 is returned for 100%).
      50             :  */
      51         220 : OptValue< double > lclDecodePercent( const AttributeList& rAttribs, sal_Int32 nToken, double fDefValue )
      52             : {
      53         220 :     OptValue< OUString > oValue = rAttribs.getString( nToken );
      54         220 :     if( oValue.has() ) return OptValue< double >( ConversionHelper::decodePercent( oValue.get(), fDefValue ) );
      55         182 :     return OptValue< double >();
      56             : }
      57             : 
      58             : /** #119750# Special method for opacity; it *should* be a percentage value, but there are cases
      59             :     where a value relative to 0xffff (65536) is used, ending with an 'f'
      60             :  */
      61         894 : OptValue< double > lclDecodeOpacity( const AttributeList& rAttribs, sal_Int32 nToken, double fDefValue )
      62             : {
      63         894 :     OptValue< OUString > oValue = rAttribs.getString( nToken );
      64         894 :     double fRetval(fDefValue);
      65             : 
      66         894 :     if( oValue.has() )
      67             :     {
      68          52 :         const OUString aString(oValue.get());
      69          52 :         const sal_Int32 nLength(aString.getLength());
      70             : 
      71          52 :         if(nLength > 0)
      72             :         {
      73          52 :             if(aString.endsWith("f"))
      74             :             {
      75          10 :                 fRetval = std::max(0.0, std::min(1.0, aString.toDouble() / 65536.0));
      76             :             }
      77             :             else
      78             :             {
      79          42 :                 fRetval = ConversionHelper::decodePercent( aString, fDefValue );
      80             :             }
      81          52 :         }
      82             :     }
      83             : 
      84         894 :     return OptValue< double >(fRetval);
      85             : }
      86             : 
      87             : /** Returns the integer value pair from the specified VML attribute (if present).
      88             :  */
      89        4660 : OptValue< Int32Pair > lclDecodeInt32Pair( const AttributeList& rAttribs, sal_Int32 nToken )
      90             : {
      91        4660 :     OptValue< OUString > oValue = rAttribs.getString( nToken );
      92        4660 :     OptValue< Int32Pair > oRetValue;
      93        4660 :     if( oValue.has() )
      94             :     {
      95        2408 :         OUString aValue1, aValue2;
      96        1204 :         ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' );
      97        2408 :         oRetValue = Int32Pair( aValue1.toInt32(), aValue2.toInt32() );
      98             :     }
      99        4660 :     return oRetValue;
     100             : }
     101             : 
     102             : /** Returns the percentage pair from the specified VML attribute (if present).
     103             :  */
     104         296 : OptValue< DoublePair > lclDecodePercentPair( const AttributeList& rAttribs, sal_Int32 nToken )
     105             : {
     106         296 :     OptValue< OUString > oValue = rAttribs.getString( nToken );
     107         296 :     OptValue< DoublePair > oRetValue;
     108         296 :     if( oValue.has() )
     109             :     {
     110          40 :         OUString aValue1, aValue2;
     111          20 :         ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' );
     112          60 :         oRetValue = DoublePair(
     113          20 :             ConversionHelper::decodePercent( aValue1, 0.0 ),
     114          60 :             ConversionHelper::decodePercent( aValue2, 0.0 ) );
     115             :     }
     116         296 :     return oRetValue;
     117             : }
     118             : 
     119             : /** Returns the boolean value from the passed string of an attribute in the x:
     120             :     namespace (VML for spreadsheets). Supported values: f, t, False, True.
     121             :     @param bDefaultForEmpty  Default value for the empty string.
     122             :  */
     123           2 : bool lclDecodeVmlxBool( const OUString& rValue, bool bDefaultForEmpty )
     124             : {
     125           2 :     if( rValue.isEmpty() ) return bDefaultForEmpty;
     126           0 :     sal_Int32 nToken = AttributeConversion::decodeToken( rValue );
     127             :     // anything else than 't' or 'True' is considered to be false, as specified
     128           0 :     return (nToken == XML_t) || (nToken == XML_True);
     129             : }
     130             : 
     131             : } // namespace
     132             : 
     133           6 : ShapeLayoutContext::ShapeLayoutContext( ContextHandler2Helper& rParent, Drawing& rDrawing ) :
     134             :     ContextHandler2( rParent ),
     135           6 :     mrDrawing( rDrawing )
     136             : {
     137           6 : }
     138             : 
     139           6 : ContextHandlerRef ShapeLayoutContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     140             : {
     141           6 :     switch( nElement )
     142             :     {
     143             :         case O_TOKEN( idmap ):
     144             :         {
     145           6 :             OUString aBlockIds = rAttribs.getString( XML_data, OUString() );
     146           6 :             sal_Int32 nIndex = 0;
     147          18 :             while( nIndex >= 0 )
     148             :             {
     149           6 :                 OUString aToken = aBlockIds.getToken( 0, ' ', nIndex ).trim();
     150           6 :                 if( !aToken.isEmpty() )
     151           6 :                     mrDrawing.registerBlockId( aToken.toInt32() );
     152          12 :             }
     153             :         }
     154           6 :         break;
     155             :     }
     156           6 :     return 0;
     157             : }
     158             : 
     159           4 : ClientDataContext::ClientDataContext( ContextHandler2Helper& rParent,
     160             :         ClientData& rClientData, const AttributeList& rAttribs ) :
     161             :     ContextHandler2( rParent ),
     162           4 :     mrClientData( rClientData )
     163             : {
     164           4 :     mrClientData.mnObjType = rAttribs.getToken( XML_ObjectType, XML_TOKEN_INVALID );
     165           4 : }
     166             : 
     167          26 : ContextHandlerRef ClientDataContext::onCreateContext( sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
     168             : {
     169          26 :     if( isRootElement() )
     170             :     {
     171          26 :         maElementText = OUString();
     172          26 :         return this;
     173             :     }
     174           0 :     return 0;
     175             : }
     176             : 
     177          34 : void ClientDataContext::onCharacters( const OUString& rChars )
     178             : {
     179             :     /*  Empty but existing elements have special meaning, e.g. 'true'. Collect
     180             :         existing text and convert it in onEndElement(). */
     181          34 :     maElementText = rChars;
     182          34 : }
     183             : 
     184          30 : void ClientDataContext::onEndElement()
     185             : {
     186          30 :     switch( getCurrentElement() )
     187             :     {
     188           4 :         case VMLX_TOKEN( Anchor ):      mrClientData.maAnchor = maElementText;                                          break;
     189           0 :         case VMLX_TOKEN( FmlaMacro ):   mrClientData.maFmlaMacro = maElementText;                                       break;
     190           0 :         case VMLX_TOKEN( FmlaPict ):    mrClientData.maFmlaPict = maElementText;                                        break;
     191           0 :         case VMLX_TOKEN( FmlaLink ):    mrClientData.maFmlaLink = maElementText;                                        break;
     192           0 :         case VMLX_TOKEN( FmlaRange ):   mrClientData.maFmlaRange = maElementText;                                       break;
     193           0 :         case VMLX_TOKEN( FmlaGroup ):   mrClientData.maFmlaGroup = maElementText;                                       break;
     194           0 :         case VMLX_TOKEN( TextHAlign ):  mrClientData.mnTextHAlign = AttributeConversion::decodeToken( maElementText );  break;
     195           2 :         case VMLX_TOKEN( TextVAlign ):  mrClientData.mnTextVAlign = AttributeConversion::decodeToken( maElementText );  break;
     196           2 :         case VMLX_TOKEN( Column ):      mrClientData.mnCol = maElementText.toInt32();                                   break;
     197           2 :         case VMLX_TOKEN( Row ):         mrClientData.mnRow = maElementText.toInt32();                                   break;
     198           2 :         case VMLX_TOKEN( Checked ):     mrClientData.mnChecked = maElementText.toInt32();                               break;
     199           0 :         case VMLX_TOKEN( DropStyle ):   mrClientData.mnDropStyle = AttributeConversion::decodeToken( maElementText );   break;
     200           0 :         case VMLX_TOKEN( DropLines ):   mrClientData.mnDropLines = maElementText.toInt32();                             break;
     201           0 :         case VMLX_TOKEN( Val ):         mrClientData.mnVal = maElementText.toInt32();                                   break;
     202           0 :         case VMLX_TOKEN( Min ):         mrClientData.mnMin = maElementText.toInt32();                                   break;
     203           0 :         case VMLX_TOKEN( Max ):         mrClientData.mnMax = maElementText.toInt32();                                   break;
     204           0 :         case VMLX_TOKEN( Inc ):         mrClientData.mnInc = maElementText.toInt32();                                   break;
     205           0 :         case VMLX_TOKEN( Page ):        mrClientData.mnPage = maElementText.toInt32();                                  break;
     206           0 :         case VMLX_TOKEN( SelType ):     mrClientData.mnSelType = AttributeConversion::decodeToken( maElementText );     break;
     207           0 :         case VMLX_TOKEN( VTEdit ):      mrClientData.mnVTEdit = maElementText.toInt32();                                break;
     208           0 :         case VMLX_TOKEN( PrintObject ): mrClientData.mbPrintObject = lclDecodeVmlxBool( maElementText, true );          break;
     209           0 :         case VMLX_TOKEN( Visible ):     mrClientData.mbVisible = lclDecodeVmlxBool( maElementText, true );              break;
     210           0 :         case VMLX_TOKEN( DDE ):         mrClientData.mbDde = lclDecodeVmlxBool( maElementText, true );                  break;
     211           2 :         case VMLX_TOKEN( NoThreeD ):    mrClientData.mbNo3D = lclDecodeVmlxBool( maElementText, true );                 break;
     212           0 :         case VMLX_TOKEN( NoThreeD2 ):   mrClientData.mbNo3D2 = lclDecodeVmlxBool( maElementText, true );                break;
     213           0 :         case VMLX_TOKEN( MultiLine ):   mrClientData.mbMultiLine = lclDecodeVmlxBool( maElementText, true );            break;
     214           0 :         case VMLX_TOKEN( VScroll ):     mrClientData.mbVScroll = lclDecodeVmlxBool( maElementText, true );              break;
     215           0 :         case VMLX_TOKEN( SecretEdit ):  mrClientData.mbSecretEdit = lclDecodeVmlxBool( maElementText, true );           break;
     216             :     }
     217          30 : }
     218             : 
     219        2330 : ShapeContextBase::ShapeContextBase( ContextHandler2Helper& rParent ) :
     220        2330 :     ContextHandler2( rParent )
     221             : {
     222        2330 : }
     223             : 
     224        2390 : ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper& rParent,
     225             :         ShapeContainer& rShapes, sal_Int32 nElement, const AttributeList& rAttribs )
     226             : {
     227        2390 :     switch( nElement )
     228             :     {
     229             :         case O_TOKEN( shapelayout ):
     230           6 :             return new ShapeLayoutContext( rParent, rShapes.getDrawing() );
     231             : 
     232             :         case VML_TOKEN( shapetype ):
     233         402 :             return new ShapeTypeContext( rParent, rShapes.createShapeType(), rAttribs );
     234             :         case VML_TOKEN( group ):
     235          68 :             return new GroupShapeContext( rParent, rShapes.createShape< GroupShape >(), rAttribs );
     236             :         case VML_TOKEN( shape ):
     237        1370 :             if (rAttribs.hasAttribute(XML_path))
     238         682 :                 return new ShapeContext( rParent, rShapes.createShape< BezierShape >(), rAttribs );
     239             :             else
     240         688 :                 return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs );
     241             :         case VML_TOKEN( rect ):
     242         468 :             return new RectangleShapeContext( rParent, rAttribs, rShapes.createShape< RectangleShape >() );
     243             :         case VML_TOKEN( roundrect ):
     244           4 :             return new ShapeContext( rParent, rShapes.createShape< RectangleShape >(), rAttribs );
     245             :         case VML_TOKEN( oval ):
     246           4 :             return new ShapeContext( rParent, rShapes.createShape< EllipseShape >(), rAttribs );
     247             :         case VML_TOKEN( polyline ):
     248           4 :             return new ShapeContext( rParent, rShapes.createShape< PolyLineShape >(), rAttribs );
     249             :         case VML_TOKEN( line ):
     250          10 :             return new ShapeContext( rParent, rShapes.createShape< LineShape >(), rAttribs );
     251             :         case VML_TOKEN( curve ):
     252           0 :             return new ShapeContext( rParent, rShapes.createShape< BezierShape >(), rAttribs );
     253             : 
     254             :         // TODO:
     255             :         case VML_TOKEN( arc ):
     256             :         case VML_TOKEN( diagram ):
     257             :         case VML_TOKEN( image ):
     258           0 :             return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs );
     259             :     }
     260          54 :     return 0;
     261             : }
     262             : 
     263        2330 : ShapeTypeContext::ShapeTypeContext( ContextHandler2Helper& rParent, ShapeType& rShapeType, const AttributeList& rAttribs ) :
     264             :     ShapeContextBase( rParent ),
     265        2330 :     mrTypeModel( rShapeType.getTypeModel() )
     266             : {
     267             :     // shape identifier and shape name
     268        2330 :     bool bHasOspid = rAttribs.hasAttribute( O_TOKEN( spid ) );
     269        2330 :     mrTypeModel.maShapeId = rAttribs.getXString( bHasOspid ? O_TOKEN( spid ) : XML_id, OUString() );
     270             :     OSL_ENSURE( !mrTypeModel.maShapeId.isEmpty(), "ShapeTypeContext::ShapeTypeContext - missing shape identifier" );
     271             :     // if the o:spid attribute exists, the id attribute contains the user-defined shape name
     272        2330 :     if( bHasOspid )
     273         710 :         mrTypeModel.maShapeName = rAttribs.getXString( XML_id, OUString() );
     274             :     // builtin shape type identifier
     275        2330 :     mrTypeModel.moShapeType = rAttribs.getInteger( O_TOKEN( spt ) );
     276             : 
     277             :     // coordinate system position/size, CSS style
     278        2330 :     mrTypeModel.moCoordPos = lclDecodeInt32Pair( rAttribs, XML_coordorigin );
     279        2330 :     mrTypeModel.moCoordSize = lclDecodeInt32Pair( rAttribs, XML_coordsize );
     280        2330 :     setStyle( rAttribs.getString( XML_style, OUString() ) );
     281        2330 :     if( lclDecodeBool( rAttribs, O_TOKEN( hr )).get( false ))
     282             :     {   // MSO's handling of o:hr width is nowhere near what the spec says:
     283             :         // - o:hrpct is not in % but in 0.1%
     284             :         // - if o:hrpct is not given, 100% width is assumed
     285             :         // - given width is used only if explicit o:hrpct="0" is given
     286          16 :         OUString hrpct = rAttribs.getString( O_TOKEN( hrpct ), "1000" );
     287          16 :         if( hrpct != "0" )
     288          16 :             mrTypeModel.maWidth = OUString::number( hrpct.toInt32() / 10 ) + "%";
     289             :     }
     290             : 
     291             :     // stroke settings (may be overridden by v:stroke element later)
     292        2330 :     mrTypeModel.maStrokeModel.moStroked = lclDecodeBool( rAttribs, XML_stroked );
     293        2330 :     mrTypeModel.maStrokeModel.moColor = rAttribs.getString( XML_strokecolor );
     294        2330 :     mrTypeModel.maStrokeModel.moWeight = rAttribs.getString( XML_strokeweight );
     295             : 
     296             :     // fill settings (may be overridden by v:fill element later)
     297        2330 :     mrTypeModel.maFillModel.moFilled = lclDecodeBool( rAttribs, XML_filled );
     298        2330 :     mrTypeModel.maFillModel.moColor = rAttribs.getString( XML_fillcolor );
     299             : 
     300             :     // For roundrect we may have a arcsize attribute to read
     301        2330 :     mrTypeModel.maArcsize = rAttribs.getString( XML_arcsize,OUString( ) );
     302             :     // editas
     303        2330 :     mrTypeModel.maEditAs = rAttribs.getString(XML_editas, OUString());
     304        2330 : }
     305             : 
     306        3196 : ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     307             : {
     308        3196 :     if( isRootElement() ) switch( nElement )
     309             :     {
     310             :         case VML_TOKEN( stroke ):
     311         598 :             mrTypeModel.maStrokeModel.moStroked.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) );
     312         598 :             mrTypeModel.maStrokeModel.maStartArrow.moArrowType = rAttribs.getToken( XML_startarrow );
     313         598 :             mrTypeModel.maStrokeModel.maStartArrow.moArrowWidth = rAttribs.getToken( XML_startarrowwidth );
     314         598 :             mrTypeModel.maStrokeModel.maStartArrow.moArrowLength = rAttribs.getToken( XML_startarrowlength );
     315         598 :             mrTypeModel.maStrokeModel.maEndArrow.moArrowType = rAttribs.getToken( XML_endarrow );
     316         598 :             mrTypeModel.maStrokeModel.maEndArrow.moArrowWidth = rAttribs.getToken( XML_endarrowwidth );
     317         598 :             mrTypeModel.maStrokeModel.maEndArrow.moArrowLength = rAttribs.getToken( XML_endarrowlength );
     318         598 :             mrTypeModel.maStrokeModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) );
     319         598 :             mrTypeModel.maStrokeModel.moOpacity = lclDecodeOpacity( rAttribs, XML_opacity, 1.0 );
     320         598 :             mrTypeModel.maStrokeModel.moWeight.assignIfUsed( rAttribs.getString( XML_weight ) );
     321         598 :             mrTypeModel.maStrokeModel.moDashStyle = rAttribs.getString( XML_dashstyle );
     322         598 :             mrTypeModel.maStrokeModel.moLineStyle = rAttribs.getToken( XML_linestyle );
     323         598 :             mrTypeModel.maStrokeModel.moEndCap = rAttribs.getToken( XML_endcap );
     324         598 :             mrTypeModel.maStrokeModel.moJoinStyle = rAttribs.getToken( XML_joinstyle );
     325         598 :         break;
     326             :         case VML_TOKEN( fill ):
     327         148 :             mrTypeModel.maFillModel.moFilled.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) );
     328         148 :             mrTypeModel.maFillModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) );
     329         148 :             mrTypeModel.maFillModel.moOpacity = lclDecodeOpacity( rAttribs, XML_opacity, 1.0 );
     330         148 :             mrTypeModel.maFillModel.moColor2 = rAttribs.getString( XML_color2 );
     331         148 :             mrTypeModel.maFillModel.moOpacity2 = lclDecodeOpacity( rAttribs, XML_opacity2, 1.0 );
     332         148 :             mrTypeModel.maFillModel.moType = rAttribs.getToken( XML_type );
     333         148 :             mrTypeModel.maFillModel.moAngle = rAttribs.getInteger( XML_angle );
     334         148 :             mrTypeModel.maFillModel.moFocus = lclDecodePercent( rAttribs, XML_focus, 0.0 );
     335         148 :             mrTypeModel.maFillModel.moFocusPos = lclDecodePercentPair( rAttribs, XML_focusposition );
     336         148 :             mrTypeModel.maFillModel.moFocusSize = lclDecodePercentPair( rAttribs, XML_focussize );
     337         148 :             mrTypeModel.maFillModel.moBitmapPath = decodeFragmentPath( rAttribs, O_TOKEN( relid ) );
     338         148 :             mrTypeModel.maFillModel.moRotate = lclDecodeBool( rAttribs, XML_rotate );
     339         148 :         break;
     340             :         case VML_TOKEN( imagedata ):
     341             :         {
     342             :             // shapes in docx use r:id for the relationship id
     343             :             // in xlsx it they use o:relid
     344         308 :             bool bHasORelId = rAttribs.hasAttribute( O_TOKEN( relid ) );
     345         308 :             mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, bHasORelId ? O_TOKEN( relid ) : R_TOKEN( id ) );
     346         308 :             mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) );
     347             :         }
     348         308 :         break;
     349             :         case NMSP_vmlWord | XML_wrap:
     350         104 :             mrTypeModel.moWrapAnchorX = rAttribs.getString(XML_anchorx);
     351         104 :             mrTypeModel.moWrapAnchorY = rAttribs.getString(XML_anchory);
     352         104 :             mrTypeModel.moWrapType = rAttribs.getString(XML_type);
     353         104 :             mrTypeModel.moWrapSide = rAttribs.getString(XML_side);
     354         104 :         break;
     355             :         case VML_TOKEN( shadow ):
     356             :         {
     357          72 :             mrTypeModel.maShadowModel.mbHasShadow = true;
     358          72 :             mrTypeModel.maShadowModel.moShadowOn.assignIfUsed(lclDecodeBool(rAttribs, XML_on));
     359          72 :             mrTypeModel.maShadowModel.moColor.assignIfUsed(rAttribs.getString(XML_color));
     360          72 :             mrTypeModel.maShadowModel.moOffset.assignIfUsed(rAttribs.getString(XML_offset));
     361          72 :             mrTypeModel.maShadowModel.moOpacity = lclDecodePercent(rAttribs, XML_opacity, 1.0);
     362             :         }
     363          72 :         break;
     364             :         case VML_TOKEN( textpath ):
     365         158 :             mrTypeModel.maTextpathModel.moString.assignIfUsed(rAttribs.getString(XML_string));
     366         158 :         break;
     367             :     }
     368        3196 :     return 0;
     369             : }
     370             : 
     371         456 : OptValue< OUString > ShapeTypeContext::decodeFragmentPath( const AttributeList& rAttribs, sal_Int32 nToken ) const
     372             : {
     373         456 :     OptValue< OUString > oFragmentPath;
     374         912 :     OptValue< OUString > oRelId = rAttribs.getString( nToken );
     375         456 :     if( oRelId.has() )
     376         308 :         oFragmentPath = getFragmentPathFromRelId( oRelId.get() );
     377         912 :     return oFragmentPath;
     378             : }
     379             : 
     380        2330 : void ShapeTypeContext::setStyle( const OUString& rStyle )
     381             : {
     382        2330 :     sal_Int32 nIndex = 0;
     383       17686 :     while( nIndex >= 0 )
     384             :     {
     385       26052 :         OUString aName, aValue;
     386       13026 :         if( ConversionHelper::separatePair( aName, aValue, rStyle.getToken( 0, ';', nIndex ), ':' ) )
     387             :         {
     388       12624 :                  if( aName == "position" )      mrTypeModel.maPosition = aValue;
     389       11070 :             else if( aName == "z-index" )        mrTypeModel.maZIndex = aValue;
     390       10764 :             else if( aName == "left" )           mrTypeModel.maLeft = aValue;
     391        9498 :             else if( aName == "top" )            mrTypeModel.maTop = aValue;
     392        8320 :             else if( aName == "width" )          mrTypeModel.maWidth = aValue;
     393        6406 :             else if( aName == "height" )         mrTypeModel.maHeight = aValue;
     394        4492 :             else if( aName == "margin-left" )    mrTypeModel.maMarginLeft = aValue;
     395        4152 :             else if( aName == "margin-top" )     mrTypeModel.maMarginTop = aValue;
     396        3812 :             else if( aName == "mso-position-vertical-relative" )  mrTypeModel.maPositionVerticalRelative = aValue;
     397        3574 :             else if( aName == "mso-position-horizontal-relative" )  mrTypeModel.maPositionHorizontalRelative = aValue;
     398        3338 :             else if( aName == "mso-position-horizontal" ) mrTypeModel.maPositionHorizontal = aValue;
     399        2844 :             else if( aName == "mso-position-vertical" ) mrTypeModel.maPositionVertical = aValue;
     400        2360 :             else if( aName == "mso-width-percent" ) mrTypeModel.maWidthPercent = aValue;
     401        2304 :             else if( aName == "mso-width-relative" ) mrTypeModel.maWidthRelative = aValue;
     402        2256 :             else if( aName == "mso-height-percent" ) mrTypeModel.maHeightPercent = aValue;
     403        2188 :             else if( aName == "mso-height-relative" ) mrTypeModel.maHeightRelative = aValue;
     404        2140 :             else if( aName == "mso-fit-shape-to-text" )           mrTypeModel.mbAutoHeight = true;
     405        2140 :             else if( aName == "rotation" )       mrTypeModel.maRotation = aValue;
     406        2054 :             else if( aName == "flip" )       mrTypeModel.maFlip = aValue;
     407        2020 :             else if( aName.equalsAscii( "visibility" ) )
     408         646 :                 mrTypeModel.mbVisible = !aValue.equalsAscii( "hidden" );
     409        1374 :             else if( aName == "mso-wrap-style" ) mrTypeModel.maWrapStyle = aValue;
     410         746 :             else if ( aName == "v-text-anchor" ) mrTypeModel.maVTextAnchor = aValue;
     411         146 :             else if ( aName == "mso-wrap-distance-left" ) mrTypeModel.maWrapDistanceLeft = aValue;
     412         136 :             else if ( aName == "mso-wrap-distance-right" ) mrTypeModel.maWrapDistanceRight = aValue;
     413         126 :             else if ( aName == "mso-wrap-distance-top" ) mrTypeModel.maWrapDistanceTop = aValue;
     414         114 :             else if ( aName == "mso-wrap-distance-bottom" ) mrTypeModel.maWrapDistanceBottom = aValue;
     415             :         }
     416       13026 :     }
     417        2330 : }
     418             : 
     419        1928 : ShapeContext::ShapeContext( ContextHandler2Helper& rParent, ShapeBase& rShape, const AttributeList& rAttribs ) :
     420             :     ShapeTypeContext( rParent, rShape, rAttribs ),
     421             :     mrShape( rShape ),
     422        1928 :     mrShapeModel( rShape.getShapeModel() )
     423             : {
     424             :     // collect shape specific attributes
     425        1928 :     mrShapeModel.maType = rAttribs.getXString( XML_type, OUString() );
     426             :     // polyline path
     427        1928 :     setPoints( rAttribs.getString( XML_points, OUString() ) );
     428             :     // line start and end positions
     429        1928 :     setFrom(rAttribs.getString(XML_from, OUString()));
     430        1928 :     setTo(rAttribs.getString(XML_to, OUString()));
     431        1928 :     setControl1(rAttribs.getString(XML_control1, OUString()));
     432        1928 :     setControl2(rAttribs.getString(XML_control2, OUString()));
     433        1928 :     setVmlPath(rAttribs.getString(XML_path, OUString()));
     434        1928 : }
     435             : 
     436        2480 : ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     437             : {
     438             :     // Excel specific shape client data
     439        2480 :     if( isRootElement() ) switch( nElement )
     440             :     {
     441             :         case VML_TOKEN( textbox ):
     442         518 :             if (getParentElement() != VML_TOKEN( group ))
     443             :             {
     444             :                 // Custom shape in Writer with a textbox are transformed into a frame
     445         148 :                 dynamic_cast<SimpleShape&>( mrShape ).setService(
     446         296 :                         "com.sun.star.text.TextFrame");
     447             :             }
     448         370 :             else if (getCurrentElement() == VML_TOKEN(rect))
     449             :                 // Transform only rectangles into a TextShape inside a groupshape.
     450         336 :                 dynamic_cast<SimpleShape&>(mrShape).setService("com.sun.star.drawing.TextShape");
     451         518 :             return new TextBoxContext( *this, mrShapeModel.createTextBox(mrShape.getTypeModel()), rAttribs,
     452         518 :                 mrShape.getDrawing().getFilter().getGraphicHelper());
     453             :         case VMLX_TOKEN( ClientData ):
     454           4 :             return new ClientDataContext( *this, mrShapeModel.createClientData(), rAttribs );
     455             :         case VMLPPT_TOKEN( textdata ):
     456             :             // Force RectangleShape, this is ugly :(
     457             :             // and is there because of the lines above which change it to TextFrame
     458           0 :             dynamic_cast< SimpleShape& >( mrShape ).setService(
     459           0 :                     "com.sun.star.drawing.RectangleShape");
     460           0 :             mrShapeModel.maLegacyDiagramPath = getFragmentPathFromRelId(rAttribs.getString(XML_id, OUString()));
     461           0 :             break;
     462             :     }
     463             :     // handle remaining stuff in base class
     464        1958 :     return ShapeTypeContext::onCreateContext( nElement, rAttribs );
     465             : }
     466             : 
     467        1928 : void ShapeContext::setPoints( const OUString& rPoints )
     468             : {
     469        1928 :     mrShapeModel.maPoints.clear();
     470        1928 :     sal_Int32 nIndex = 0;
     471             : 
     472        5788 :     while( nIndex >= 0 )
     473             :     {
     474        1932 :         sal_Int32 nX = rPoints.getToken( 0, ',', nIndex ).toInt32();
     475        1932 :         sal_Int32 nY = rPoints.getToken( 0, ',', nIndex ).toInt32();
     476        1932 :         mrShapeModel.maPoints.push_back( awt::Point( nX, nY ) );
     477             :     }
     478        1928 : }
     479             : 
     480        1928 : void ShapeContext::setFrom( const OUString& rPoints )
     481             : {
     482        1928 :     if (!rPoints.isEmpty())
     483          10 :         mrShapeModel.maFrom = rPoints;
     484        1928 : }
     485             : 
     486        1928 : void ShapeContext::setTo( const OUString& rPoints )
     487             : {
     488        1928 :     if (!rPoints.isEmpty())
     489          10 :         mrShapeModel.maTo = rPoints;
     490        1928 : }
     491             : 
     492        1928 : void ShapeContext::setControl1( const OUString& rPoints )
     493             : {
     494        1928 :     if (!rPoints.isEmpty())
     495           0 :         mrShapeModel.maControl1 = rPoints;
     496        1928 : }
     497             : 
     498        1928 : void ShapeContext::setControl2( const OUString& rPoints )
     499             : {
     500        1928 :     if (!rPoints.isEmpty())
     501           0 :         mrShapeModel.maControl2 = rPoints;
     502        1928 : }
     503        1928 : void ShapeContext::setVmlPath( const OUString& rPath )
     504             : {
     505        1928 :     if (!rPath.isEmpty())
     506         682 :         mrShapeModel.maVmlPath = rPath;
     507        1928 : }
     508             : 
     509          68 : GroupShapeContext::GroupShapeContext( ContextHandler2Helper& rParent, GroupShape& rShape, const AttributeList& rAttribs ) :
     510             :     ShapeContext( rParent, rShape, rAttribs ),
     511          68 :     mrShapes( rShape.getChildren() )
     512             : {
     513          68 : }
     514             : 
     515        1316 : ContextHandlerRef GroupShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     516             : {
     517             :     // try to create a context of an embedded shape
     518        1316 :     ContextHandlerRef xContext = createShapeContext( *this, mrShapes, nElement, rAttribs );
     519             :     // handle remaining stuff of this shape in base class
     520        1316 :     return xContext.get() ? xContext : ShapeContext::onCreateContext( nElement, rAttribs );
     521             : }
     522             : 
     523         468 : RectangleShapeContext::RectangleShapeContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, RectangleShape& rShape ) :
     524         468 :     ShapeContext( rParent, rShape, rAttribs )
     525             : {
     526         468 : }
     527             : 
     528         488 : ContextHandlerRef RectangleShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     529             : {
     530             :     // The parent class's context is fine
     531         488 :     return ShapeContext::onCreateContext( nElement, rAttribs );
     532             : }
     533             : 
     534             : } // namespace vml
     535         408 : } // namespace oox
     536             : 
     537             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10