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

Generated by: LCOV version 1.10