LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLFontStylesContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 89 97.8 %
Date: 2012-08-25 Functions: 15 22 68.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64 126 50.8 %

           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 <com/sun/star/awt/FontFamily.hpp>
      31                 :            : #include <com/sun/star/awt/FontPitch.hpp>
      32                 :            : 
      33                 :            : #include <rtl/logfile.hxx>
      34                 :            : 
      35                 :            : #include <xmloff/nmspmap.hxx>
      36                 :            : #include "xmloff/xmlnmspe.hxx"
      37                 :            : #include <xmloff/xmltoken.hxx>
      38                 :            : #include "fonthdl.hxx"
      39                 :            : #include <xmloff/xmlimp.hxx>
      40                 :            : #include <xmloff/maptype.hxx>
      41                 :            : #include <xmloff/XMLFontStylesContext.hxx>
      42                 :            : 
      43                 :            : 
      44                 :            : using ::rtl::OUString;
      45                 :            : using ::rtl::OUStringBuffer;
      46                 :            : 
      47                 :            : using namespace ::com::sun::star;
      48                 :            : using namespace ::com::sun::star::uno;
      49                 :            : using namespace ::com::sun::star::xml::sax;
      50                 :            : using namespace ::com::sun::star::container;
      51                 :            : using namespace ::com::sun::star::beans;
      52                 :            : using namespace ::com::sun::star::lang;
      53                 :            : using namespace ::com::sun::star::awt;
      54                 :            : using namespace ::xmloff::token;
      55                 :            : 
      56                 :            : 
      57                 :            : #define XML_STYLE_FAMILY_FONT 1
      58                 :            : 
      59                 :            : enum XMLFontStyleAttrTokens
      60                 :            : {
      61                 :            :     XML_TOK_FONT_STYLE_ATTR_FAMILY,
      62                 :            :     XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC,
      63                 :            :     XML_TOK_FONT_STYLE_ATTR_STYLENAME,
      64                 :            :     XML_TOK_FONT_STYLE_ATTR_PITCH,
      65                 :            :     XML_TOK_FONT_STYLE_ATTR_CHARSET,
      66                 :            : 
      67                 :            :     XML_TOK_FONT_STYLE_ATTR_END=XML_TOK_UNKNOWN
      68                 :            : };
      69                 :            : 
      70                 :        312 : const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap()
      71                 :            : {
      72                 :            :     static SvXMLTokenMapEntry aFontStyleAttrTokenMap[] =
      73                 :            :     {
      74                 :            :         { XML_NAMESPACE_SVG, XML_FONT_FAMILY,
      75                 :            :                 XML_TOK_FONT_STYLE_ATTR_FAMILY },
      76                 :            :         { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC,
      77                 :            :                 XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC },
      78                 :            :         { XML_NAMESPACE_STYLE, XML_FONT_ADORNMENTS,
      79                 :            :                 XML_TOK_FONT_STYLE_ATTR_STYLENAME },
      80                 :            :         { XML_NAMESPACE_STYLE, XML_FONT_PITCH,
      81                 :            :                 XML_TOK_FONT_STYLE_ATTR_PITCH },
      82                 :            :         { XML_NAMESPACE_STYLE, XML_FONT_CHARSET,
      83                 :            :                 XML_TOK_FONT_STYLE_ATTR_CHARSET },
      84                 :            : 
      85                 :            :         XML_TOKEN_MAP_END
      86                 :            :     };
      87                 :        312 :     return aFontStyleAttrTokenMap;
      88                 :            : }
      89                 :            : 
      90                 :            : class XMLFontStyleContext_Impl : public SvXMLStyleContext
      91                 :            : {
      92                 :            :     Any aFamilyName;
      93                 :            :     Any aStyleName;
      94                 :            :     Any aFamily;
      95                 :            :     Any aPitch;
      96                 :            :     Any aEnc;
      97                 :            : 
      98                 :            :     SvXMLImportContextRef xStyles;
      99                 :            : 
     100                 :      10320 :     XMLFontStylesContext *GetStyles()
     101                 :            :     {
     102                 :      10320 :         return ((XMLFontStylesContext *)&xStyles);
     103                 :            :     }
     104                 :            : 
     105                 :            : public:
     106                 :            : 
     107                 :            :     TYPEINFO();
     108                 :            : 
     109                 :            :     XMLFontStyleContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
     110                 :            :             const ::rtl::OUString& rLName,
     111                 :            :             const ::com::sun::star::uno::Reference<
     112                 :            :                 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
     113                 :            :             XMLFontStylesContext& rStyles );
     114                 :            :     virtual ~XMLFontStyleContext_Impl();
     115                 :            : 
     116                 :            :     void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
     117                 :            :                        const OUString& rValue );
     118                 :            : 
     119                 :            :     void FillProperties( ::std::vector< XMLPropertyState > &rProps,
     120                 :            :                          sal_Int32 nFamilyNameIdx,
     121                 :            :                          sal_Int32 nStyleNameIdx,
     122                 :            :                          sal_Int32 nFamilyIdx,
     123                 :            :                          sal_Int32 nPitchIdx,
     124                 :            :                          sal_Int32 nCharsetIdx ) const;
     125                 :            : 
     126                 :            : };
     127                 :            : 
     128 [ +  - ][ #  # ]:       5140 : TYPEINIT1( XMLFontStyleContext_Impl, SvXMLStyleContext );
     129                 :            : 
     130                 :       1566 : XMLFontStyleContext_Impl::XMLFontStyleContext_Impl( SvXMLImport& rImport,
     131                 :            :         sal_uInt16 nPrfx, const OUString& rLName,
     132                 :            :         const Reference< XAttributeList > & xAttrList,
     133                 :            :         XMLFontStylesContext& rStyles ) :
     134                 :            :     SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ),
     135                 :       1566 :     xStyles( &rStyles )
     136                 :            : {
     137                 :       1566 :     OUString sEmpty;
     138         [ +  - ]:       1566 :     aFamilyName <<= sEmpty;
     139         [ +  - ]:       1566 :     aStyleName <<= sEmpty;
     140         [ +  - ]:       1566 :     aFamily <<= (sal_Int16)FontFamily::DONTKNOW;
     141         [ +  - ]:       1566 :     aPitch <<= (sal_Int16)FontPitch::DONTKNOW;
     142         [ +  - ]:       1566 :     aEnc <<= (sal_Int16)rStyles.GetDfltCharset();
     143                 :       1566 : }
     144                 :            : 
     145                 :       5952 : void XMLFontStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
     146                 :            :                                         const OUString& rLocalName,
     147                 :            :                                         const OUString& rValue )
     148                 :            : {
     149                 :       5952 :     SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
     150                 :       5952 :     const SvXMLTokenMap& rTokenMap = GetStyles()->GetFontStyleAttrTokenMap();
     151                 :       5952 :     Any aAny;
     152                 :            : 
     153   [ +  +  +  +  :       5952 :     switch( rTokenMap.Get( nPrefixKey, rLocalName ) )
           +  + ][ +  - ]
     154                 :            :     {
     155                 :            :     case XML_TOK_FONT_STYLE_ATTR_FAMILY:
     156         [ +  + ]:       3132 :         if( GetStyles()->GetFamilyNameHdl().importXML( rValue, aAny,
     157         [ +  - ]:       1566 :                                                           rUnitConv ) )
     158                 :       1560 :             aFamilyName = aAny;
     159                 :       1566 :         break;
     160                 :            :     case XML_TOK_FONT_STYLE_ATTR_STYLENAME:
     161         [ +  - ]:         18 :         aStyleName <<= rValue;
     162                 :         18 :         break;
     163                 :            :     case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC:
     164         [ +  - ]:       2828 :         if( GetStyles()->GetFamilyHdl().importXML( rValue, aAny,
     165         [ +  - ]:       1414 :                                                       rUnitConv ) )
     166                 :       1414 :             aFamily = aAny;
     167                 :       1414 :         break;
     168                 :            :     case XML_TOK_FONT_STYLE_ATTR_PITCH:
     169         [ +  - ]:       2764 :         if( GetStyles()->GetPitchHdl().importXML( rValue, aAny,
     170         [ +  - ]:       1382 :                                                       rUnitConv ) )
     171                 :       1382 :             aPitch = aAny;
     172                 :       1382 :         break;
     173                 :            :     case XML_TOK_FONT_STYLE_ATTR_CHARSET:
     174         [ +  - ]:         12 :         if( GetStyles()->GetEncodingHdl().importXML( rValue, aAny,
     175         [ +  - ]:          6 :                                                       rUnitConv ) )
     176                 :          6 :             aEnc = aAny;
     177                 :          6 :         break;
     178                 :            :     default:
     179         [ +  - ]:       1566 :         SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
     180                 :       1566 :         break;
     181                 :       5952 :     }
     182                 :       5952 : }
     183                 :            : 
     184         [ +  - ]:       1566 : XMLFontStyleContext_Impl::~XMLFontStyleContext_Impl()
     185                 :            : {
     186         [ -  + ]:       3132 : }
     187                 :            : 
     188                 :       1285 : void XMLFontStyleContext_Impl::FillProperties(
     189                 :            :         ::std::vector< XMLPropertyState > &rProps,
     190                 :            :         sal_Int32 nFamilyNameIdx,
     191                 :            :         sal_Int32 nStyleNameIdx,
     192                 :            :         sal_Int32 nFamilyIdx,
     193                 :            :         sal_Int32 nPitchIdx,
     194                 :            :         sal_Int32 nCharsetIdx ) const
     195                 :            : {
     196         [ +  - ]:       1285 :     if( nFamilyNameIdx != -1 )
     197                 :            :     {
     198                 :       1285 :         XMLPropertyState aPropState( nFamilyNameIdx, aFamilyName );
     199         [ +  - ]:       1285 :         rProps.push_back( aPropState );
     200                 :            :     }
     201         [ +  - ]:       1285 :     if( nStyleNameIdx != -1 )
     202                 :            :     {
     203                 :       1285 :         XMLPropertyState aPropState( nStyleNameIdx, aStyleName );
     204         [ +  - ]:       1285 :         rProps.push_back( aPropState );
     205                 :            :     }
     206         [ +  - ]:       1285 :     if( nFamilyIdx != -1 )
     207                 :            :     {
     208                 :       1285 :         XMLPropertyState aPropState( nFamilyIdx, aFamily );
     209         [ +  - ]:       1285 :         rProps.push_back( aPropState );
     210                 :            :     }
     211         [ +  - ]:       1285 :     if( nPitchIdx != -1 )
     212                 :            :     {
     213                 :       1285 :         XMLPropertyState aPropState( nPitchIdx, aPitch );
     214         [ +  - ]:       1285 :         rProps.push_back( aPropState );
     215                 :            :     }
     216         [ +  - ]:       1285 :     if( nCharsetIdx != -1 )
     217                 :            :     {
     218                 :       1285 :         XMLPropertyState aPropState( nCharsetIdx, aEnc );
     219         [ +  - ]:       1285 :         rProps.push_back( aPropState );
     220                 :            :     }
     221                 :       1285 : }
     222                 :            : 
     223                 :       1566 : SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext(
     224                 :            :         sal_uInt16 nPrefix,
     225                 :            :         const ::rtl::OUString& rLocalName,
     226                 :            :         const ::com::sun::star::uno::Reference<
     227                 :            :             ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
     228                 :            : {
     229                 :            :     SvXMLStyleContext *pStyle;
     230   [ +  -  +  - ]:       3132 :     if( XML_NAMESPACE_STYLE == nPrefix &&
                 [ +  - ]
     231                 :       1566 :         IsXMLToken( rLocalName, XML_FONT_FACE ) )
     232                 :            :     {
     233                 :       1566 :         pStyle = new XMLFontStyleContext_Impl( GetImport(), nPrefix,
     234         [ +  - ]:       1566 :                                                rLocalName, xAttrList, *this );
     235                 :            :     }
     236                 :            :     else
     237                 :            :     {
     238                 :            :         pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix,
     239                 :          0 :                                                rLocalName, xAttrList );
     240                 :            :     }
     241                 :            : 
     242                 :       1566 :     return pStyle;
     243                 :            : }
     244                 :            : 
     245 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLFontStylesContext, SvXMLStylesContext );
     246                 :            : 
     247                 :        312 : XMLFontStylesContext::XMLFontStylesContext( SvXMLImport& rImport,
     248                 :            :         sal_uInt16 nPrfx, const OUString& rLName,
     249                 :            :         const Reference< XAttributeList > & xAttrList,
     250                 :            :         rtl_TextEncoding eDfltEnc ) :
     251                 :            :     SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
     252         [ +  - ]:        312 :     pFamilyNameHdl( new XMLFontFamilyNamePropHdl ),
     253         [ +  - ]:        312 :     pFamilyHdl( new XMLFontFamilyPropHdl ),
     254         [ +  - ]:        312 :     pPitchHdl( new XMLFontPitchPropHdl ),
     255         [ +  - ]:        312 :     pEncHdl( new XMLFontEncodingPropHdl ),
     256         [ +  - ]:        312 :     pFontStyleAttrTokenMap( new SvXMLTokenMap(lcl_getFontStyleAttrTokenMap()) ),
     257 [ +  - ][ +  - ]:       1560 :     eDfltEncoding( eDfltEnc )
         [ +  - ][ +  - ]
                 [ +  - ]
     258                 :            : {
     259                 :        312 : }
     260                 :            : 
     261                 :        312 : XMLFontStylesContext::~XMLFontStylesContext()
     262                 :            : {
     263 [ +  - ][ +  - ]:        312 :     delete pFamilyNameHdl;
     264 [ +  - ][ +  - ]:        312 :     delete pFamilyHdl;
     265 [ +  - ][ +  - ]:        312 :     delete pPitchHdl;
     266 [ +  - ][ +  - ]:        312 :     delete pEncHdl;
     267 [ +  - ][ +  - ]:        312 :     delete pFontStyleAttrTokenMap;
     268         [ -  + ]:        624 : }
     269                 :            : 
     270                 :       1285 : sal_Bool XMLFontStylesContext::FillProperties( const OUString& rName,
     271                 :            :                          ::std::vector< XMLPropertyState > &rProps,
     272                 :            :                          sal_Int32 nFamilyNameIdx,
     273                 :            :                          sal_Int32 nStyleNameIdx,
     274                 :            :                          sal_Int32 nFamilyIdx,
     275                 :            :                          sal_Int32 nPitchIdx,
     276                 :            :                          sal_Int32 nCharsetIdx ) const
     277                 :            : {
     278                 :       1285 :     const SvXMLStyleContext* pStyle = FindStyleChildContext( XML_STYLE_FAMILY_FONT, rName, sal_True );
     279 [ +  - ][ +  - ]:       1285 :     const XMLFontStyleContext_Impl *pFontStyle = PTR_CAST( XMLFontStyleContext_Impl,pStyle);// use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
     280         [ +  - ]:       1285 :     if( pFontStyle )
     281                 :            :         pFontStyle->FillProperties( rProps, nFamilyNameIdx, nStyleNameIdx,
     282                 :       1285 :                                     nFamilyIdx, nPitchIdx, nCharsetIdx );
     283                 :       1285 :     return 0 != pFontStyle;
     284                 :            : }
     285                 :            : 
     286                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10