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

Generated by: LCOV version 1.10