LCOV - code coverage report
Current view: top level - libreoffice/vcl/generic/glyphs - gcach_ftyp.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 25 92.0 %
Date: 2012-12-27 Functions: 14 16 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _SV_GCACHFTYP_HXX
      21             : #define _SV_GCACHFTYP_HXX
      22             : 
      23             : #include "generic/glyphcache.hxx"
      24             : 
      25             : #include <rtl/textcvt.h>
      26             : 
      27             : #include <config_graphite.h>
      28             : #ifdef ENABLE_GRAPHITE
      29             : class GraphiteFaceWrapper;
      30             : #endif
      31             : 
      32             : // -----------------------------------------------------------------------
      33             : 
      34             : // FtFontFile has the responsibility that a font file is only mapped once.
      35             : // (#86621#) the old directly ft-managed solution caused it to be mapped
      36             : // in up to nTTC*nSizes*nOrientation*nSynthetic times
      37        2180 : class FtFontFile
      38             : {
      39             : public:
      40             :     static FtFontFile*      FindFontFile( const ::rtl::OString& rNativeFileName );
      41             : 
      42             :     bool                    Map();
      43             :     void                    Unmap();
      44             : 
      45        5897 :     const unsigned char*    GetBuffer() const { return mpFileMap; }
      46        3310 :     int                     GetFileSize() const { return mnFileSize; }
      47           0 :     const ::rtl::OString*   GetFileName() const { return &maNativeFileName; }
      48        2280 :     int                     GetLangBoost() const { return mnLangBoost; }
      49             : 
      50             : private:
      51             :                             FtFontFile( const ::rtl::OString& rNativeFileName );
      52             : 
      53             :     const ::rtl::OString    maNativeFileName;
      54             :     const unsigned char*    mpFileMap;
      55             :     int                     mnFileSize;
      56             :     int                     mnRefCount;
      57             :     int                     mnLangBoost;
      58             : };
      59             : 
      60             : // -----------------------------------------------------------------------
      61             : 
      62             : // FtFontInfo corresponds to an unscaled font face
      63             : class FtFontInfo
      64             : {
      65             : public:
      66             :                            FtFontInfo( const ImplDevFontAttributes&,
      67             :                                const ::rtl::OString& rNativeFileName,
      68             :                                int nFaceNum, sal_IntPtr nFontId, int nSynthetic,
      69             :                                 const ExtraKernInfo* );
      70             :                           ~FtFontInfo();
      71             : 
      72             :     const unsigned char*  GetTable( const char*, sal_uLong* pLength=0 ) const;
      73             : 
      74             :     FT_FaceRec_*          GetFaceFT();
      75             : #ifdef ENABLE_GRAPHITE
      76             :     GraphiteFaceWrapper*  GetGraphiteFace();
      77             : #endif
      78             :     void                  ReleaseFaceFT( FT_FaceRec_* );
      79             : 
      80           0 :     const ::rtl::OString* GetFontFileName() const   { return mpFontFile->GetFileName(); }
      81             :     int                   GetFaceNum() const        { return mnFaceNum; }
      82             :     int                   GetSynthetic() const      { return mnSynthetic; }
      83       19772 :     sal_IntPtr            GetFontId() const         { return mnFontId; }
      84      335556 :     bool                  IsSymbolFont() const      { return maDevFontAttributes.IsSymbolFont(); }
      85        4841 :     const ImplFontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
      86             : 
      87             :     void                  AnnounceFont( ImplDevFontList* );
      88             : 
      89             :     int                   GetGlyphIndex( sal_UCS4 cChar ) const;
      90             :     void                  CacheGlyphIndex( sal_UCS4 cChar, int nGI ) const;
      91             : 
      92             :     bool                  GetFontCodeRanges( CmapResult& ) const;
      93             :     const ImplFontCharMap* GetImplFontCharMap( void );
      94             : 
      95             :     bool                  HasExtraKerning() const;
      96             :     int                   GetExtraKernPairs( ImplKernPairData** ) const;
      97             : 
      98             : private:
      99             :     FT_FaceRec_*    maFaceFT;
     100             :     FtFontFile*     mpFontFile;
     101             :     const int       mnFaceNum;
     102             :     int             mnRefCount;
     103             :     const int       mnSynthetic;
     104             : #ifdef ENABLE_GRAPHITE
     105             :     bool            mbCheckedGraphite;
     106             :     GraphiteFaceWrapper * mpGraphiteFace;
     107             : #endif
     108             :     sal_IntPtr      mnFontId;
     109             :     ImplDevFontAttributes maDevFontAttributes;
     110             : 
     111             :     const ImplFontCharMap* mpFontCharMap;
     112             : 
     113             :     // cache unicode->glyphid mapping because looking it up is expensive
     114             :     // TODO: change to boost::unordered_multimap when a use case requires a m:n mapping
     115             :     typedef ::boost::unordered_map<int,int> Int2IntMap;
     116             :     mutable Int2IntMap* mpChar2Glyph;
     117             :     mutable Int2IntMap* mpGlyph2Char;
     118             :     void InitHashes() const;
     119             : 
     120             :     const ExtraKernInfo* mpExtraKernInfo;
     121             : };
     122             : 
     123             : // these two inlines are very important for performance
     124             : 
     125      305222 : inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar ) const
     126             : {
     127      305222 :     if( !mpChar2Glyph )
     128          88 :         return -1;
     129      305134 :     Int2IntMap::const_iterator it = mpChar2Glyph->find( cChar );
     130      305134 :     if( it == mpChar2Glyph->end() )
     131        1972 :         return -1;
     132      303162 :     return it->second;
     133             : }
     134             : 
     135        2060 : inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar, int nIndex ) const
     136             : {
     137        2060 :     if( !mpChar2Glyph )
     138          88 :         InitHashes();
     139        2060 :     (*mpChar2Glyph)[ cChar ] = nIndex;
     140        2060 :     (*mpGlyph2Char)[ nIndex ] = cChar;
     141        2060 : }
     142             : 
     143             : // -----------------------------------------------------------------------
     144             : 
     145             : class FreetypeManager
     146             : {
     147             : public:
     148             :                         FreetypeManager();
     149             :                         ~FreetypeManager();
     150             : 
     151             :     void                AddFontFile( const rtl::OString& rNormalizedName,
     152             :                             int nFaceNum, sal_IntPtr nFontId, const ImplDevFontAttributes&,
     153             :                             const ExtraKernInfo* );
     154             :     void                AnnounceFonts( ImplDevFontList* ) const;
     155             :     void                ClearFontList();
     156             : 
     157             :     ServerFont* CreateFont( const FontSelectPattern& );
     158             : 
     159             : private:
     160             :     typedef ::boost::unordered_map<sal_IntPtr,FtFontInfo*> FontList;
     161             :     FontList            maFontList;
     162             : 
     163             :     sal_IntPtr          mnMaxFontId;
     164             : };
     165             : 
     166             : // -----------------------------------------------------------------------
     167             : 
     168       77074 : class ImplFTSFontData : public PhysicalFontFace
     169             : {
     170             : private:
     171             :     FtFontInfo*             mpFtFontInfo;
     172             :     enum { IFTSFONT_MAGIC = 0x1F150A1C };
     173             : 
     174             : public:
     175             :                             ImplFTSFontData( FtFontInfo*, const ImplDevFontAttributes& );
     176             : 
     177             :     FtFontInfo*             GetFtFontInfo() const { return mpFtFontInfo; }
     178             : 
     179             :     virtual ImplFontEntry*  CreateFontInstance( FontSelectPattern& ) const;
     180       39270 :     virtual PhysicalFontFace* Clone() const   { return new ImplFTSFontData( *this ); }
     181       19772 :     virtual sal_IntPtr      GetFontId() const { return mpFtFontInfo->GetFontId(); }
     182             : 
     183             :     static bool             CheckFontData( const PhysicalFontFace& r ) { return r.CheckMagic( IFTSFONT_MAGIC ); }
     184             : };
     185             : 
     186             : // -----------------------------------------------------------------------
     187             : 
     188             : #endif // _SV_GCACHFTYP_HXX
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10