bump product version to 4.1.6.2
[LibreOffice.git] / vcl / generic / glyphs / gcach_ftyp.hxx
blob2c31bb4244499240966a03436cc6db6b43b40266
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SV_GCACHFTYP_HXX
21 #define _SV_GCACHFTYP_HXX
23 #include "generic/glyphcache.hxx"
25 #include <rtl/textcvt.h>
27 #include <config_graphite.h>
28 #if ENABLE_GRAPHITE
29 class GraphiteFaceWrapper;
30 #endif
32 // -----------------------------------------------------------------------
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 class FtFontFile
39 public:
40 static FtFontFile* FindFontFile( const OString& rNativeFileName );
42 bool Map();
43 void Unmap();
45 const unsigned char* GetBuffer() const { return mpFileMap; }
46 int GetFileSize() const { return mnFileSize; }
47 const OString* GetFileName() const { return &maNativeFileName; }
48 int GetLangBoost() const { return mnLangBoost; }
50 private:
51 FtFontFile( const OString& rNativeFileName );
53 const OString maNativeFileName;
54 const unsigned char* mpFileMap;
55 int mnFileSize;
56 int mnRefCount;
57 int mnLangBoost;
60 // -----------------------------------------------------------------------
62 // FtFontInfo corresponds to an unscaled font face
63 class FtFontInfo
65 public:
66 FtFontInfo( const ImplDevFontAttributes&,
67 const OString& rNativeFileName,
68 int nFaceNum, sal_IntPtr nFontId, int nSynthetic,
69 const ExtraKernInfo* );
70 ~FtFontInfo();
72 const unsigned char* GetTable( const char*, sal_uLong* pLength=0 ) const;
74 FT_FaceRec_* GetFaceFT();
75 #if ENABLE_GRAPHITE
76 GraphiteFaceWrapper* GetGraphiteFace();
77 #endif
78 void ReleaseFaceFT( FT_FaceRec_* );
80 const OString* GetFontFileName() const { return mpFontFile->GetFileName(); }
81 int GetFaceNum() const { return mnFaceNum; }
82 int GetSynthetic() const { return mnSynthetic; }
83 sal_IntPtr GetFontId() const { return mnFontId; }
84 bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); }
85 const ImplFontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
87 void AnnounceFont( ImplDevFontList* );
89 int GetGlyphIndex( sal_UCS4 cChar ) const;
90 void CacheGlyphIndex( sal_UCS4 cChar, int nGI ) const;
92 bool GetFontCodeRanges( CmapResult& ) const;
93 const ImplFontCharMap* GetImplFontCharMap( void );
95 bool HasExtraKerning() const;
96 int GetExtraKernPairs( ImplKernPairData** ) const;
98 private:
99 FT_FaceRec_* maFaceFT;
100 FtFontFile* mpFontFile;
101 const int mnFaceNum;
102 int mnRefCount;
103 const int mnSynthetic;
104 #if ENABLE_GRAPHITE
105 bool mbCheckedGraphite;
106 GraphiteFaceWrapper * mpGraphiteFace;
107 #endif
108 sal_IntPtr mnFontId;
109 ImplDevFontAttributes maDevFontAttributes;
111 const ImplFontCharMap* mpFontCharMap;
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;
120 const ExtraKernInfo* mpExtraKernInfo;
123 // these two inlines are very important for performance
125 inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar ) const
127 if( !mpChar2Glyph )
128 return -1;
129 Int2IntMap::const_iterator it = mpChar2Glyph->find( cChar );
130 if( it == mpChar2Glyph->end() )
131 return -1;
132 return it->second;
135 inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar, int nIndex ) const
137 if( !mpChar2Glyph )
138 InitHashes();
139 (*mpChar2Glyph)[ cChar ] = nIndex;
140 (*mpGlyph2Char)[ nIndex ] = cChar;
143 // -----------------------------------------------------------------------
145 class FreetypeManager
147 public:
148 FreetypeManager();
149 ~FreetypeManager();
151 void AddFontFile( const OString& rNormalizedName,
152 int nFaceNum, sal_IntPtr nFontId, const ImplDevFontAttributes&,
153 const ExtraKernInfo* );
154 void AnnounceFonts( ImplDevFontList* ) const;
155 void ClearFontList();
157 ServerFont* CreateFont( const FontSelectPattern& );
159 private:
160 typedef ::boost::unordered_map<sal_IntPtr,FtFontInfo*> FontList;
161 FontList maFontList;
163 sal_IntPtr mnMaxFontId;
166 // -----------------------------------------------------------------------
168 class ImplFTSFontData : public PhysicalFontFace
170 private:
171 FtFontInfo* mpFtFontInfo;
172 enum { IFTSFONT_MAGIC = 0x1F150A1C };
174 public:
175 ImplFTSFontData( FtFontInfo*, const ImplDevFontAttributes& );
177 FtFontInfo* GetFtFontInfo() const { return mpFtFontInfo; }
179 virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const;
180 virtual PhysicalFontFace* Clone() const { return new ImplFTSFontData( *this ); }
181 virtual sal_IntPtr GetFontId() const { return mpFtFontInfo->GetFontId(); }
183 static bool CheckFontData( const PhysicalFontFace& r ) { return r.CheckMagic( IFTSFONT_MAGIC ); }
186 // -----------------------------------------------------------------------
188 #endif // _SV_GCACHFTYP_HXX
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */