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