LCOV - code coverage report
Current view: top level - vcl/generic/glyphs - gcach_ftyp.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 25 92.0 %
Date: 2012-08-25 Functions: 14 16 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 18 66.7 %

           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                 :            : #ifndef _SV_GCACHFTYP_HXX
      30                 :            : #define _SV_GCACHFTYP_HXX
      31                 :            : 
      32                 :            : #include "generic/glyphcache.hxx"
      33                 :            : 
      34                 :            : #include <rtl/textcvt.h>
      35                 :            : 
      36                 :            : #ifdef ENABLE_GRAPHITE
      37                 :            : class GraphiteFaceWrapper;
      38                 :            : #endif
      39                 :            : 
      40                 :            : // -----------------------------------------------------------------------
      41                 :            : 
      42                 :            : // FtFontFile has the responsibility that a font file is only mapped once.
      43                 :            : // (#86621#) the old directly ft-managed solution caused it to be mapped
      44                 :            : // in up to nTTC*nSizes*nOrientation*nSynthetic times
      45                 :      33782 : class FtFontFile
      46                 :            : {
      47                 :            : public:
      48                 :            :     static FtFontFile*      FindFontFile( const ::rtl::OString& rNativeFileName );
      49                 :            : 
      50                 :            :     bool                    Map();
      51                 :            :     void                    Unmap();
      52                 :            : 
      53                 :      24952 :     const unsigned char*    GetBuffer() const { return mpFileMap; }
      54                 :      15157 :     int                     GetFileSize() const { return mnFileSize; }
      55                 :          0 :     const ::rtl::OString*   GetFileName() const { return &maNativeFileName; }
      56                 :      34962 :     int                     GetLangBoost() const { return mnLangBoost; }
      57                 :            : 
      58                 :            : private:
      59                 :            :                             FtFontFile( const ::rtl::OString& rNativeFileName );
      60                 :            : 
      61                 :            :     const ::rtl::OString    maNativeFileName;
      62                 :            :     const unsigned char*    mpFileMap;
      63                 :            :     int                     mnFileSize;
      64                 :            :     int                     mnRefCount;
      65                 :            :     int                     mnLangBoost;
      66                 :            : };
      67                 :            : 
      68                 :            : // -----------------------------------------------------------------------
      69                 :            : 
      70                 :            : // FtFontInfo corresponds to an unscaled font face
      71                 :            : class FtFontInfo
      72                 :            : {
      73                 :            : public:
      74                 :            :                            FtFontInfo( const ImplDevFontAttributes&,
      75                 :            :                                const ::rtl::OString& rNativeFileName,
      76                 :            :                                int nFaceNum, sal_IntPtr nFontId, int nSynthetic,
      77                 :            :                                 const ExtraKernInfo* );
      78                 :            :                           ~FtFontInfo();
      79                 :            : 
      80                 :            :     const unsigned char*  GetTable( const char*, sal_uLong* pLength=0 ) const;
      81                 :            : 
      82                 :            :     FT_FaceRec_*          GetFaceFT();
      83                 :            : #ifdef ENABLE_GRAPHITE
      84                 :            :     GraphiteFaceWrapper*  GetGraphiteFace();
      85                 :            : #endif
      86                 :            :     void                  ReleaseFaceFT( FT_FaceRec_* );
      87                 :            : 
      88                 :          0 :     const ::rtl::OString* GetFontFileName() const   { return mpFontFile->GetFileName(); }
      89                 :            :     int                   GetFaceNum() const        { return mnFaceNum; }
      90                 :            :     int                   GetSynthetic() const      { return mnSynthetic; }
      91                 :     196497 :     sal_IntPtr            GetFontId() const         { return mnFontId; }
      92                 :   23416475 :     bool                  IsSymbolFont() const      { return maDevFontAttributes.IsSymbolFont(); }
      93                 :      18038 :     const ImplFontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
      94                 :            : 
      95                 :            :     void                  AnnounceFont( ImplDevFontList* );
      96                 :            : 
      97                 :            :     int                   GetGlyphIndex( sal_UCS4 cChar ) const;
      98                 :            :     void                  CacheGlyphIndex( sal_UCS4 cChar, int nGI ) const;
      99                 :            : 
     100                 :            :     bool                  GetFontCodeRanges( CmapResult& ) const;
     101                 :            :     const ImplFontCharMap* GetImplFontCharMap( void );
     102                 :            : 
     103                 :            :     bool                  HasExtraKerning() const;
     104                 :            :     int                   GetExtraKernPairs( ImplKernPairData** ) const;
     105                 :            :     int                   GetExtraGlyphKernValue( int nLeftGlyph, int nRightGlyph ) const;
     106                 :            : 
     107                 :            : private:
     108                 :            :     FT_FaceRec_*    maFaceFT;
     109                 :            :     FtFontFile*     mpFontFile;
     110                 :            :     const int       mnFaceNum;
     111                 :            :     int             mnRefCount;
     112                 :            :     const int       mnSynthetic;
     113                 :            : #ifdef ENABLE_GRAPHITE
     114                 :            :     bool            mbCheckedGraphite;
     115                 :            :     GraphiteFaceWrapper * mpGraphiteFace;
     116                 :            : #endif
     117                 :            :     sal_IntPtr      mnFontId;
     118                 :            :     ImplDevFontAttributes maDevFontAttributes;
     119                 :            : 
     120                 :            :     const ImplFontCharMap* mpFontCharMap;
     121                 :            : 
     122                 :            :     // cache unicode->glyphid mapping because looking it up is expensive
     123                 :            :     // TODO: change to boost::unordered_multimap when a use case requires a m:n mapping
     124                 :            :     typedef ::boost::unordered_map<int,int> Int2IntMap;
     125                 :            :     mutable Int2IntMap* mpChar2Glyph;
     126                 :            :     mutable Int2IntMap* mpGlyph2Char;
     127                 :            :     void InitHashes() const;
     128                 :            : 
     129                 :            :     const ExtraKernInfo* mpExtraKernInfo;
     130                 :            : };
     131                 :            : 
     132                 :            : // these two inlines are very important for performance
     133                 :            : 
     134                 :   23392166 : inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar ) const
     135                 :            : {
     136         [ +  + ]:   23392166 :     if( !mpChar2Glyph )
     137                 :        690 :         return -1;
     138         [ +  - ]:   23391476 :     Int2IntMap::const_iterator it = mpChar2Glyph->find( cChar );
     139 [ +  + ][ +  - ]:   23391476 :     if( it == mpChar2Glyph->end() )
     140                 :      15109 :         return -1;
     141         [ +  - ]:   23392166 :     return it->second;
     142                 :            : }
     143                 :            : 
     144                 :      15799 : inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar, int nIndex ) const
     145                 :            : {
     146         [ +  + ]:      15799 :     if( !mpChar2Glyph )
     147                 :        690 :         InitHashes();
     148         [ +  - ]:      15799 :     (*mpChar2Glyph)[ cChar ] = nIndex;
     149                 :      15799 :     (*mpGlyph2Char)[ nIndex ] = cChar;
     150                 :      15799 : }
     151                 :            : 
     152                 :            : // -----------------------------------------------------------------------
     153                 :            : 
     154                 :            : class FreetypeManager
     155                 :            : {
     156                 :            : public:
     157                 :            :                         FreetypeManager();
     158                 :            :                         ~FreetypeManager();
     159                 :            : 
     160                 :            :     void                AddFontFile( const rtl::OString& rNormalizedName,
     161                 :            :                             int nFaceNum, sal_IntPtr nFontId, const ImplDevFontAttributes&,
     162                 :            :                             const ExtraKernInfo* );
     163                 :            :     void                AnnounceFonts( ImplDevFontList* ) const;
     164                 :            :     void                ClearFontList();
     165                 :            : 
     166                 :            :     ServerFont* CreateFont( const FontSelectPattern& );
     167                 :            : 
     168                 :            : private:
     169                 :            :     typedef ::boost::unordered_map<sal_IntPtr,FtFontInfo*> FontList;
     170                 :            :     FontList            maFontList;
     171                 :            : 
     172                 :            :     sal_IntPtr          mnMaxFontId;
     173                 :            : };
     174                 :            : 
     175                 :            : // -----------------------------------------------------------------------
     176                 :            : 
     177         [ -  + ]:     756704 : class ImplFTSFontData : public PhysicalFontFace
     178                 :            : {
     179                 :            : private:
     180                 :            :     FtFontInfo*             mpFtFontInfo;
     181                 :            :     enum { IFTSFONT_MAGIC = 0x1F150A1C };
     182                 :            : 
     183                 :            : public:
     184                 :            :                             ImplFTSFontData( FtFontInfo*, const ImplDevFontAttributes& );
     185                 :            : 
     186                 :            :     FtFontInfo*             GetFtFontInfo() const { return mpFtFontInfo; }
     187                 :            : 
     188                 :            :     virtual ImplFontEntry*  CreateFontInstance( FontSelectPattern& ) const;
     189         [ +  - ]:     243408 :     virtual PhysicalFontFace* Clone() const   { return new ImplFTSFontData( *this ); }
     190                 :     196497 :     virtual sal_IntPtr      GetFontId() const { return mpFtFontInfo->GetFontId(); }
     191                 :            : 
     192                 :            :     static bool             CheckFontData( const PhysicalFontFace& r ) { return r.CheckMagic( IFTSFONT_MAGIC ); }
     193                 :            : };
     194                 :            : 
     195                 :            : // -----------------------------------------------------------------------
     196                 :            : 
     197                 :            : #endif // _SV_GCACHFTYP_HXX
     198                 :            : 
     199                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10