LCOV - code coverage report
Current view: top level - vcl/source/gdi - font.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 422 540 78.1 %
Date: 2012-08-25 Functions: 76 81 93.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 250 546 45.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 "unotools/fontcfg.hxx"
      31                 :            : 
      32                 :            : #include "tools/stream.hxx"
      33                 :            : #include "tools/vcompat.hxx"
      34                 :            : #include "tools/debug.hxx"
      35                 :            : 
      36                 :            : #include "vcl/font.hxx"
      37                 :            : 
      38                 :            : #include "impfont.hxx"
      39                 :            : #include "outfont.hxx"
      40                 :            : #include "sft.hxx"
      41                 :            : 
      42                 :            : #include <sal/macros.h>
      43                 :            : 
      44                 :            : #include <algorithm>
      45                 :            : 
      46                 :            : using namespace vcl;
      47                 :            : 
      48                 :            : // =======================================================================
      49                 :            : 
      50                 :            : DBG_NAME( Font )
      51                 :            : 
      52                 :            : // -----------------------------------------------------------------------
      53                 :            : 
      54                 :      57401 : Impl_Font::Impl_Font() :
      55                 :            :     maColor( COL_TRANSPARENT ),
      56         [ +  - ]:      57401 :     maFillColor( COL_TRANSPARENT )
      57                 :            : {
      58                 :      57401 :     mnRefCount          = 1;
      59                 :      57401 :     meCharSet           = RTL_TEXTENCODING_DONTKNOW;
      60                 :      57401 :     meLanguage          = LANGUAGE_DONTKNOW;
      61                 :      57401 :     meCJKLanguage       = LANGUAGE_DONTKNOW;
      62                 :      57401 :     meFamily            = FAMILY_DONTKNOW;
      63                 :      57401 :     mePitch             = PITCH_DONTKNOW;
      64                 :      57401 :     meAlign             = ALIGN_TOP;
      65                 :      57401 :     meWeight            = WEIGHT_DONTKNOW;
      66                 :      57401 :     meWidthType         = WIDTH_DONTKNOW;
      67                 :      57401 :     meItalic            = ITALIC_NONE;
      68                 :      57401 :     meUnderline         = UNDERLINE_NONE;
      69                 :      57401 :     meOverline          = UNDERLINE_NONE;
      70                 :      57401 :     meStrikeout         = STRIKEOUT_NONE;
      71                 :      57401 :     meRelief            = RELIEF_NONE;
      72                 :      57401 :     meEmphasisMark      = EMPHASISMARK_NONE;
      73                 :      57401 :     mnOrientation       = 0;
      74                 :      57401 :     mnKerning           = 0;
      75                 :      57401 :     mbWordLine          = false;
      76                 :      57401 :     mbOutline           = false;
      77                 :      57401 :     mbShadow            = false;
      78                 :      57401 :     mbVertical          = false;
      79                 :      57401 :     mbTransparent       = true;
      80                 :      57401 :     mbConfigLookup      = false;
      81                 :      57401 : }
      82                 :            : 
      83                 :            : // -----------------------------------------------------------------------
      84                 :            : 
      85                 :    2722005 : Impl_Font::Impl_Font( const Impl_Font& rImplFont )
      86                 :            : :   maFamilyName( rImplFont.maFamilyName ),
      87                 :            :     maStyleName( rImplFont.maStyleName ),
      88                 :            :     maSize( rImplFont.maSize ),
      89                 :            :     maColor( rImplFont.maColor ),
      90         [ +  - ]:    2722005 :     maFillColor( rImplFont.maFillColor )
      91                 :            : {
      92                 :    2722005 :     mnRefCount          = 1;
      93                 :    2722005 :     meCharSet           = rImplFont.meCharSet;
      94                 :    2722005 :     meLanguage          = rImplFont.meLanguage;
      95                 :    2722005 :     meCJKLanguage       = rImplFont.meCJKLanguage;
      96                 :    2722005 :     meFamily            = rImplFont.meFamily;
      97                 :    2722005 :     mePitch             = rImplFont.mePitch;
      98                 :    2722005 :     meAlign             = rImplFont.meAlign;
      99                 :    2722005 :     meWeight            = rImplFont.meWeight;
     100                 :    2722005 :     meWidthType         = rImplFont.meWidthType;
     101                 :    2722005 :     meItalic            = rImplFont.meItalic;
     102                 :    2722005 :     meUnderline         = rImplFont.meUnderline;
     103                 :    2722005 :     meOverline          = rImplFont.meOverline;
     104                 :    2722005 :     meStrikeout         = rImplFont.meStrikeout;
     105                 :    2722005 :     meRelief            = rImplFont.meRelief;
     106                 :    2722005 :     meEmphasisMark      = rImplFont.meEmphasisMark;
     107                 :    2722005 :     mnOrientation       = rImplFont.mnOrientation;
     108                 :    2722005 :     mnKerning           = rImplFont.mnKerning;
     109                 :    2722005 :     mbWordLine          = rImplFont.mbWordLine;
     110                 :    2722005 :     mbOutline           = rImplFont.mbOutline;
     111                 :    2722005 :     mbShadow            = rImplFont.mbShadow;
     112                 :    2722005 :     mbVertical          = rImplFont.mbVertical;
     113                 :    2722005 :     mbTransparent       = rImplFont.mbTransparent;
     114                 :    2722005 :     mbConfigLookup      = rImplFont.mbConfigLookup;
     115                 :    2722005 : }
     116                 :            : 
     117                 :            : // -----------------------------------------------------------------------
     118                 :            : 
     119                 :     609441 : bool Impl_Font::operator==( const Impl_Font& rOther ) const
     120                 :            : {
     121                 :            :     // equality tests split up for easier debugging
     122 [ +  + ][ +  + ]:     609441 :     if( (meWeight   != rOther.meWeight)
         [ +  + ][ +  + ]
     123                 :            :     ||  (meItalic   != rOther.meItalic)
     124                 :            :     ||  (meFamily   != rOther.meFamily)
     125                 :            :     ||  (mePitch    != rOther.mePitch) )
     126                 :     163807 :         return false;
     127                 :            : 
     128 [ +  + ][ +  + ]:     445634 :     if( (meCharSet     != rOther.meCharSet)
         [ +  + ][ +  + ]
     129                 :            :     ||  (meLanguage    != rOther.meLanguage)
     130                 :            :     ||  (meCJKLanguage != rOther.meCJKLanguage)
     131                 :            :     ||  (meAlign       != rOther.meAlign) )
     132                 :       9090 :         return false;
     133                 :            : 
     134 [ +  + ][ +  + ]:     436544 :     if( (maSize         != rOther.maSize)
         [ -  + ][ +  + ]
     135                 :            :     ||  (mnOrientation  != rOther.mnOrientation)
     136                 :            :     ||  (mbVertical     != rOther.mbVertical) )
     137                 :      35687 :         return false;
     138                 :            : 
     139   [ +  +  +  + ]:     801366 :     if( (maFamilyName   != rOther.maFamilyName)
                 [ +  + ]
     140                 :     400509 :     ||  (maStyleName    != rOther.maStyleName) )
     141                 :        495 :         return false;
     142                 :            : 
     143   [ +  +  +  + ]:     800047 :     if( (maColor        != rOther.maColor)
                 [ +  + ]
     144                 :     399685 :     ||  (maFillColor    != rOther.maFillColor) )
     145                 :        769 :         return false;
     146                 :            : 
     147 [ +  + ][ +  + ]:     399593 :     if( (meUnderline    != rOther.meUnderline)
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ -  + ]
     148                 :            :     ||  (meOverline     != rOther.meOverline)
     149                 :            :     ||  (meStrikeout    != rOther.meStrikeout)
     150                 :            :     ||  (meRelief       != rOther.meRelief)
     151                 :            :     ||  (meEmphasisMark != rOther.meEmphasisMark)
     152                 :            :     ||  (mbWordLine     != rOther.mbWordLine)
     153                 :            :     ||  (mbOutline      != rOther.mbOutline)
     154                 :            :     ||  (mbShadow       != rOther.mbShadow)
     155                 :            :     ||  (mnKerning      != rOther.mnKerning)
     156                 :            :     ||  (mbTransparent  != rOther.mbTransparent) )
     157                 :       5112 :         return false;
     158                 :            : 
     159                 :     609441 :     return true;
     160                 :            : }
     161                 :            : 
     162                 :            : // -----------------------------------------------------------------------
     163                 :            : 
     164                 :      39824 : void Impl_Font::AskConfig()
     165                 :            : {
     166         [ +  + ]:      39824 :     if( mbConfigLookup )
     167                 :      39824 :         return;
     168                 :            : 
     169                 :      15160 :     mbConfigLookup = true;
     170                 :            : 
     171                 :            :     // prepare the FontSubst configuration lookup
     172         [ +  - ]:      15160 :     const utl::FontSubstConfiguration& rFontSubst = utl::FontSubstConfiguration::get();
     173                 :            : 
     174         [ +  - ]:      15160 :     String      aShortName;
     175         [ +  - ]:      15160 :     String      aFamilyName;
     176                 :      15160 :     sal_uLong       nType = 0;
     177                 :      15160 :     FontWeight  eWeight = WEIGHT_DONTKNOW;
     178                 :      15160 :     FontWidth   eWidthType = WIDTH_DONTKNOW;
     179         [ +  - ]:      15160 :     String      aMapName = maFamilyName;
     180         [ +  - ]:      15160 :     GetEnglishSearchFontName( aMapName );
     181                 :            :     utl::FontSubstConfiguration::getMapName( aMapName,
     182         [ +  - ]:      15160 :         aShortName, aFamilyName, eWeight, eWidthType, nType );
     183                 :            : 
     184                 :            :     // lookup the font name in the configuration
     185 [ +  - ][ +  - ]:      15160 :     const utl::FontNameAttr* pFontAttr = rFontSubst.getSubstInfo( aMapName );
     186                 :            : 
     187                 :            :     // if the direct lookup failed try again with an alias name
     188 [ +  - ][ +  + ]:      15160 :     if ( !pFontAttr && (aShortName != aMapName) )
         [ +  + ][ +  + ]
     189 [ +  - ][ +  - ]:        612 :         pFontAttr = rFontSubst.getSubstInfo( aShortName );
     190                 :            : 
     191         [ +  + ]:      15160 :     if( pFontAttr )
     192                 :            :     {
     193                 :            :         // the font was found in the configuration
     194         [ +  + ]:       8366 :         if( meFamily == FAMILY_DONTKNOW )
     195                 :            :         {
     196         [ +  + ]:       6752 :             if ( pFontAttr->Type & IMPL_FONT_ATTR_SERIF )
     197                 :       2480 :                 meFamily = FAMILY_ROMAN;
     198         [ +  + ]:       4272 :             else if ( pFontAttr->Type & IMPL_FONT_ATTR_SANSSERIF )
     199                 :        642 :                 meFamily = FAMILY_SWISS;
     200         [ +  + ]:       3630 :             else if ( pFontAttr->Type & IMPL_FONT_ATTR_TYPEWRITER )
     201                 :         15 :                 meFamily = FAMILY_MODERN;
     202         [ -  + ]:       3615 :             else if ( pFontAttr->Type & IMPL_FONT_ATTR_ITALIC )
     203                 :          0 :                 meFamily = FAMILY_SCRIPT;
     204         [ -  + ]:       3615 :             else if ( pFontAttr->Type & IMPL_FONT_ATTR_DECORATIVE )
     205                 :          0 :                 meFamily = FAMILY_DECORATIVE;
     206                 :            :         }
     207                 :            : 
     208         [ +  - ]:       8366 :         if( mePitch == PITCH_DONTKNOW )
     209                 :            :         {
     210         [ +  + ]:       8366 :             if ( pFontAttr->Type & IMPL_FONT_ATTR_FIXED )
     211                 :         15 :                 mePitch = PITCH_FIXED;
     212                 :            :         }
     213                 :            :     }
     214                 :            : 
     215                 :            :     // if some attributes are still unknown then use the FontSubst magic
     216         [ +  + ]:      15160 :     if( meFamily == FAMILY_DONTKNOW )
     217                 :            :     {
     218         [ +  + ]:      10006 :         if( nType & IMPL_FONT_ATTR_SERIF )
     219                 :         10 :             meFamily = FAMILY_ROMAN;
     220         [ +  + ]:       9996 :         else if( nType & IMPL_FONT_ATTR_SANSSERIF )
     221                 :          4 :             meFamily = FAMILY_SWISS;
     222         [ -  + ]:       9992 :         else if( nType & IMPL_FONT_ATTR_TYPEWRITER )
     223                 :          0 :             meFamily = FAMILY_MODERN;
     224         [ -  + ]:       9992 :         else if( nType & IMPL_FONT_ATTR_ITALIC )
     225                 :          0 :             meFamily = FAMILY_SCRIPT;
     226         [ -  + ]:       9992 :         else if( nType & IMPL_FONT_ATTR_DECORATIVE )
     227                 :          0 :             meFamily = FAMILY_DECORATIVE;
     228                 :            :     }
     229                 :            : 
     230         [ +  + ]:      15160 :     if( meWeight == WEIGHT_DONTKNOW )
     231                 :      12162 :         meWeight = eWeight;
     232         [ +  - ]:      15160 :     if( meWidthType == WIDTH_DONTKNOW )
     233 [ +  - ][ +  - ]:      39824 :         meWidthType = eWidthType;
                 [ +  - ]
     234                 :            : }
     235                 :            : 
     236                 :            : // =======================================================================
     237                 :            : 
     238                 :   10348836 : void Font::MakeUnique()
     239                 :            : {
     240                 :            :     // create a copy if others still reference it
     241         [ +  + ]:   10348836 :     if ( mpImplFont->mnRefCount != 1 )
     242                 :            :     {
     243         [ +  + ]:    2722005 :         if ( mpImplFont->mnRefCount )
     244                 :    1917951 :             mpImplFont->mnRefCount--;
     245         [ +  - ]:    2722005 :         mpImplFont = new Impl_Font( *mpImplFont );
     246                 :            :     }
     247                 :   10348836 : }
     248                 :            : 
     249                 :            : // -----------------------------------------------------------------------
     250                 :            : 
     251                 :    2836987 : Font::Font()
     252                 :            : {
     253                 :            :     DBG_CTOR( Font, NULL );
     254                 :            : 
     255 [ +  + ][ +  - ]:    2836987 :     static Impl_Font aStaticImplFont;
         [ +  - ][ #  # ]
     256                 :            :     // RefCount is zero for static objects
     257                 :    2836987 :     aStaticImplFont.mnRefCount = 0;
     258                 :    2836987 :     mpImplFont = &aStaticImplFont;
     259                 :    2836987 : }
     260                 :            : 
     261                 :            : // -----------------------------------------------------------------------
     262                 :            : 
     263                 :    3914314 : Font::Font( const Font& rFont )
     264                 :            : {
     265                 :            :     DBG_CTOR( Font, NULL );
     266                 :            :     DBG_CHKOBJ( &rFont, Font, NULL );
     267                 :            :     DBG_ASSERT( rFont.mpImplFont->mnRefCount < 0xFFFE, "Font: RefCount overflow" );
     268                 :            : 
     269                 :    3914314 :     mpImplFont = rFont.mpImplFont;
     270                 :            :     // do not count static objects (where RefCount is zero)
     271         [ +  + ]:    3914314 :     if ( mpImplFont->mnRefCount )
     272                 :    3873989 :         mpImplFont->mnRefCount++;
     273                 :    3914314 : }
     274                 :            : 
     275                 :            : // -----------------------------------------------------------------------
     276                 :            : 
     277                 :      15682 : Font::Font( const String& rFamilyName, const Size& rSize )
     278                 :            : {
     279                 :            :     DBG_CTOR( Font, NULL );
     280                 :            : 
     281         [ +  - ]:      15682 :     mpImplFont              = new Impl_Font;
     282                 :      15682 :     mpImplFont->maFamilyName= rFamilyName;
     283                 :      15682 :     mpImplFont->maSize      = rSize;
     284                 :      15682 : }
     285                 :            : 
     286                 :            : // -----------------------------------------------------------------------
     287                 :            : 
     288                 :      41059 : Font::Font( const String& rFamilyName, const String& rStyleName, const Size& rSize )
     289                 :            : {
     290                 :            :     DBG_CTOR( Font, NULL );
     291                 :            : 
     292         [ +  - ]:      41059 :     mpImplFont              = new Impl_Font;
     293                 :      41059 :     mpImplFont->maFamilyName= rFamilyName;
     294                 :      41059 :     mpImplFont->maStyleName = rStyleName;
     295                 :      41059 :     mpImplFont->maSize      = rSize;
     296                 :      41059 : }
     297                 :            : 
     298                 :            : // -----------------------------------------------------------------------
     299                 :            : 
     300                 :        409 : Font::Font( FontFamily eFamily, const Size& rSize )
     301                 :            : {
     302                 :            :     DBG_CTOR( Font, NULL );
     303                 :            : 
     304         [ +  - ]:        409 :     mpImplFont              = new Impl_Font;
     305                 :        409 :     mpImplFont->meFamily    = eFamily;
     306                 :        409 :     mpImplFont->maSize      = rSize;
     307                 :        409 : }
     308                 :            : 
     309                 :            : // -----------------------------------------------------------------------
     310                 :            : 
     311                 :    6778433 : Font::~Font()
     312                 :            : {
     313                 :            :     DBG_DTOR( Font, NULL );
     314                 :            : 
     315                 :            :     // decrement reference counter and delete if last reference
     316                 :            :     // if the object is not static (Refcounter==0)
     317         [ +  + ]:    6778433 :     if ( mpImplFont->mnRefCount )
     318                 :            :     {
     319         [ +  + ]:    6599804 :         if ( mpImplFont->mnRefCount == 1 )
     320         [ +  - ]:    1867401 :             delete mpImplFont;
     321                 :            :         else
     322                 :    4732403 :             mpImplFont->mnRefCount--;
     323                 :            :     }
     324                 :    6778433 : }
     325                 :            : 
     326                 :            : // -----------------------------------------------------------------------
     327                 :            : 
     328                 :     721726 : void Font::SetColor( const Color& rColor )
     329                 :            : {
     330                 :            :     DBG_CHKTHIS( Font, NULL );
     331                 :            : 
     332         [ +  + ]:     721726 :     if( mpImplFont->maColor != rColor )
     333                 :            :     {
     334                 :     150321 :         MakeUnique();
     335                 :     150321 :         mpImplFont->maColor = rColor;
     336                 :            :     }
     337                 :     721726 : }
     338                 :            : 
     339                 :            : // -----------------------------------------------------------------------
     340                 :            : 
     341                 :      17842 : void Font::SetFillColor( const Color& rColor )
     342                 :            : {
     343                 :            :     DBG_CHKTHIS( Font, NULL );
     344                 :            : 
     345                 :      17842 :     MakeUnique();
     346                 :      17842 :     mpImplFont->maFillColor = rColor;
     347         [ +  + ]:      17842 :     if ( rColor.GetTransparency() )
     348                 :       3483 :         mpImplFont->mbTransparent = true;
     349                 :      17842 : }
     350                 :            : 
     351                 :            : // -----------------------------------------------------------------------
     352                 :            : 
     353                 :     694377 : void Font::SetTransparent( sal_Bool bTransparent )
     354                 :            : {
     355                 :            :     DBG_CHKTHIS( Font, NULL );
     356                 :            : 
     357         [ +  + ]:     694377 :     if( mpImplFont->mbTransparent != bTransparent )
     358                 :            :     {
     359                 :      13683 :         MakeUnique();
     360                 :      13683 :         mpImplFont->mbTransparent = bTransparent;
     361                 :            :     }
     362                 :     694377 : }
     363                 :            : 
     364                 :            : // -----------------------------------------------------------------------
     365                 :            : 
     366                 :     756307 : void Font::SetAlign( FontAlign eAlign )
     367                 :            : {
     368                 :            :     DBG_CHKTHIS( Font, NULL );
     369                 :            : 
     370         [ +  + ]:     756307 :     if( mpImplFont->meAlign != eAlign )
     371                 :            :     {
     372                 :     163542 :         MakeUnique();
     373                 :     163542 :         mpImplFont->meAlign = eAlign;
     374                 :            :     }
     375                 :     756307 : }
     376                 :            : 
     377                 :            : // -----------------------------------------------------------------------
     378                 :            : 
     379                 :    1841282 : void Font::SetName( const rtl::OUString& rFamilyName )
     380                 :            : {
     381                 :            :     DBG_CHKTHIS( Font, NULL );
     382                 :            : 
     383                 :    1841282 :     MakeUnique();
     384                 :    1841282 :     mpImplFont->maFamilyName = rFamilyName;
     385                 :    1841282 : }
     386                 :            : 
     387                 :            : // -----------------------------------------------------------------------
     388                 :            : 
     389                 :    1081495 : void Font::SetStyleName( const String& rStyleName )
     390                 :            : {
     391                 :            :     DBG_CHKTHIS( Font, NULL );
     392                 :            : 
     393                 :    1081495 :     MakeUnique();
     394                 :    1081495 :     mpImplFont->maStyleName = rStyleName;
     395                 :    1081495 : }
     396                 :            : 
     397                 :            : // -----------------------------------------------------------------------
     398                 :            : 
     399                 :    1532593 : void Font::SetSize( const Size& rSize )
     400                 :            : {
     401                 :            :     DBG_CHKTHIS( Font, NULL );
     402                 :            : 
     403         [ +  + ]:    1532593 :     if( mpImplFont->maSize != rSize )
     404                 :            :     {
     405                 :    1104606 :         MakeUnique();
     406                 :    1104606 :         mpImplFont->maSize = rSize;
     407                 :            :     }
     408                 :    1532593 : }
     409                 :            : 
     410                 :            : // -----------------------------------------------------------------------
     411                 :            : 
     412                 :    1743656 : void Font::SetFamily( FontFamily eFamily )
     413                 :            : {
     414                 :            :     DBG_CHKTHIS( Font, NULL );
     415                 :            : 
     416         [ +  + ]:    1743656 :     if( mpImplFont->meFamily != eFamily )
     417                 :            :     {
     418                 :     688311 :         MakeUnique();
     419                 :     688311 :         mpImplFont->meFamily = eFamily;
     420                 :            :     }
     421                 :    1743656 : }
     422                 :            : 
     423                 :            : // -----------------------------------------------------------------------
     424                 :            : 
     425                 :    1787653 : void Font::SetCharSet( CharSet eCharSet )
     426                 :            : {
     427                 :            :     DBG_CHKTHIS( Font, NULL );
     428                 :            : 
     429         [ +  + ]:    1787653 :     if( mpImplFont->meCharSet != eCharSet )
     430                 :            :     {
     431                 :    1260925 :         MakeUnique();
     432                 :    1260925 :         mpImplFont->meCharSet = eCharSet;
     433                 :            :     }
     434                 :    1787653 : }
     435                 :            : 
     436                 :            : // -----------------------------------------------------------------------
     437                 :            : 
     438                 :    1891005 : void Font::SetLanguage( LanguageType eLanguage )
     439                 :            : {
     440                 :            :     DBG_CHKTHIS( Font, NULL );
     441                 :            : 
     442         [ +  + ]:    1891005 :     if( mpImplFont->meLanguage != eLanguage )
     443                 :            :     {
     444                 :     302188 :         MakeUnique();
     445                 :     302188 :         mpImplFont->meLanguage = eLanguage;
     446                 :            :     }
     447                 :    1891005 : }
     448                 :            : 
     449                 :            : // -----------------------------------------------------------------------
     450                 :            : 
     451                 :     688277 : void Font::SetCJKContextLanguage( LanguageType eLanguage )
     452                 :            : {
     453                 :            :     DBG_CHKTHIS( Font, NULL );
     454                 :            : 
     455         [ +  + ]:     688277 :     if( mpImplFont->meCJKLanguage != eLanguage )
     456                 :            :     {
     457                 :     536760 :         MakeUnique();
     458                 :     536760 :         mpImplFont->meCJKLanguage = eLanguage;
     459                 :            :     }
     460                 :     688277 : }
     461                 :            : 
     462                 :            : // -----------------------------------------------------------------------
     463                 :            : 
     464                 :    1784920 : void Font::SetPitch( FontPitch ePitch )
     465                 :            : {
     466                 :            :     DBG_CHKTHIS( Font, NULL );
     467                 :            : 
     468         [ +  + ]:    1784920 :     if( mpImplFont->mePitch != ePitch )
     469                 :            :     {
     470                 :     853885 :         MakeUnique();
     471                 :     853885 :         mpImplFont->mePitch = ePitch;
     472                 :            :     }
     473                 :    1784920 : }
     474                 :            : 
     475                 :            : // -----------------------------------------------------------------------
     476                 :            : 
     477                 :     703497 : void Font::SetOrientation( short nOrientation )
     478                 :            : {
     479                 :            :     DBG_CHKTHIS( Font, NULL );
     480                 :            : 
     481         [ +  + ]:     703497 :     if( mpImplFont->mnOrientation != nOrientation )
     482                 :            :     {
     483                 :      17866 :         MakeUnique();
     484                 :      17866 :         mpImplFont->mnOrientation = nOrientation;
     485                 :            :     }
     486                 :     703497 : }
     487                 :            : 
     488                 :            : // -----------------------------------------------------------------------
     489                 :            : 
     490                 :     224065 : void Font::SetVertical( sal_Bool bVertical )
     491                 :            : {
     492                 :            :     DBG_CHKTHIS( Font, NULL );
     493                 :            : 
     494         [ -  + ]:     224065 :     if( mpImplFont->mbVertical != bVertical )
     495                 :            :     {
     496                 :          0 :         MakeUnique();
     497                 :          0 :         mpImplFont->mbVertical = bVertical;
     498                 :            :     }
     499                 :     224065 : }
     500                 :            : 
     501                 :            : // -----------------------------------------------------------------------
     502                 :            : 
     503                 :     636879 : void Font::SetKerning( FontKerning nKerning )
     504                 :            : {
     505                 :            :     DBG_CHKTHIS( Font, NULL );
     506                 :            : 
     507         [ +  + ]:     636879 :     if( mpImplFont->mnKerning != nKerning )
     508                 :            :     {
     509                 :      58833 :         MakeUnique();
     510                 :      58833 :         mpImplFont->mnKerning = nKerning;
     511                 :            :     }
     512                 :     636879 : }
     513                 :            : 
     514                 :            : // -----------------------------------------------------------------------
     515                 :            : 
     516                 :       7965 : sal_Bool Font::IsKerning() const
     517                 :            : {
     518                 :       7965 :     return (mpImplFont->mnKerning & KERNING_FONTSPECIFIC) != 0;
     519                 :            : }
     520                 :            : 
     521                 :            : // -----------------------------------------------------------------------
     522                 :            : 
     523                 :    1822107 : void Font::SetWeight( FontWeight eWeight )
     524                 :            : {
     525                 :            :     DBG_CHKTHIS( Font, NULL );
     526                 :            : 
     527         [ +  + ]:    1822107 :     if( mpImplFont->meWeight != eWeight )
     528                 :            :     {
     529                 :     833388 :         MakeUnique();
     530                 :     833388 :         mpImplFont->meWeight = eWeight;
     531                 :            :     }
     532                 :    1822107 : }
     533                 :            : 
     534                 :            : // -----------------------------------------------------------------------
     535                 :            : 
     536                 :    1045720 : void Font::SetWidthType( FontWidth eWidth )
     537                 :            : {
     538                 :            :     DBG_CHKTHIS( Font, NULL );
     539                 :            : 
     540         [ +  + ]:    1045720 :     if( mpImplFont->meWidthType != eWidth )
     541                 :            :     {
     542                 :     893034 :         MakeUnique();
     543                 :     893034 :         mpImplFont->meWidthType = eWidth;
     544                 :            :     }
     545                 :    1045720 : }
     546                 :            : 
     547                 :            : // -----------------------------------------------------------------------
     548                 :            : 
     549                 :    1726577 : void Font::SetItalic( FontItalic eItalic )
     550                 :            : {
     551                 :            :     DBG_CHKTHIS( Font, NULL );
     552                 :            : 
     553         [ +  + ]:    1726577 :     if( mpImplFont->meItalic != eItalic )
     554                 :            :     {
     555                 :     229226 :         MakeUnique();
     556                 :     229226 :         mpImplFont->meItalic = eItalic;
     557                 :            :     }
     558                 :    1726577 : }
     559                 :            : 
     560                 :            : // -----------------------------------------------------------------------
     561                 :            : 
     562                 :     641261 : void Font::SetOutline( sal_Bool bOutline )
     563                 :            : {
     564                 :            :     DBG_CHKTHIS( Font, NULL );
     565                 :            : 
     566         [ +  + ]:     641261 :     if( mpImplFont->mbOutline != bOutline )
     567                 :            :     {
     568                 :      20611 :         MakeUnique();
     569                 :      20611 :         mpImplFont->mbOutline = bOutline;
     570                 :            :     }
     571                 :     641261 : }
     572                 :            : 
     573                 :            : // -----------------------------------------------------------------------
     574                 :            : 
     575                 :     602027 : void Font::SetShadow( sal_Bool bShadow )
     576                 :            : {
     577                 :            :     DBG_CHKTHIS( Font, NULL );
     578                 :            : 
     579         [ +  + ]:     602027 :     if( mpImplFont->mbShadow != bShadow )
     580                 :            :     {
     581                 :      19013 :         MakeUnique();
     582                 :      19013 :         mpImplFont->mbShadow = bShadow;
     583                 :            :     }
     584                 :     602027 : }
     585                 :            : 
     586                 :            : // -----------------------------------------------------------------------
     587                 :            : 
     588                 :     615537 : void Font::SetUnderline( FontUnderline eUnderline )
     589                 :            : {
     590                 :            :     DBG_CHKTHIS( Font, NULL );
     591                 :            : 
     592         [ +  + ]:     615537 :     if( mpImplFont->meUnderline != eUnderline )
     593                 :            :     {
     594                 :      48265 :         MakeUnique();
     595                 :      48265 :         mpImplFont->meUnderline = eUnderline;
     596                 :            :     }
     597                 :     615537 : }
     598                 :            : 
     599                 :            : // -----------------------------------------------------------------------
     600                 :            : 
     601                 :     594540 : void Font::SetOverline( FontUnderline eOverline )
     602                 :            : {
     603                 :            :     DBG_CHKTHIS( Font, NULL );
     604                 :            : 
     605         [ +  + ]:     594540 :     if( mpImplFont->meOverline != eOverline )
     606                 :            :     {
     607                 :      19758 :         MakeUnique();
     608                 :      19758 :         mpImplFont->meOverline = eOverline;
     609                 :            :     }
     610                 :     594540 : }
     611                 :            : 
     612                 :            : // -----------------------------------------------------------------------
     613                 :            : 
     614                 :     606634 : void Font::SetStrikeout( FontStrikeout eStrikeout )
     615                 :            : {
     616                 :            :     DBG_CHKTHIS( Font, NULL );
     617                 :            : 
     618         [ +  + ]:     606634 :     if( mpImplFont->meStrikeout != eStrikeout )
     619                 :            :     {
     620                 :      31747 :         MakeUnique();
     621                 :      31747 :         mpImplFont->meStrikeout = eStrikeout;
     622                 :            :     }
     623                 :     606634 : }
     624                 :            : 
     625                 :            : // -----------------------------------------------------------------------
     626                 :            : 
     627                 :     578633 : void Font::SetRelief( FontRelief eRelief )
     628                 :            : {
     629                 :            :     DBG_CHKTHIS( Font, NULL );
     630                 :            : 
     631         [ +  + ]:     578633 :     if( mpImplFont->meRelief != eRelief )
     632                 :            :     {
     633                 :      33628 :         MakeUnique();
     634                 :      33628 :         mpImplFont->meRelief = eRelief;
     635                 :            :     }
     636                 :     578633 : }
     637                 :            : 
     638                 :            : // -----------------------------------------------------------------------
     639                 :            : 
     640                 :     601234 : void Font::SetEmphasisMark( FontEmphasisMark eEmphasisMark )
     641                 :            : {
     642                 :            :     DBG_CHKTHIS( Font, NULL );
     643                 :            : 
     644         [ +  + ]:     601234 :     if( mpImplFont->meEmphasisMark != eEmphasisMark )
     645                 :            :     {
     646                 :      35626 :         MakeUnique();
     647                 :      35626 :         mpImplFont->meEmphasisMark = eEmphasisMark;
     648                 :            :     }
     649                 :     601234 : }
     650                 :            : 
     651                 :            : // -----------------------------------------------------------------------
     652                 :            : 
     653                 :     620062 : void Font::SetWordLineMode( sal_Bool bWordLine )
     654                 :            : {
     655                 :            :     DBG_CHKTHIS( Font, NULL );
     656                 :            : 
     657         [ +  + ]:     620062 :     if( mpImplFont->mbWordLine != bWordLine )
     658                 :            :     {
     659                 :      23478 :         MakeUnique();
     660                 :      23478 :         mpImplFont->mbWordLine = bWordLine;
     661                 :            :     }
     662                 :     620062 : }
     663                 :            : 
     664                 :            : // -----------------------------------------------------------------------
     665                 :            : 
     666                 :    3940123 : Font& Font::operator=( const Font& rFont )
     667                 :            : {
     668                 :            :     DBG_CHKTHIS( Font, NULL );
     669                 :            :     DBG_CHKOBJ( &rFont, Font, NULL );
     670                 :            :     DBG_ASSERT( rFont.mpImplFont->mnRefCount < 0xFFFE, "Font: RefCount overflow" );
     671                 :            : 
     672                 :            :     // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann
     673                 :            :     // RefCount == 0 fuer statische Objekte
     674         [ +  + ]:    3940123 :     if ( rFont.mpImplFont->mnRefCount )
     675                 :    3934007 :         rFont.mpImplFont->mnRefCount++;
     676                 :            : 
     677                 :            :     // Wenn es keine statischen ImplDaten sind, dann loeschen, wenn es
     678                 :            :     // die letzte Referenz ist, sonst Referenzcounter decrementieren
     679         [ +  + ]:    3940123 :     if ( mpImplFont->mnRefCount )
     680                 :            :     {
     681         [ +  + ]:    2043246 :         if ( mpImplFont->mnRefCount == 1 )
     682         [ +  - ]:     890107 :             delete mpImplFont;
     683                 :            :         else
     684                 :    1153139 :             mpImplFont->mnRefCount--;
     685                 :            :     }
     686                 :            : 
     687                 :    3940123 :     mpImplFont = rFont.mpImplFont;
     688                 :            : 
     689                 :    3940123 :     return *this;
     690                 :            : }
     691                 :            : 
     692                 :            : // -----------------------------------------------------------------------
     693                 :            : 
     694                 :    1174566 : sal_Bool Font::operator==( const Font& rFont ) const
     695                 :            : {
     696                 :            :     DBG_CHKTHIS( Font, NULL );
     697                 :            :     DBG_CHKOBJ( &rFont, Font, NULL );
     698                 :            : 
     699         [ +  + ]:    1174566 :     if( mpImplFont == rFont.mpImplFont )
     700                 :     565125 :         return sal_True;
     701         [ +  + ]:     609441 :     if( *mpImplFont == *rFont.mpImplFont )
     702                 :     394481 :         return sal_True;
     703                 :            : 
     704                 :    1174566 :     return sal_False;
     705                 :            : }
     706                 :            : 
     707                 :            : // -----------------------------------------------------------------------
     708                 :            : 
     709                 :       7419 : void Font::Merge( const Font& rFont )
     710                 :            : {
     711         [ +  + ]:       7419 :     if ( rFont.GetName().Len() )
     712                 :            :     {
     713         [ +  - ]:       7373 :         SetName( rFont.GetName() );
     714                 :       7373 :         SetStyleName( rFont.GetStyleName() );
     715                 :       7373 :         SetCharSet( GetCharSet() );
     716                 :       7373 :         SetLanguage( rFont.GetLanguage() );
     717                 :       7373 :         SetCJKContextLanguage( rFont.GetCJKContextLanguage() );
     718                 :            :         // don't use access methods here, might lead to AskConfig(), if DONTKNOW
     719                 :       7373 :         SetFamily( rFont.mpImplFont->meFamily );
     720                 :       7373 :         SetPitch( rFont.mpImplFont->mePitch );
     721                 :            :     }
     722                 :            : 
     723                 :            :     // don't use access methods here, might lead to AskConfig(), if DONTKNOW
     724         [ +  + ]:       7419 :     if ( rFont.mpImplFont->meWeight != WEIGHT_DONTKNOW )
     725                 :       7389 :         SetWeight( rFont.GetWeight() );
     726         [ +  - ]:       7419 :     if ( rFont.mpImplFont->meItalic != ITALIC_DONTKNOW )
     727                 :       7419 :         SetItalic( rFont.GetItalic() );
     728         [ +  + ]:       7419 :     if ( rFont.mpImplFont->meWidthType != WIDTH_DONTKNOW )
     729                 :       7313 :         SetWidthType( rFont.GetWidthType() );
     730                 :            : 
     731                 :            : 
     732         [ +  + ]:       7419 :     if ( rFont.GetSize().Height() )
     733                 :       7389 :         SetSize( rFont.GetSize() );
     734         [ +  - ]:       7419 :     if ( rFont.GetUnderline() != UNDERLINE_DONTKNOW )
     735                 :            :     {
     736                 :       7419 :         SetUnderline( rFont.GetUnderline() );
     737                 :       7419 :         SetWordLineMode( rFont.IsWordLineMode() );
     738                 :            :     }
     739         [ +  - ]:       7419 :     if ( rFont.GetOverline() != UNDERLINE_DONTKNOW )
     740                 :            :     {
     741                 :       7419 :         SetOverline( rFont.GetOverline() );
     742                 :       7419 :         SetWordLineMode( rFont.IsWordLineMode() );
     743                 :            :     }
     744         [ +  - ]:       7419 :     if ( rFont.GetStrikeout() != STRIKEOUT_DONTKNOW )
     745                 :            :     {
     746                 :       7419 :         SetStrikeout( rFont.GetStrikeout() );
     747                 :       7419 :         SetWordLineMode( rFont.IsWordLineMode() );
     748                 :            :     }
     749                 :            : 
     750                 :            :     // Defaults?
     751                 :       7419 :     SetOrientation( rFont.GetOrientation() );
     752                 :       7419 :     SetVertical( rFont.IsVertical() );
     753                 :       7419 :     SetEmphasisMark( rFont.GetEmphasisMark() );
     754                 :       7419 :     SetKerning( rFont.IsKerning() );
     755                 :       7419 :     SetOutline( rFont.IsOutline() );
     756                 :       7419 :     SetShadow( rFont.IsShadow() );
     757                 :       7419 :     SetRelief( rFont.GetRelief() );
     758                 :       7419 : }
     759                 :            : 
     760                 :     841765 : void Font::GetFontAttributes( ImplFontAttributes& rAttrs ) const
     761                 :            : {
     762                 :            :     // #i56788# Use members directly, don't risc config access.
     763                 :     841765 :     rAttrs.maName = mpImplFont->maFamilyName;
     764                 :     841765 :     rAttrs.maStyleName = mpImplFont->maStyleName;
     765                 :     841765 :     rAttrs.meFamily = mpImplFont->meFamily;
     766                 :     841765 :     rAttrs.mePitch = mpImplFont->mePitch;
     767                 :     841765 :     rAttrs.meItalic = mpImplFont->meItalic;
     768                 :     841765 :     rAttrs.meWeight = mpImplFont->meWeight;
     769                 :     841765 :     rAttrs.meWidthType = WIDTH_DONTKNOW;
     770                 :     841765 :     rAttrs.mbSymbolFlag= (mpImplFont->meCharSet == RTL_TEXTENCODING_SYMBOL);
     771                 :     841765 : }
     772                 :            : 
     773                 :            : 
     774                 :            : // -----------------------------------------------------------------------
     775                 :            : 
     776                 :      69523 : SvStream& operator>>( SvStream& rIStm, Impl_Font& rImpl_Font )
     777                 :            : {
     778         [ +  - ]:      69523 :     VersionCompat   aCompat( rIStm, STREAM_READ );
     779                 :            :     sal_uInt16          nTmp16;
     780                 :            :     sal_Bool            bTmp;
     781                 :            :     sal_uInt8           nTmp8;
     782                 :            : 
     783 [ +  - ][ +  - ]:      69523 :     rImpl_Font.maFamilyName = rIStm.ReadUniOrByteString(rIStm.GetStreamCharSet());
     784 [ +  - ][ +  - ]:      69523 :     rImpl_Font.maStyleName = rIStm.ReadUniOrByteString(rIStm.GetStreamCharSet());
     785         [ +  - ]:      69523 :     rIStm >> rImpl_Font.maSize;
     786                 :            : 
     787         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meCharSet = (rtl_TextEncoding) nTmp16;
     788         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meFamily = (FontFamily) nTmp16;
     789         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.mePitch = (FontPitch) nTmp16;
     790         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meWeight = (FontWeight) nTmp16;
     791         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meUnderline = (FontUnderline) nTmp16;
     792         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meStrikeout = (FontStrikeout) nTmp16;
     793         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meItalic = (FontItalic) nTmp16;
     794         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meLanguage = (LanguageType) nTmp16;
     795         [ +  - ]:      69523 :     rIStm >> nTmp16; rImpl_Font.meWidthType = (FontWidth) nTmp16;
     796                 :            : 
     797         [ +  - ]:      69523 :     rIStm >> rImpl_Font.mnOrientation;
     798                 :            : 
     799         [ +  - ]:      69523 :     rIStm >> bTmp; rImpl_Font.mbWordLine = bTmp;
     800         [ +  - ]:      69523 :     rIStm >> bTmp; rImpl_Font.mbOutline = bTmp;
     801         [ +  - ]:      69523 :     rIStm >> bTmp; rImpl_Font.mbShadow = bTmp;
     802         [ +  - ]:      69523 :     rIStm >> nTmp8; rImpl_Font.mnKerning = nTmp8;
     803                 :            : 
     804         [ +  - ]:      69523 :     if( aCompat.GetVersion() >= 2 )
     805                 :            :     {
     806         [ +  - ]:      69523 :         rIStm >> nTmp8;     rImpl_Font.meRelief = (FontRelief)nTmp8;
     807         [ +  - ]:      69523 :         rIStm >> nTmp16;    rImpl_Font.meCJKLanguage = (LanguageType)nTmp16;
     808         [ +  - ]:      69523 :         rIStm >> bTmp;      rImpl_Font.mbVertical = bTmp;
     809         [ +  - ]:      69523 :         rIStm >> nTmp16;    rImpl_Font.meEmphasisMark = (FontEmphasisMark)nTmp16;
     810                 :            :     }
     811         [ +  - ]:      69523 :     if( aCompat.GetVersion() >= 3 )
     812                 :            :     {
     813         [ +  - ]:      69523 :         rIStm >> nTmp16; rImpl_Font.meOverline = (FontUnderline) nTmp16;
     814                 :            :     }
     815                 :            :     // Relief
     816                 :            :     // CJKContextLanguage
     817                 :            : 
     818         [ +  - ]:      69523 :     return rIStm;
     819                 :            : }
     820                 :            : 
     821                 :            : // -----------------------------------------------------------------------
     822                 :            : 
     823                 :      79775 : SvStream& operator<<( SvStream& rOStm, const Impl_Font& rImpl_Font )
     824                 :            : {
     825         [ +  - ]:      79775 :     VersionCompat aCompat( rOStm, STREAM_WRITE, 3 );
     826 [ +  - ][ +  - ]:      79775 :     rOStm.WriteUniOrByteString( rImpl_Font.maFamilyName, rOStm.GetStreamCharSet() );
     827 [ +  - ][ +  - ]:      79775 :     rOStm.WriteUniOrByteString( rImpl_Font.maStyleName, rOStm.GetStreamCharSet() );
     828         [ +  - ]:      79775 :     rOStm << rImpl_Font.maSize;
     829                 :            : 
     830         [ +  - ]:      79775 :     rOStm << (sal_uInt16) GetStoreCharSet( rImpl_Font.meCharSet );
     831         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meFamily;
     832         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.mePitch;
     833         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meWeight;
     834         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meUnderline;
     835         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meStrikeout;
     836         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meItalic;
     837         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meLanguage;
     838         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meWidthType;
     839                 :            : 
     840         [ +  - ]:      79775 :     rOStm << rImpl_Font.mnOrientation;
     841                 :            : 
     842         [ +  - ]:      79775 :     rOStm << (sal_Bool) rImpl_Font.mbWordLine;
     843         [ +  - ]:      79775 :     rOStm << (sal_Bool) rImpl_Font.mbOutline;
     844         [ +  - ]:      79775 :     rOStm << (sal_Bool) rImpl_Font.mbShadow;
     845         [ +  - ]:      79775 :     rOStm << (sal_uInt8) rImpl_Font.mnKerning;
     846                 :            : 
     847                 :            :     // new in version 2
     848         [ +  - ]:      79775 :     rOStm << (sal_uInt8)        rImpl_Font.meRelief;
     849         [ +  - ]:      79775 :     rOStm << (sal_uInt16)   rImpl_Font.meCJKLanguage;
     850         [ +  - ]:      79775 :     rOStm << (sal_Bool)     rImpl_Font.mbVertical;
     851         [ +  - ]:      79775 :     rOStm << (sal_uInt16)   rImpl_Font.meEmphasisMark;
     852                 :            : 
     853                 :            :     // new in version 3
     854         [ +  - ]:      79775 :     rOStm << (sal_uInt16) rImpl_Font.meOverline;
     855                 :            : 
     856         [ +  - ]:      79775 :     return rOStm;
     857                 :            : }
     858                 :            : 
     859                 :            : // -----------------------------------------------------------------------
     860                 :            : 
     861                 :      69523 : SvStream& operator>>( SvStream& rIStm, Font& rFont )
     862                 :            : {
     863                 :      69523 :     rFont.MakeUnique();
     864                 :      69523 :     return( rIStm >> *rFont.mpImplFont );
     865                 :            : }
     866                 :            : 
     867                 :            : // -----------------------------------------------------------------------
     868                 :            : 
     869                 :      79775 : SvStream& operator<<( SvStream& rOStm, const Font& rFont )
     870                 :            : {
     871                 :      79775 :     return( rOStm << *rFont.mpImplFont );
     872                 :            : }
     873                 :            : 
     874                 :            : // -----------------------------------------------------------------------
     875                 :            : namespace
     876                 :            : {
     877                 :          0 :     bool identifyTrueTypeFont( const void* i_pBuffer, sal_uInt32 i_nSize, Font& o_rResult )
     878                 :            :     {
     879                 :          0 :         bool bResult = false;
     880                 :          0 :         TrueTypeFont* pTTF = NULL;
     881 [ #  # ][ #  # ]:          0 :         if( OpenTTFontBuffer( const_cast<void*>(i_pBuffer), i_nSize, 0, &pTTF ) == SF_OK )
     882                 :            :         {
     883                 :            :             TTGlobalFontInfo aInfo;
     884         [ #  # ]:          0 :             GetTTGlobalFontInfo( pTTF, &aInfo );
     885                 :            :             // most important: the family name
     886         [ #  # ]:          0 :             if( aInfo.ufamily )
     887         [ #  # ]:          0 :                 o_rResult.SetName( aInfo.ufamily );
     888         [ #  # ]:          0 :             else if( aInfo.family )
     889 [ #  # ][ #  # ]:          0 :                 o_rResult.SetName( rtl::OStringToOUString( aInfo.family, RTL_TEXTENCODING_ASCII_US ) );
     890                 :            :             // set weight
     891         [ #  # ]:          0 :             if( aInfo.weight )
     892                 :            :             {
     893         [ #  # ]:          0 :                 if( aInfo.weight < FW_EXTRALIGHT )
     894         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_THIN );
     895         [ #  # ]:          0 :                 else if( aInfo.weight < FW_LIGHT )
     896         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_ULTRALIGHT );
     897         [ #  # ]:          0 :                 else if( aInfo.weight < FW_NORMAL )
     898         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_LIGHT );
     899         [ #  # ]:          0 :                 else if( aInfo.weight < FW_MEDIUM )
     900         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_NORMAL );
     901         [ #  # ]:          0 :                 else if( aInfo.weight < FW_SEMIBOLD )
     902         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_MEDIUM );
     903         [ #  # ]:          0 :                 else if( aInfo.weight < FW_BOLD )
     904         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_SEMIBOLD );
     905         [ #  # ]:          0 :                 else if( aInfo.weight < FW_EXTRABOLD )
     906         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_BOLD );
     907         [ #  # ]:          0 :                 else if( aInfo.weight < FW_BLACK )
     908         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_ULTRABOLD );
     909                 :            :                 else
     910         [ #  # ]:          0 :                     o_rResult.SetWeight( WEIGHT_BLACK );
     911                 :            :             }
     912                 :            :             else
     913 [ #  # ][ #  # ]:          0 :                 o_rResult.SetWeight( (aInfo.macStyle & 1) ? WEIGHT_BOLD : WEIGHT_NORMAL );
     914                 :            :             // set width
     915         [ #  # ]:          0 :             if( aInfo.width )
     916                 :            :             {
     917         [ #  # ]:          0 :                 if( aInfo.width == FWIDTH_ULTRA_CONDENSED )
     918         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_ULTRA_CONDENSED );
     919         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_EXTRA_CONDENSED )
     920         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_EXTRA_CONDENSED );
     921         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_CONDENSED )
     922         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_CONDENSED );
     923         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_SEMI_CONDENSED )
     924         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_SEMI_CONDENSED );
     925         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_NORMAL )
     926         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_NORMAL );
     927         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_SEMI_EXPANDED )
     928         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_SEMI_EXPANDED );
     929         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_EXPANDED )
     930         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_EXPANDED );
     931         [ #  # ]:          0 :                 else if( aInfo.width == FWIDTH_EXTRA_EXPANDED )
     932         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_EXTRA_EXPANDED );
     933         [ #  # ]:          0 :                 else if( aInfo.width >= FWIDTH_ULTRA_EXPANDED )
     934         [ #  # ]:          0 :                     o_rResult.SetWidth( WIDTH_ULTRA_EXPANDED );
     935                 :            :             }
     936                 :            :             // set italic
     937 [ #  # ][ #  # ]:          0 :             o_rResult.SetItalic( (aInfo.italicAngle != 0) ? ITALIC_NORMAL : ITALIC_NONE );
     938                 :            : 
     939                 :            :             // set pitch
     940 [ #  # ][ #  # ]:          0 :             o_rResult.SetPitch( (aInfo.pitch == 0) ? PITCH_VARIABLE : PITCH_FIXED );
     941                 :            : 
     942                 :            :             // set style name
     943         [ #  # ]:          0 :             if( aInfo.usubfamily )
     944 [ #  # ][ #  # ]:          0 :                 o_rResult.SetStyleName( rtl::OUString( aInfo.usubfamily ) );
                 [ #  # ]
     945         [ #  # ]:          0 :             else if( aInfo.subfamily )
     946 [ #  # ][ #  # ]:          0 :                 o_rResult.SetStyleName( rtl::OUString::createFromAscii( aInfo.subfamily ) );
                 [ #  # ]
     947                 :            : 
     948                 :            :             // cleanup
     949         [ #  # ]:          0 :             CloseTTFont( pTTF );
     950                 :            :             // success
     951                 :          0 :             bResult = true;
     952                 :            :         }
     953                 :          0 :         return bResult;
     954                 :            :     }
     955                 :            : 
     956                 :            :     struct WeightSearchEntry
     957                 :            :     {
     958                 :            :         const char* string;
     959                 :            :         int         string_len;
     960                 :            :         FontWeight  weight;
     961                 :            : 
     962                 :          0 :         bool operator<( const WeightSearchEntry& rRight ) const
     963                 :            :         {
     964                 :          0 :             return rtl_str_compareIgnoreAsciiCase_WithLength( string, string_len, rRight.string, rRight.string_len ) < 0;
     965                 :            :         }
     966                 :            :     }
     967                 :            :     weight_table[] =
     968                 :            :     {
     969                 :            :         { "black", 5, WEIGHT_BLACK },
     970                 :            :         { "bold", 4, WEIGHT_BOLD },
     971                 :            :         { "book", 4, WEIGHT_LIGHT },
     972                 :            :         { "demi", 4, WEIGHT_SEMIBOLD },
     973                 :            :         { "heavy", 5, WEIGHT_BLACK },
     974                 :            :         { "light", 5, WEIGHT_LIGHT },
     975                 :            :         { "medium", 6, WEIGHT_MEDIUM },
     976                 :            :         { "regular", 7, WEIGHT_NORMAL },
     977                 :            :         { "super", 5, WEIGHT_ULTRABOLD },
     978                 :            :         { "thin", 4, WEIGHT_THIN }
     979                 :            :     };
     980                 :            : 
     981                 :          0 :     bool identifyType1Font( const char* i_pBuffer, sal_uInt32 i_nSize, Font& o_rResult )
     982                 :            :     {
     983                 :          0 :         bool bResult = false;
     984                 :            :         // might be a type1, find eexec
     985                 :          0 :         const char* pStream = i_pBuffer;
     986                 :          0 :         const char* pExec = "eexec";
     987                 :          0 :         const char* pExecPos = std::search( pStream, pStream+i_nSize, pExec, pExec+5 );
     988         [ #  # ]:          0 :         if( pExecPos != pStream+i_nSize)
     989                 :            :         {
     990                 :            :             // find /FamilyName entry
     991                 :            :             static const char* pFam = "/FamilyName";
     992                 :          0 :             const char* pFamPos = std::search( pStream, pExecPos, pFam, pFam+11 );
     993         [ #  # ]:          0 :             if( pFamPos != pExecPos )
     994                 :            :             {
     995                 :            :                 // extract the string value behind /FamilyName
     996                 :          0 :                 const char* pOpen = pFamPos+11;
     997 [ #  # ][ #  # ]:          0 :                 while( pOpen < pExecPos && *pOpen != '(' )
                 [ #  # ]
     998                 :          0 :                     pOpen++;
     999                 :          0 :                 const char* pClose = pOpen;
    1000 [ #  # ][ #  # ]:          0 :                 while( pClose < pExecPos && *pClose != ')' )
                 [ #  # ]
    1001                 :          0 :                     pClose++;
    1002         [ #  # ]:          0 :                 if( pClose - pOpen > 1 )
    1003                 :            :                 {
    1004 [ #  # ][ #  # ]:          0 :                     o_rResult.SetName( rtl::OStringToOUString( rtl::OString( pOpen+1, pClose-pOpen-1 ), RTL_TEXTENCODING_ASCII_US ) );
    1005                 :            :                 }
    1006                 :            :             }
    1007                 :            : 
    1008                 :            :             // parse /ItalicAngle
    1009                 :            :             static const char* pItalic = "/ItalicAngle";
    1010                 :          0 :             const char* pItalicPos = std::search( pStream, pExecPos, pItalic, pItalic+12 );
    1011         [ #  # ]:          0 :             if( pItalicPos != pExecPos )
    1012                 :            :             {
    1013                 :          0 :                 sal_Int32 nItalic = rtl_str_toInt32( pItalicPos+12, 10 );
    1014         [ #  # ]:          0 :                 o_rResult.SetItalic( (nItalic != 0) ? ITALIC_NORMAL : ITALIC_NONE );
    1015                 :            :             }
    1016                 :            : 
    1017                 :            :             // parse /Weight
    1018                 :            :             static const char* pWeight = "/Weight";
    1019                 :          0 :             const char* pWeightPos = std::search( pStream, pExecPos, pWeight, pWeight+7 );
    1020         [ #  # ]:          0 :             if( pWeightPos != pExecPos )
    1021                 :            :             {
    1022                 :            :                 // extract the string value behind /Weight
    1023                 :          0 :                 const char* pOpen = pWeightPos+7;
    1024 [ #  # ][ #  # ]:          0 :                 while( pOpen < pExecPos && *pOpen != '(' )
                 [ #  # ]
    1025                 :          0 :                     pOpen++;
    1026                 :          0 :                 const char* pClose = pOpen;
    1027 [ #  # ][ #  # ]:          0 :                 while( pClose < pExecPos && *pClose != ')' )
                 [ #  # ]
    1028                 :          0 :                     pClose++;
    1029         [ #  # ]:          0 :                 if( pClose - pOpen > 1 )
    1030                 :            :                 {
    1031                 :            :                     WeightSearchEntry aEnt;
    1032                 :          0 :                     aEnt.string = pOpen+1;
    1033                 :          0 :                     aEnt.string_len = (pClose-pOpen)-1;
    1034                 :          0 :                     aEnt.weight = WEIGHT_NORMAL;
    1035                 :          0 :                     const int nEnt = SAL_N_ELEMENTS( weight_table );
    1036         [ #  # ]:          0 :                     WeightSearchEntry* pFound = std::lower_bound( weight_table, weight_table+nEnt, aEnt );
    1037         [ #  # ]:          0 :                     if( pFound != (weight_table+nEnt) )
    1038         [ #  # ]:          0 :                         o_rResult.SetWeight( pFound->weight );
    1039                 :            :                 }
    1040                 :            :             }
    1041                 :            : 
    1042                 :            :             // parse isFixedPitch
    1043                 :            :             static const char* pFixed = "/isFixedPitch";
    1044                 :          0 :             const char* pFixedPos = std::search( pStream, pExecPos, pFixed, pFixed+13 );
    1045         [ #  # ]:          0 :             if( pFixedPos != pExecPos )
    1046                 :            :             {
    1047                 :            :                 // skip whitespace
    1048 [ #  # ][ #  # ]:          0 :                 while( pFixedPos < pExecPos-4 &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1049                 :            :                        ( *pFixedPos == ' '  ||
    1050                 :            :                          *pFixedPos == '\t' ||
    1051                 :            :                          *pFixedPos == '\r' ||
    1052                 :            :                          *pFixedPos == '\n' ) )
    1053                 :            :                 {
    1054                 :          0 :                     pFixedPos++;
    1055                 :            :                 }
    1056                 :            :                 // find "true" value
    1057         [ #  # ]:          0 :                 if( rtl_str_compareIgnoreAsciiCase_WithLength( pFixedPos, 4, "true", 4 ) == 0 )
    1058                 :          0 :                     o_rResult.SetPitch( PITCH_FIXED );
    1059                 :            :                 else
    1060                 :          0 :                     o_rResult.SetPitch( PITCH_VARIABLE );
    1061                 :            :             }
    1062                 :            :         }
    1063                 :          0 :         return bResult;
    1064                 :            :     }
    1065                 :            : }
    1066                 :            : 
    1067                 :          0 : Font Font::identifyFont( const void* i_pBuffer, sal_uInt32 i_nSize )
    1068                 :            : {
    1069                 :          0 :     Font aResult;
    1070 [ #  # ][ #  # ]:          0 :     if( ! identifyTrueTypeFont( i_pBuffer, i_nSize, aResult ) )
    1071                 :            :     {
    1072                 :          0 :         const char* pStream = reinterpret_cast<const char*>(i_pBuffer);
    1073 [ #  # ][ #  # ]:          0 :         if( pStream && i_nSize > 100 &&
         [ #  # ][ #  # ]
    1074                 :          0 :              *pStream == '%' && pStream[1] == '!' )
    1075                 :            :         {
    1076         [ #  # ]:          0 :             identifyType1Font( pStream, i_nSize, aResult );
    1077                 :            :         }
    1078                 :            :     }
    1079                 :            : 
    1080                 :          0 :     return aResult;
    1081                 :            : }
    1082                 :            : 
    1083                 :            : // the inlines from the font.hxx header are now instantiated for pImpl-ification
    1084                 :            : // TODO: reformat
    1085                 :    2598467 : const Color& Font::GetColor() const { return mpImplFont->maColor; }
    1086                 :     110746 : const Color& Font::GetFillColor() const { return mpImplFont->maFillColor; }
    1087                 :     533350 : sal_Bool Font::IsTransparent() const { return mpImplFont->mbTransparent; }
    1088                 :    1284976 : FontAlign Font::GetAlign() const { return mpImplFont->meAlign; }
    1089                 :    2478876 : const String& Font::GetName() const { return mpImplFont->maFamilyName; }
    1090                 :      46620 : const String& Font::GetStyleName() const { return mpImplFont->maStyleName; }
    1091                 :    2756170 : const Size& Font::GetSize() const { return mpImplFont->maSize; }
    1092         [ +  - ]:     105850 : void Font::SetHeight( long nHeight ) { SetSize( Size( mpImplFont->maSize.Width(), nHeight ) ); }
    1093                 :     753218 : long Font::GetHeight() const { return mpImplFont->maSize.Height(); }
    1094         [ #  # ]:          0 : void Font::SetWidth( long nWidth ) { SetSize( Size( nWidth, mpImplFont->maSize.Height() ) ); }
    1095                 :        185 : long Font::GetWidth() const { return mpImplFont->maSize.Width(); }
    1096                 :     467634 : rtl_TextEncoding Font::GetCharSet() const { return mpImplFont->meCharSet; }
    1097                 :    2012391 : LanguageType Font::GetLanguage() const { return mpImplFont->meLanguage; }
    1098                 :      19100 : LanguageType Font::GetCJKContextLanguage() const { return mpImplFont->meCJKLanguage; }
    1099                 :     895342 : short Font::GetOrientation() const { return mpImplFont->mnOrientation; }
    1100                 :    1868604 : sal_Bool Font::IsVertical() const { return mpImplFont->mbVertical; }
    1101                 :    3196428 : FontKerning Font::GetKerning() const { return mpImplFont->mnKerning; }
    1102                 :      60495 : FontPitch Font::GetPitch() const { return mpImplFont->GetPitch(); }
    1103                 :     453541 : FontWeight Font::GetWeight() const { return mpImplFont->GetWeight(); }
    1104                 :       7313 : FontWidth Font::GetWidthType() const { return mpImplFont->GetWidthType(); }
    1105                 :    2163931 : FontItalic Font::GetItalic() const { return mpImplFont->GetItalic(); }
    1106                 :      39576 : FontFamily Font::GetFamily() const { return mpImplFont->GetFamily(); }
    1107                 :     748175 : sal_Bool Font::IsOutline() const { return mpImplFont->mbOutline; }
    1108                 :     773307 : sal_Bool Font::IsShadow() const { return mpImplFont->mbShadow; }
    1109                 :     753267 : FontRelief Font::GetRelief() const { return mpImplFont->meRelief; }
    1110                 :    1318095 : FontUnderline Font::GetUnderline() const { return mpImplFont->meUnderline; }
    1111                 :    1047885 : FontUnderline Font::GetOverline()  const { return mpImplFont->meOverline; }
    1112                 :    1041773 : FontStrikeout Font::GetStrikeout() const { return mpImplFont->meStrikeout; }
    1113                 :     997252 : FontEmphasisMark Font::GetEmphasisMark() const { return mpImplFont->meEmphasisMark; }
    1114                 :    1486379 : sal_Bool Font::IsWordLineMode() const { return mpImplFont->mbWordLine; }
    1115                 :    2324218 : sal_Bool Font::IsSameInstance( const Font& rFont ) const { return (mpImplFont == rFont.mpImplFont); }
    1116                 :            : 
    1117                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10