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 47736 : class FtFontFile
35 : {
36 : public:
37 : static FtFontFile* FindFontFile( const OString& rNativeFileName );
38 :
39 : bool Map();
40 : void Unmap();
41 :
42 28682 : const unsigned char* GetBuffer() const { return mpFileMap; }
43 15135 : int GetFileSize() const { return mnFileSize; }
44 0 : const OString& GetFileName() const { return maNativeFileName; }
45 50995 : int GetLangBoost() const { return mnLangBoost; }
46 :
47 : private:
48 : explicit FtFontFile( const OString& rNativeFileName );
49 :
50 : const OString maNativeFileName;
51 : 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 285020 : sal_IntPtr GetFontId() const { return mnFontId; }
78 24856826 : bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); }
79 15159 : 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 std::unordered_multimap when a use case requires a m:n mapping
106 : typedef std::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 24850721 : inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar ) const
115 : {
116 24850721 : if( !mpChar2Glyph )
117 902 : return -1;
118 24849819 : Int2IntMap::const_iterator it = mpChar2Glyph->find( cChar );
119 24849819 : if( it == mpChar2Glyph->end() )
120 23802 : return -1;
121 24826017 : return it->second;
122 : }
123 :
124 24704 : inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar, int nIndex ) const
125 : {
126 24704 : if( !mpChar2Glyph )
127 902 : InitHashes();
128 24704 : (*mpChar2Glyph)[ cChar ] = nIndex;
129 24704 : (*mpGlyph2Char)[ nIndex ] = cChar;
130 24704 : }
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 std::unordered_map<sal_IntPtr,FtFontInfo*> FontList;
147 : FontList maFontList;
148 :
149 : sal_IntPtr mnMaxFontId;
150 : };
151 :
152 2584386 : 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 809936 : virtual PhysicalFontFace* Clone() const SAL_OVERRIDE { return new ImplFTSFontData( *this ); }
165 285020 : 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: */
|