LCOV - code coverage report
Current view: top level - xmloff/source/style - HatchStyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 83 66.3 %
Date: 2012-08-25 Functions: 5 6 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 103 33.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "xmloff/HatchStyle.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/drawing/Hatch.hpp>
      33                 :            : 
      34                 :            : #include <sax/tools/converter.hxx>
      35                 :            : 
      36                 :            : #include <xmloff/nmspmap.hxx>
      37                 :            : #include <xmloff/xmluconv.hxx>
      38                 :            : #include "xmloff/xmlnmspe.hxx"
      39                 :            : #include <xmloff/xmltoken.hxx>
      40                 :            : #include <xmloff/xmlexp.hxx>
      41                 :            : #include <xmloff/xmlimp.hxx>
      42                 :            : #include <rtl/ustrbuf.hxx>
      43                 :            : #include <rtl/ustring.hxx>
      44                 :            : #include <tools/debug.hxx>
      45                 :            : #include <xmloff/xmltkmap.hxx>
      46                 :            : 
      47                 :            : using namespace ::com::sun::star;
      48                 :            : using ::rtl::OUString;
      49                 :            : using ::rtl::OUStringBuffer;
      50                 :            : 
      51                 :            : using namespace ::xmloff::token;
      52                 :            : 
      53                 :            : enum SvXMLTokenMapAttrs
      54                 :            : {
      55                 :            :     XML_TOK_HATCH_NAME,
      56                 :            :     XML_TOK_HATCH_DISPLAY_NAME,
      57                 :            :     XML_TOK_HATCH_STYLE,
      58                 :            :     XML_TOK_HATCH_COLOR,
      59                 :            :     XML_TOK_HATCH_DISTANCE,
      60                 :            :     XML_TOK_HATCH_ROTATION,
      61                 :            :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      62                 :            : };
      63                 :            : 
      64                 :            : 
      65                 :            : SvXMLEnumMapEntry const pXML_HatchStyle_Enum[] =
      66                 :            : {
      67                 :            :     { XML_HATCHSTYLE_SINGLE,    drawing::HatchStyle_SINGLE },
      68                 :            :     { XML_HATCHSTYLE_DOUBLE,    drawing::HatchStyle_DOUBLE },
      69                 :            :     { XML_HATCHSTYLE_TRIPLE,    drawing::HatchStyle_TRIPLE },
      70                 :            :     { XML_TOKEN_INVALID, 0 }
      71                 :            : };
      72                 :            : 
      73                 :            : 
      74                 :            : //-------------------------------------------------------------
      75                 :            : // Import
      76                 :            : //-------------------------------------------------------------
      77                 :            : 
      78                 :        116 : XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport& rImp )
      79                 :        116 :     : rImport(rImp)
      80                 :            : {
      81                 :        116 : }
      82                 :            : 
      83                 :        116 : XMLHatchStyleImport::~XMLHatchStyleImport()
      84                 :            : {
      85                 :        116 : }
      86                 :            : 
      87                 :        116 : sal_Bool XMLHatchStyleImport::importXML(
      88                 :            :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      89                 :            :     uno::Any& rValue,
      90                 :            :     OUString& rStrName )
      91                 :            : {
      92                 :        116 :     sal_Bool bRet = sal_False;
      93                 :            : 
      94                 :        116 :     sal_Bool bHasName  = sal_False;
      95                 :        116 :     sal_Bool bHasStyle = sal_False;
      96                 :        116 :     sal_Bool bHasColor = sal_False;
      97                 :        116 :     sal_Bool bHasDist  = sal_False;
      98                 :        116 :     OUString aDisplayName;
      99                 :            : 
     100                 :        116 :     drawing::Hatch aHatch;
     101                 :        116 :     aHatch.Style = drawing::HatchStyle_SINGLE;
     102                 :        116 :     aHatch.Color = 0;
     103                 :        116 :     aHatch.Distance = 0;
     104                 :        116 :     aHatch.Angle = 0;
     105                 :            : 
     106                 :            :     {
     107                 :            :         static SvXMLTokenMapEntry aHatchAttrTokenMap[] =
     108                 :            : {
     109                 :            :     { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_HATCH_NAME },
     110                 :            :     { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_HATCH_DISPLAY_NAME },
     111                 :            :     { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_HATCH_STYLE },
     112                 :            :     { XML_NAMESPACE_DRAW, XML_COLOR, XML_TOK_HATCH_COLOR },
     113                 :            :     { XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE },
     114                 :            :     { XML_NAMESPACE_DRAW, XML_ROTATION, XML_TOK_HATCH_ROTATION },
     115                 :            :     XML_TOKEN_MAP_END
     116                 :            : };
     117                 :            : 
     118         [ +  - ]:        116 :     SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
     119         [ +  - ]:        116 :     SvXMLNamespaceMap rNamespaceMap = rImport.GetNamespaceMap();
     120                 :        116 :     SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
     121                 :            : 
     122 [ +  - ][ +  - ]:        116 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
     123         [ +  + ]:        732 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     124                 :            :     {
     125 [ +  - ][ +  - ]:        616 :         const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
     126                 :        616 :         OUString aStrAttrName;
     127         [ +  - ]:        616 :         sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName );
     128 [ +  - ][ +  - ]:        616 :         const OUString& rStrValue = xAttrList->getValueByIndex( i );
     129                 :            : 
     130 [ +  - ][ +  +  :        616 :         switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
             +  +  +  +  
                      - ]
     131                 :            :         {
     132                 :            :             case XML_TOK_HATCH_NAME:
     133                 :            :                 {
     134                 :        116 :                     rStrName = rStrValue;
     135                 :        116 :                     bHasName = sal_True;
     136                 :            :                 }
     137                 :        116 :                 break;
     138                 :            :             case XML_TOK_HATCH_DISPLAY_NAME:
     139                 :         36 :                 aDisplayName = rStrValue;
     140                 :         36 :                 break;
     141                 :            :             case XML_TOK_HATCH_STYLE:
     142                 :            :                 {
     143                 :            :                     sal_uInt16 eValue;
     144         [ +  - ]:        116 :                     bHasStyle = rUnitConverter.convertEnum( eValue, rStrValue, pXML_HatchStyle_Enum );
     145         [ +  - ]:        116 :                     if( bHasStyle )
     146                 :        116 :                         aHatch.Style = (drawing::HatchStyle) eValue;
     147                 :            :                 }
     148                 :        116 :                 break;
     149                 :            :             case XML_TOK_HATCH_COLOR:
     150                 :            :                 {
     151                 :            :                     bHasColor = ::sax::Converter::convertColor(
     152         [ +  - ]:        116 :                             aHatch.Color, rStrValue);
     153                 :            :                 }
     154                 :        116 :                 break;
     155                 :            :             case XML_TOK_HATCH_DISTANCE:
     156                 :            :                 bHasDist = rUnitConverter.convertMeasureToCore(
     157         [ +  - ]:        116 :                         (sal_Int32&)aHatch.Distance, rStrValue );
     158                 :        116 :                 break;
     159                 :            :             case XML_TOK_HATCH_ROTATION:
     160                 :            :                 {
     161                 :            :                     sal_Int32 nValue;
     162         [ +  - ]:        116 :                     ::sax::Converter::convertNumber(nValue, rStrValue, 0, 3600);
     163                 :        116 :                     aHatch.Angle = sal_Int16( nValue );
     164                 :            :                 }
     165                 :        116 :                 break;
     166                 :            : 
     167                 :            :             default:
     168                 :            :                 DBG_WARNING( "Unknown token at import hatch style" )
     169                 :            :                 ;
     170                 :            :         }
     171                 :        616 :     }
     172                 :            : 
     173         [ +  - ]:        116 :     rValue <<= aHatch;
     174                 :            : 
     175         [ +  + ]:        116 :     if( !aDisplayName.isEmpty() )
     176                 :            :     {
     177                 :            :         rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_HATCH_ID, rStrName,
     178         [ +  - ]:         36 :                                      aDisplayName );
     179                 :         36 :         rStrName = aDisplayName;
     180                 :            :     }
     181                 :            : 
     182 [ +  - ][ +  - ]:        116 :     bRet = bHasName && bHasStyle && bHasColor && bHasDist;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     183                 :            : 
     184                 :            :     }
     185                 :            : 
     186                 :        116 :     return bRet;
     187                 :            : }
     188                 :            : 
     189                 :            : 
     190                 :            : //-------------------------------------------------------------
     191                 :            : // Export
     192                 :            : //-------------------------------------------------------------
     193                 :            : 
     194                 :         46 : XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport& rExp )
     195                 :         46 :     : rExport(rExp)
     196                 :            : {
     197                 :         46 : }
     198                 :            : 
     199                 :         46 : XMLHatchStyleExport::~XMLHatchStyleExport()
     200                 :            : {
     201                 :         46 : }
     202                 :            : 
     203                 :          0 : sal_Bool XMLHatchStyleExport::exportXML(
     204                 :            :     const OUString& rStrName,
     205                 :            :     const uno::Any& rValue )
     206                 :            : {
     207                 :          0 :     sal_Bool bRet = sal_False;
     208                 :          0 :     drawing::Hatch aHatch;
     209                 :            : 
     210         [ #  # ]:          0 :     if( !rStrName.isEmpty() )
     211                 :            :     {
     212 [ #  # ][ #  # ]:          0 :         if( rValue >>= aHatch )
     213                 :            :         {
     214                 :          0 :             OUString aStrValue;
     215                 :          0 :             OUStringBuffer aOut;
     216                 :            : 
     217                 :            :             SvXMLUnitConverter& rUnitConverter =
     218                 :          0 :                 rExport.GetMM100UnitConverter();
     219                 :            : 
     220                 :            :             // Style
     221 [ #  # ][ #  # ]:          0 :             if( !rUnitConverter.convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
     222                 :            :             {
     223                 :          0 :                 bRet = sal_False;
     224                 :            :             }
     225                 :            :             else
     226                 :            :             {
     227                 :            :                 // Name
     228                 :          0 :                 sal_Bool bEncoded = sal_False;
     229                 :            :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
     230                 :            :                                       rExport.EncodeStyleName( rStrName,
     231 [ #  # ][ #  # ]:          0 :                                                                 &bEncoded ) );
     232         [ #  # ]:          0 :                 if( bEncoded )
     233                 :            :                     rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
     234         [ #  # ]:          0 :                                             rStrName );
     235                 :            : 
     236         [ #  # ]:          0 :                 aStrValue = aOut.makeStringAndClear();
     237         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue );
     238                 :            : 
     239                 :            :                 // Color
     240         [ #  # ]:          0 :                 ::sax::Converter::convertColor(aOut, aHatch.Color);
     241         [ #  # ]:          0 :                 aStrValue = aOut.makeStringAndClear();
     242         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aStrValue );
     243                 :            : 
     244                 :            :                 // Distance
     245         [ #  # ]:          0 :                 rUnitConverter.convertMeasureToXML( aOut, aHatch.Distance );
     246         [ #  # ]:          0 :                 aStrValue = aOut.makeStringAndClear();
     247         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, aStrValue );
     248                 :            : 
     249                 :            :                 // Angle
     250         [ #  # ]:          0 :                 ::sax::Converter::convertNumber(aOut, sal_Int32(aHatch.Angle));
     251         [ #  # ]:          0 :                 aStrValue = aOut.makeStringAndClear();
     252         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, aStrValue );
     253                 :            : 
     254                 :            :                 // Do Write
     255                 :            :                 SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_HATCH,
     256 [ #  # ][ #  # ]:          0 :                                           sal_True, sal_False );
     257                 :          0 :             }
     258                 :            :         }
     259                 :            :     }
     260                 :            : 
     261                 :          0 :     return bRet;
     262                 :            : }
     263                 :            : 
     264                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10