LCOV - code coverage report
Current view: top level - oox/source/drawingml - linepropertiescontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 42 81.0 %
Date: 2014-11-03 Functions: 4 4 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 "drawingml/linepropertiescontext.hxx"
      21             : #include "oox/drawingml/drawingmltypes.hxx"
      22             : #include "drawingml/fillpropertiesgroupcontext.hxx"
      23             : #include "oox/drawingml/lineproperties.hxx"
      24             : #include "oox/helper/attributelist.hxx"
      25             : 
      26             : using namespace ::oox::core;
      27             : using namespace ::com::sun::star::uno;
      28             : using namespace ::com::sun::star::xml::sax;
      29             : 
      30             : // CT_LineProperties
      31             : 
      32             : namespace oox { namespace drawingml {
      33             : 
      34       12732 : LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs,
      35             :     LineProperties& rLineProperties ) throw()
      36             : : ContextHandler2( rParent )
      37       12732 : , mrLineProperties( rLineProperties )
      38             : {
      39       12732 :     mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w );
      40       12732 :     mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd );
      41       12732 :     mrLineProperties.moLineCap = rAttribs.getToken( XML_cap );
      42       12732 : }
      43             : 
      44       25464 : LinePropertiesContext::~LinePropertiesContext()
      45             : {
      46       25464 : }
      47             : 
      48       26018 : ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      49             : {
      50       26018 :     switch( nElement )
      51             :     {
      52             :         // LineFillPropertiesGroup
      53             :         case A_TOKEN( noFill ):
      54             :         case A_TOKEN( solidFill ):
      55             :         case A_TOKEN( gradFill ):
      56             :         case A_TOKEN( pattFill ):
      57       12498 :             return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill );
      58             :         break;
      59             : 
      60             :         // LineDashPropertiesGroup
      61             :         case A_TOKEN( prstDash ):  // CT_PresetLineDashProperties
      62        8420 :             mrLineProperties.moPresetDash = rAttribs.getToken( XML_val );
      63        8420 :         break;
      64             :         case A_TOKEN( custDash ):  // CT_DashStopList
      65          34 :             return this;
      66             :         break;
      67             :         case A_TOKEN( ds ):
      68             :         {
      69             :             // 'a:ds' has 2 attributes : 'd' and 'sp'
      70             :             // both are of type 'a:ST_PositivePercentage'
      71             :             // according to the specs Office will read percentages formatted with a trailing percent sign
      72             :             // or formatted as 1000th of a percent without a trailing percent sign, but only write percentages
      73             :             // as 1000th's of a percent without a trailing percent sign.
      74             :             // The code below takes care of both scenarios by converting to '1000th of a percent' always
      75          62 :             OUString aStr;
      76          62 :             sal_Int32 nDash = 0;
      77          62 :             aStr = rAttribs.getString( XML_d, "" );
      78          62 :             if ( aStr.endsWith("%") )
      79             :             {
      80             :                 // Ends with a '%'
      81           0 :                 aStr = aStr.copy(0, aStr.getLength() - 1);
      82           0 :                 aStr = aStr.trim();
      83           0 :                 nDash = aStr.toInt32();
      84             : 
      85             :                 // Convert to 1000th of a percent
      86           0 :                 nDash *= 1000;
      87             :             }
      88             :             else
      89             :             {
      90          62 :                 nDash = rAttribs.getInteger( XML_d, 0 );
      91             :             }
      92             : 
      93          62 :             sal_Int32 nSp = 0;
      94          62 :             aStr = rAttribs.getString( XML_sp, "" );
      95          62 :             if ( aStr.endsWith("%") )
      96             :             {
      97             :                 // Ends with a '%'
      98           0 :                 aStr = aStr.copy(0, aStr.getLength() - 1);
      99           0 :                 aStr = aStr.trim();
     100           0 :                 nSp = aStr.toInt32();
     101             : 
     102             :                 // Convert to 1000th of a percent
     103           0 :                 nSp *= 1000;
     104             :             }
     105             :             else
     106             :             {
     107          62 :                 nSp = rAttribs.getInteger( XML_sp, 0 );
     108             :             }
     109             : 
     110          62 :             mrLineProperties.maCustomDash.push_back( LineProperties::DashStop( nDash, nSp ) );
     111             :         }
     112          62 :         break;
     113             : 
     114             :         // LineJoinPropertiesGroup
     115             :         case A_TOKEN( round ):
     116             :         case A_TOKEN( bevel ):
     117             :         case A_TOKEN( miter ):
     118        2642 :             mrLineProperties.moLineJoint = getBaseToken( nElement );
     119        2642 :         break;
     120             : 
     121             :         case A_TOKEN( headEnd ):  // CT_LineEndProperties
     122             :         case A_TOKEN( tailEnd ):  // CT_LineEndProperties
     123             :         {                         // ST_LineEndType
     124        2362 :             bool bTailEnd = nElement == A_TOKEN( tailEnd );
     125        2362 :             LineArrowProperties& rArrowProps = bTailEnd ? mrLineProperties.maEndArrow : mrLineProperties.maStartArrow;
     126        2362 :             rArrowProps.moArrowType = rAttribs.getToken( XML_type );
     127        2362 :             rArrowProps.moArrowWidth = rAttribs.getToken( XML_w );
     128        2362 :             rArrowProps.moArrowLength = rAttribs.getToken( XML_len );
     129             :         }
     130        2362 :         break;
     131             :     }
     132       13486 :     return 0;
     133             : }
     134             : 
     135             : } }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10