LCOV - code coverage report
Current view: top level - oox/source/drawingml - linepropertiescontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 42 81.0 %
Date: 2015-06-13 12:38:46 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        7339 : LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs,
      35             :     LineProperties& rLineProperties ) throw()
      36             : : ContextHandler2( rParent )
      37        7339 : , mrLineProperties( rLineProperties )
      38             : {
      39        7339 :     mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w );
      40        7339 :     mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd );
      41        7339 :     mrLineProperties.moLineCap = rAttribs.getToken( XML_cap );
      42        7339 : }
      43             : 
      44       14678 : LinePropertiesContext::~LinePropertiesContext()
      45             : {
      46       14678 : }
      47             : 
      48       14764 : ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      49             : {
      50       14764 :     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        7218 :             return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill );
      58             :         break;
      59             : 
      60             :         // LineDashPropertiesGroup
      61             :         case A_TOKEN( prstDash ):  // CT_PresetLineDashProperties
      62        4630 :             mrLineProperties.moPresetDash = rAttribs.getToken( XML_val );
      63        4630 :         break;
      64             :         case A_TOKEN( custDash ):  // CT_DashStopList
      65          23 :             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          37 :             OUString aStr;
      76          37 :             sal_Int32 nDash = 0;
      77          37 :             aStr = rAttribs.getString( XML_d, "" );
      78          37 :             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          37 :                 nDash = rAttribs.getInteger( XML_d, 0 );
      91             :             }
      92             : 
      93          37 :             sal_Int32 nSp = 0;
      94          37 :             aStr = rAttribs.getString( XML_sp, "" );
      95          37 :             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          37 :                 nSp = rAttribs.getInteger( XML_sp, 0 );
     108             :             }
     109             : 
     110          37 :             mrLineProperties.maCustomDash.push_back( LineProperties::DashStop( nDash, nSp ) );
     111             :         }
     112          37 :         break;
     113             : 
     114             :         // LineJoinPropertiesGroup
     115             :         case A_TOKEN( round ):
     116             :         case A_TOKEN( bevel ):
     117             :         case A_TOKEN( miter ):
     118        1633 :             mrLineProperties.moLineJoint = getBaseToken( nElement );
     119        1633 :         break;
     120             : 
     121             :         case A_TOKEN( headEnd ):  // CT_LineEndProperties
     122             :         case A_TOKEN( tailEnd ):  // CT_LineEndProperties
     123             :         {                         // ST_LineEndType
     124        1223 :             bool bTailEnd = nElement == A_TOKEN( tailEnd );
     125        1223 :             LineArrowProperties& rArrowProps = bTailEnd ? mrLineProperties.maEndArrow : mrLineProperties.maStartArrow;
     126        1223 :             rArrowProps.moArrowType = rAttribs.getToken( XML_type );
     127        1223 :             rArrowProps.moArrowWidth = rAttribs.getToken( XML_w );
     128        1223 :             rArrowProps.moArrowLength = rAttribs.getToken( XML_len );
     129             :         }
     130        1223 :         break;
     131             :     }
     132        7523 :     return 0;
     133             : }
     134             : 
     135             : } }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11