LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLFontAutoStylePool.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 99 107 92.5 %
Date: 2012-08-25 Functions: 18 18 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64 112 57.1 %

           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                 :            : #include <o3tl/sorted_vector.hxx>
      30                 :            : #include <tools/fontenum.hxx>
      31                 :            : #include "xmloff/xmlnmspe.hxx"
      32                 :            : #include <xmloff/xmltoken.hxx>
      33                 :            : #include <xmloff/xmluconv.hxx>
      34                 :            : #include "fonthdl.hxx"
      35                 :            : #include <xmloff/xmlexp.hxx>
      36                 :            : #include <xmloff/XMLFontAutoStylePool.hxx>
      37                 :            : 
      38                 :            : 
      39                 :            : using ::rtl::OUString;
      40                 :            : using ::rtl::OUStringBuffer;
      41                 :            : 
      42                 :            : using namespace ::com::sun::star::uno;
      43                 :            : using namespace ::xmloff::token;
      44                 :            : 
      45                 :       1495 : class XMLFontAutoStylePoolEntry_Impl
      46                 :            : {
      47                 :            :     OUString    sName;
      48                 :            :     OUString    sFamilyName;
      49                 :            :     OUString    sStyleName;
      50                 :            :     sal_Int16   nFamily;
      51                 :            :     sal_Int16   nPitch;
      52                 :            :     rtl_TextEncoding eEnc;
      53                 :            : 
      54                 :            : public:
      55                 :            : 
      56                 :            :     inline XMLFontAutoStylePoolEntry_Impl(
      57                 :            :             const ::rtl::OUString& rName,
      58                 :            :             const ::rtl::OUString& rFamilyName,
      59                 :            :             const ::rtl::OUString& rStyleName,
      60                 :            :             sal_Int16 nFamily,
      61                 :            :             sal_Int16 nPitch,
      62                 :            :             rtl_TextEncoding eEnc );
      63                 :            : 
      64                 :            :     inline XMLFontAutoStylePoolEntry_Impl(
      65                 :            :             const ::rtl::OUString& rFamilyName,
      66                 :            :             const ::rtl::OUString& rStyleName,
      67                 :            :             sal_Int16 nFamily,
      68                 :            :             sal_Int16 nPitch,
      69                 :            :             rtl_TextEncoding eEnc );
      70                 :            : 
      71                 :        722 :     const OUString& GetName() const { return sName; }
      72                 :       3578 :     const OUString& GetFamilyName() const { return sFamilyName; }
      73                 :       2078 :     const OUString& GetStyleName() const { return sStyleName; }
      74                 :       6310 :     sal_Int16 GetFamily() const {   return nFamily; }
      75                 :       7344 :     sal_Int16 GetPitch() const { return nPitch; }
      76                 :       6144 :     rtl_TextEncoding GetEncoding() const { return eEnc; }
      77                 :            : };
      78                 :            : 
      79                 :            : 
      80                 :        270 : inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl(
      81                 :            :         const ::rtl::OUString& rName,
      82                 :            :         const ::rtl::OUString& rFamilyName,
      83                 :            :         const ::rtl::OUString& rStyleName,
      84                 :            :         sal_Int16 nFam,
      85                 :            :         sal_Int16 nP,
      86                 :            :         rtl_TextEncoding eE ) :
      87                 :            :     sName( rName ),
      88                 :            :     sFamilyName( rFamilyName ),
      89                 :            :     sStyleName( rStyleName ),
      90                 :            :     nFamily( nFam ),
      91                 :            :     nPitch( nP ),
      92                 :        270 :     eEnc( eE )
      93                 :            : {
      94                 :        270 : }
      95                 :            : 
      96                 :       1225 : inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl(
      97                 :            :         const ::rtl::OUString& rFamilyName,
      98                 :            :         const ::rtl::OUString& rStyleName,
      99                 :            :         sal_Int16 nFam,
     100                 :            :         sal_Int16 nP,
     101                 :            :         rtl_TextEncoding eE ) :
     102                 :            :     sFamilyName( rFamilyName ),
     103                 :            :     sStyleName( rStyleName ),
     104                 :            :     nFamily( nFam ),
     105                 :            :     nPitch( nP ),
     106                 :       1225 :     eEnc( eE )
     107                 :            : {
     108                 :       1225 : }
     109                 :            : 
     110                 :            : struct XMLFontAutoStylePoolEntryCmp_Impl {
     111                 :       2937 :     bool operator()(
     112                 :            :         XMLFontAutoStylePoolEntry_Impl* const& r1,
     113                 :            :         XMLFontAutoStylePoolEntry_Impl* const& r2 ) const
     114                 :            :     {
     115                 :       2937 :         sal_Int8 nEnc1(r1->GetEncoding() != RTL_TEXTENCODING_SYMBOL);
     116                 :       2937 :         sal_Int8 nEnc2(r2->GetEncoding() != RTL_TEXTENCODING_SYMBOL);
     117         [ -  + ]:       2937 :         if( nEnc1 != nEnc2 )
     118                 :          0 :             return nEnc1 < nEnc2;
     119         [ +  + ]:       2937 :         else if( r1->GetPitch() != r2->GetPitch() )
     120                 :        600 :             return r1->GetPitch() < r2->GetPitch();
     121         [ +  + ]:       2337 :         else if( r1->GetFamily() != r2->GetFamily() )
     122                 :        683 :             return r1->GetFamily() < r2->GetFamily();
     123                 :            :         else
     124                 :            :         {
     125                 :       1654 :             sal_Int32 nCmp = r1->GetFamilyName().compareTo( r2->GetFamilyName() );
     126         [ +  + ]:       1654 :             if( 0 == nCmp )
     127                 :        904 :                 return r1->GetStyleName().compareTo( r2->GetStyleName() ) < 0;
     128                 :            :             else
     129                 :       2937 :                 return nCmp < 0;
     130                 :            :         }
     131                 :            :     }
     132                 :            : };
     133                 :            : 
     134                 :        234 : class XMLFontAutoStylePool_Impl : public o3tl::sorted_vector<XMLFontAutoStylePoolEntry_Impl*, XMLFontAutoStylePoolEntryCmp_Impl>
     135                 :            : {
     136                 :            : public:
     137         [ +  - ]:        234 :     ~XMLFontAutoStylePool_Impl() { DeleteAndDestroyAll(); }
     138                 :            : };
     139                 :            : 
     140                 :        234 : XMLFontAutoStylePool::XMLFontAutoStylePool( SvXMLExport& rExp ) :
     141                 :            :     rExport( rExp ),
     142 [ +  - ][ +  - ]:        234 :     pPool( new XMLFontAutoStylePool_Impl )
                 [ +  - ]
     143                 :            : {
     144                 :        234 : }
     145                 :            : 
     146                 :        234 : XMLFontAutoStylePool::~XMLFontAutoStylePool()
     147                 :            : {
     148 [ +  - ][ +  - ]:        234 :     delete pPool;
     149         [ -  + ]:        418 : }
     150                 :            : 
     151                 :        450 : OUString XMLFontAutoStylePool::Add(
     152                 :            :             const OUString& rFamilyName,
     153                 :            :             const OUString& rStyleName,
     154                 :            :             sal_Int16 nFamily,
     155                 :            :             sal_Int16 nPitch,
     156                 :            :             rtl_TextEncoding eEnc )
     157                 :            : {
     158                 :        450 :     OUString sPoolName;
     159                 :            :     XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily,
     160                 :        450 :                                           nPitch, eEnc );
     161         [ +  - ]:        450 :     XMLFontAutoStylePool_Impl::const_iterator it = pPool->find( &aTmp );
     162 [ +  - ][ +  + ]:        450 :     if( it != pPool->end() )
     163                 :            :     {
     164                 :        180 :         sPoolName = (*it)->GetName();
     165                 :            :     }
     166                 :            :     else
     167                 :            :     {
     168                 :        270 :         OUString sName;
     169                 :        270 :         sal_Int32 nLen = rFamilyName.indexOf( sal_Unicode(';'), 0 );
     170         [ +  + ]:        270 :         if( -1 == nLen )
     171                 :            :         {
     172                 :        264 :             sName = rFamilyName;
     173                 :            :         }
     174         [ +  - ]:          6 :         else if( nLen > 0 )
     175                 :            :         {
     176                 :          6 :             sName = rFamilyName.copy( 0, nLen );
     177                 :          6 :             sName.trim();
     178                 :            :         }
     179                 :            : 
     180         [ -  + ]:        270 :         if( sName.isEmpty() )
     181                 :          0 :             sName = OUString::valueOf( sal_Unicode( 'F' ) );
     182                 :            : 
     183 [ +  - ][ +  + ]:        270 :         if( m_aNames.find(sName) != m_aNames.end() )
     184                 :            :         {
     185                 :         54 :             sal_Int32 nCount = 1;
     186                 :         54 :             OUString sPrefix( sName );
     187                 :         54 :             sName += OUString::valueOf( nCount );
     188 [ +  - ][ -  + ]:         54 :             while( m_aNames.find(sName) != m_aNames.end() )
     189                 :            :             {
     190                 :          0 :                 sName = sPrefix;
     191                 :          0 :                 sName += OUString::valueOf( ++nCount );
     192                 :         54 :             }
     193                 :            :         }
     194                 :            : 
     195                 :            :         XMLFontAutoStylePoolEntry_Impl *pEntry =
     196                 :            :             new XMLFontAutoStylePoolEntry_Impl( sName, rFamilyName, rStyleName,
     197         [ +  - ]:        270 :                                                 nFamily, nPitch, eEnc );
     198         [ +  - ]:        270 :         pPool->insert( pEntry );
     199         [ +  - ]:        270 :         m_aNames.insert(sName);
     200                 :            :     }
     201                 :            : 
     202                 :        450 :     return sPoolName;
     203                 :            : }
     204                 :            : 
     205                 :        775 : ::rtl::OUString XMLFontAutoStylePool::Find(
     206                 :            :             const OUString& rFamilyName,
     207                 :            :             const OUString& rStyleName,
     208                 :            :             sal_Int16 nFamily,
     209                 :            :             sal_Int16 nPitch,
     210                 :            :             rtl_TextEncoding eEnc ) const
     211                 :            : {
     212                 :        775 :     OUString sName;
     213                 :            :     XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily,
     214                 :        775 :                                           nPitch, eEnc );
     215         [ +  - ]:        775 :     XMLFontAutoStylePool_Impl::const_iterator it = pPool->find( &aTmp );
     216 [ +  - ][ +  + ]:        775 :     if( it != pPool->end() )
     217                 :            :     {
     218                 :        272 :         sName = (*it)->GetName();
     219                 :            :     }
     220                 :            : 
     221                 :        775 :     return sName;
     222                 :            : }
     223                 :            : 
     224                 :            : 
     225                 :        226 : void XMLFontAutoStylePool::exportXML()
     226                 :            : {
     227                 :        226 :     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_OFFICE,
     228                 :            :                               XML_FONT_FACE_DECLS,
     229         [ +  - ]:        226 :                               sal_True, sal_True );
     230                 :        226 :     Any aAny;
     231                 :        226 :     OUString sTmp;
     232                 :        226 :     XMLFontFamilyNamePropHdl aFamilyNameHdl;
     233                 :        226 :     XMLFontFamilyPropHdl aFamilyHdl;
     234                 :        226 :     XMLFontPitchPropHdl aPitchHdl;
     235                 :        226 :     XMLFontEncodingPropHdl aEncHdl;
     236                 :        226 :     const SvXMLUnitConverter& rUnitConv = GetExport().GetMM100UnitConverter();
     237                 :            : 
     238                 :        226 :     sal_uInt32 nCount = pPool->size();
     239         [ +  + ]:        496 :     for( sal_uInt32 i=0; i<nCount; i++ )
     240                 :            :     {
     241         [ +  - ]:        270 :         const XMLFontAutoStylePoolEntry_Impl *pEntry = (*pPool)[ i ];
     242                 :            : 
     243                 :        270 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     244         [ +  - ]:        540 :                                   XML_NAME, pEntry->GetName() );
     245                 :            : 
     246         [ +  - ]:        270 :         aAny <<= pEntry->GetFamilyName();
     247 [ +  - ][ +  - ]:        270 :         if( aFamilyNameHdl.exportXML( sTmp, aAny, rUnitConv ) )
     248                 :        270 :             GetExport().AddAttribute( XML_NAMESPACE_SVG,
     249         [ +  - ]:        270 :                                       XML_FONT_FAMILY, sTmp );
     250                 :            : 
     251                 :        270 :         const OUString& rStyleName = pEntry->GetStyleName();
     252         [ -  + ]:        270 :         if( !rStyleName.isEmpty() )
     253                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     254                 :            :                                       XML_FONT_ADORNMENTS,
     255         [ #  # ]:          0 :                                       rStyleName );
     256                 :            : 
     257         [ +  - ]:        270 :         aAny <<= (sal_Int16)pEntry->GetFamily();
     258 [ +  - ][ +  + ]:        270 :         if( aFamilyHdl.exportXML( sTmp, aAny, rUnitConv  ) )
     259                 :        238 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     260         [ +  - ]:        238 :                                       XML_FONT_FAMILY_GENERIC, sTmp );
     261                 :            : 
     262         [ +  - ]:        270 :         aAny <<= (sal_Int16)pEntry->GetPitch();
     263 [ +  - ][ +  + ]:        270 :         if( aPitchHdl.exportXML( sTmp, aAny, rUnitConv  ) )
     264                 :        226 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     265         [ +  - ]:        226 :                                       XML_FONT_PITCH, sTmp );
     266                 :            : 
     267         [ +  - ]:        270 :         aAny <<= (sal_Int16)pEntry->GetEncoding();
     268 [ +  - ][ -  + ]:        270 :         if( aEncHdl.exportXML( sTmp, aAny, rUnitConv  ) )
     269                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     270         [ #  # ]:          0 :                                       XML_FONT_CHARSET, sTmp );
     271                 :            : 
     272                 :        270 :         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
     273                 :            :                                   XML_FONT_FACE,
     274         [ +  - ]:        270 :                                   sal_True, sal_True );
     275 [ +  - ][ +  - ]:        496 :     }
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     276                 :        226 : }
     277                 :            : 
     278                 :            : 
     279                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10