LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - HatchStyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 83 66.3 %
Date: 2013-07-09 Functions: 5 6 83.3 %
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             : 
      21             : #include "xmloff/HatchStyle.hxx"
      22             : 
      23             : #include <com/sun/star/drawing/Hatch.hpp>
      24             : 
      25             : #include <sax/tools/converter.hxx>
      26             : 
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include "xmloff/xmlnmspe.hxx"
      30             : #include <xmloff/xmltoken.hxx>
      31             : #include <xmloff/xmlexp.hxx>
      32             : #include <xmloff/xmlimp.hxx>
      33             : #include <rtl/ustrbuf.hxx>
      34             : #include <rtl/ustring.hxx>
      35             : #include <tools/debug.hxx>
      36             : #include <xmloff/xmltkmap.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : using namespace ::xmloff::token;
      41             : 
      42             : enum SvXMLTokenMapAttrs
      43             : {
      44             :     XML_TOK_HATCH_NAME,
      45             :     XML_TOK_HATCH_DISPLAY_NAME,
      46             :     XML_TOK_HATCH_STYLE,
      47             :     XML_TOK_HATCH_COLOR,
      48             :     XML_TOK_HATCH_DISTANCE,
      49             :     XML_TOK_HATCH_ROTATION,
      50             :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      51             : };
      52             : 
      53             : 
      54             : SvXMLEnumMapEntry const pXML_HatchStyle_Enum[] =
      55             : {
      56             :     { XML_HATCHSTYLE_SINGLE,    drawing::HatchStyle_SINGLE },
      57             :     { XML_HATCHSTYLE_DOUBLE,    drawing::HatchStyle_DOUBLE },
      58             :     { XML_HATCHSTYLE_TRIPLE,    drawing::HatchStyle_TRIPLE },
      59             :     { XML_TOKEN_INVALID, 0 }
      60             : };
      61             : 
      62             : 
      63             : //-------------------------------------------------------------
      64             : // Import
      65             : //-------------------------------------------------------------
      66             : 
      67          54 : XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport& rImp )
      68          54 :     : rImport(rImp)
      69             : {
      70          54 : }
      71             : 
      72          54 : XMLHatchStyleImport::~XMLHatchStyleImport()
      73             : {
      74          54 : }
      75             : 
      76          54 : sal_Bool XMLHatchStyleImport::importXML(
      77             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      78             :     uno::Any& rValue,
      79             :     OUString& rStrName )
      80             : {
      81          54 :     sal_Bool bRet = sal_False;
      82             : 
      83          54 :     sal_Bool bHasName  = sal_False;
      84          54 :     sal_Bool bHasStyle = sal_False;
      85          54 :     sal_Bool bHasColor = sal_False;
      86          54 :     sal_Bool bHasDist  = sal_False;
      87          54 :     OUString aDisplayName;
      88             : 
      89          54 :     drawing::Hatch aHatch;
      90          54 :     aHatch.Style = drawing::HatchStyle_SINGLE;
      91          54 :     aHatch.Color = 0;
      92          54 :     aHatch.Distance = 0;
      93          54 :     aHatch.Angle = 0;
      94             : 
      95             :     {
      96             :         static SvXMLTokenMapEntry aHatchAttrTokenMap[] =
      97             : {
      98             :     { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_HATCH_NAME },
      99             :     { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_HATCH_DISPLAY_NAME },
     100             :     { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_HATCH_STYLE },
     101             :     { XML_NAMESPACE_DRAW, XML_COLOR, XML_TOK_HATCH_COLOR },
     102             :     { XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE },
     103             :     { XML_NAMESPACE_DRAW, XML_ROTATION, XML_TOK_HATCH_ROTATION },
     104             :     XML_TOKEN_MAP_END
     105             : };
     106             : 
     107          54 :     SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
     108         108 :     SvXMLNamespaceMap rNamespaceMap = rImport.GetNamespaceMap();
     109          54 :     SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
     110             : 
     111          54 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     112         338 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     113             :     {
     114         284 :         const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
     115         568 :         OUString aStrAttrName;
     116         284 :         sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName );
     117         568 :         const OUString& rStrValue = xAttrList->getValueByIndex( i );
     118             : 
     119         284 :         switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
     120             :         {
     121             :             case XML_TOK_HATCH_NAME:
     122             :                 {
     123          54 :                     rStrName = rStrValue;
     124          54 :                     bHasName = sal_True;
     125             :                 }
     126          54 :                 break;
     127             :             case XML_TOK_HATCH_DISPLAY_NAME:
     128          14 :                 aDisplayName = rStrValue;
     129          14 :                 break;
     130             :             case XML_TOK_HATCH_STYLE:
     131             :                 {
     132             :                     sal_uInt16 eValue;
     133          54 :                     bHasStyle = rUnitConverter.convertEnum( eValue, rStrValue, pXML_HatchStyle_Enum );
     134          54 :                     if( bHasStyle )
     135          54 :                         aHatch.Style = (drawing::HatchStyle) eValue;
     136             :                 }
     137          54 :                 break;
     138             :             case XML_TOK_HATCH_COLOR:
     139             :                 {
     140             :                     bHasColor = ::sax::Converter::convertColor(
     141          54 :                             aHatch.Color, rStrValue);
     142             :                 }
     143          54 :                 break;
     144             :             case XML_TOK_HATCH_DISTANCE:
     145             :                 bHasDist = rUnitConverter.convertMeasureToCore(
     146          54 :                         (sal_Int32&)aHatch.Distance, rStrValue );
     147          54 :                 break;
     148             :             case XML_TOK_HATCH_ROTATION:
     149             :                 {
     150             :                     sal_Int32 nValue;
     151          54 :                     ::sax::Converter::convertNumber(nValue, rStrValue, 0, 3600);
     152          54 :                     aHatch.Angle = sal_Int16( nValue );
     153             :                 }
     154          54 :                 break;
     155             : 
     156             :             default:
     157             :                 DBG_WARNING( "Unknown token at import hatch style" )
     158             :                 ;
     159             :         }
     160         284 :     }
     161             : 
     162          54 :     rValue <<= aHatch;
     163             : 
     164          54 :     if( !aDisplayName.isEmpty() )
     165             :     {
     166             :         rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_HATCH_ID, rStrName,
     167          14 :                                      aDisplayName );
     168          14 :         rStrName = aDisplayName;
     169             :     }
     170             : 
     171         108 :     bRet = bHasName && bHasStyle && bHasColor && bHasDist;
     172             : 
     173             :     }
     174             : 
     175          54 :     return bRet;
     176             : }
     177             : 
     178             : 
     179             : //-------------------------------------------------------------
     180             : // Export
     181             : //-------------------------------------------------------------
     182             : 
     183          35 : XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport& rExp )
     184          35 :     : rExport(rExp)
     185             : {
     186          35 : }
     187             : 
     188          35 : XMLHatchStyleExport::~XMLHatchStyleExport()
     189             : {
     190          35 : }
     191             : 
     192           0 : sal_Bool XMLHatchStyleExport::exportXML(
     193             :     const OUString& rStrName,
     194             :     const uno::Any& rValue )
     195             : {
     196           0 :     sal_Bool bRet = sal_False;
     197           0 :     drawing::Hatch aHatch;
     198             : 
     199           0 :     if( !rStrName.isEmpty() )
     200             :     {
     201           0 :         if( rValue >>= aHatch )
     202             :         {
     203           0 :             OUString aStrValue;
     204           0 :             OUStringBuffer aOut;
     205             : 
     206             :             SvXMLUnitConverter& rUnitConverter =
     207           0 :                 rExport.GetMM100UnitConverter();
     208             : 
     209             :             // Style
     210           0 :             if( !rUnitConverter.convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
     211             :             {
     212           0 :                 bRet = sal_False;
     213             :             }
     214             :             else
     215             :             {
     216             :                 // Name
     217           0 :                 sal_Bool bEncoded = sal_False;
     218             :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
     219             :                                       rExport.EncodeStyleName( rStrName,
     220           0 :                                                                 &bEncoded ) );
     221           0 :                 if( bEncoded )
     222             :                     rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
     223           0 :                                             rStrName );
     224             : 
     225           0 :                 aStrValue = aOut.makeStringAndClear();
     226           0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue );
     227             : 
     228             :                 // Color
     229           0 :                 ::sax::Converter::convertColor(aOut, aHatch.Color);
     230           0 :                 aStrValue = aOut.makeStringAndClear();
     231           0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aStrValue );
     232             : 
     233             :                 // Distance
     234           0 :                 rUnitConverter.convertMeasureToXML( aOut, aHatch.Distance );
     235           0 :                 aStrValue = aOut.makeStringAndClear();
     236           0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, aStrValue );
     237             : 
     238             :                 // Angle
     239           0 :                 ::sax::Converter::convertNumber(aOut, sal_Int32(aHatch.Angle));
     240           0 :                 aStrValue = aOut.makeStringAndClear();
     241           0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, aStrValue );
     242             : 
     243             :                 // Do Write
     244             :                 SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_HATCH,
     245           0 :                                           sal_True, sal_False );
     246           0 :             }
     247             :         }
     248             :     }
     249             : 
     250           0 :     return bRet;
     251             : }
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10