1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_VCL_GENERIC_GLYPHS_GCACH_FTYP_HXX
21 #define INCLUDED_VCL_GENERIC_GLYPHS_GCACH_FTYP_HXX
23 #include "generic/glyphcache.hxx"
24 #include "PhysicalFontFace.hxx"
26 #include <config_graphite.h>
28 class GraphiteFaceWrapper
;
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
37 static FtFontFile
* FindFontFile( const OString
& rNativeFileName
);
42 const unsigned char* GetBuffer() const { return mpFileMap
; }
43 int GetFileSize() const { return mnFileSize
; }
44 const OString
& GetFileName() const { return maNativeFileName
; }
45 int GetLangBoost() const { return mnLangBoost
; }
48 FtFontFile( const OString
& rNativeFileName
);
50 const OString maNativeFileName
;
51 unsigned char* mpFileMap
;
57 // FtFontInfo corresponds to an unscaled font face
61 FtFontInfo( const ImplDevFontAttributes
&,
62 const OString
& rNativeFileName
,
63 int nFaceNum
, sal_IntPtr nFontId
, int nSynthetic
);
66 const unsigned char* GetTable( const char*, sal_uLong
* pLength
=0 ) const;
68 FT_FaceRec_
* GetFaceFT();
70 GraphiteFaceWrapper
* GetGraphiteFace();
74 const OString
& GetFontFileName() const { return mpFontFile
->GetFileName(); }
75 int GetFaceNum() const { return mnFaceNum
; }
76 int GetSynthetic() const { return mnSynthetic
; }
77 sal_IntPtr
GetFontId() const { return mnFontId
; }
78 bool IsSymbolFont() const { return maDevFontAttributes
.IsSymbolFont(); }
79 const ImplFontAttributes
& GetFontAttributes() const { return maDevFontAttributes
; }
81 void AnnounceFont( PhysicalFontCollection
* );
83 int GetGlyphIndex( sal_UCS4 cChar
) const;
84 void CacheGlyphIndex( sal_UCS4 cChar
, int nGI
) const;
86 bool GetFontCodeRanges( CmapResult
& ) const;
87 const FontCharMapPtr
GetFontCharMap();
90 FT_FaceRec_
* maFaceFT
;
91 FtFontFile
* mpFontFile
;
94 const int mnSynthetic
;
96 bool mbCheckedGraphite
;
97 GraphiteFaceWrapper
* mpGraphiteFace
;
100 ImplDevFontAttributes maDevFontAttributes
;
102 FontCharMapPtr mpFontCharMap
;
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;
112 // these two inlines are very important for performance
114 inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar
) const
118 Int2IntMap::const_iterator it
= mpChar2Glyph
->find( cChar
);
119 if( it
== mpChar2Glyph
->end() )
124 inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar
, int nIndex
) const
128 (*mpChar2Glyph
)[ cChar
] = nIndex
;
129 (*mpGlyph2Char
)[ nIndex
] = cChar
;
132 class FreetypeManager
138 void AddFontFile( const OString
& rNormalizedName
,
139 int nFaceNum
, sal_IntPtr nFontId
, const ImplDevFontAttributes
&);
140 void AnnounceFonts( PhysicalFontCollection
* ) const;
141 void ClearFontList();
143 ServerFont
* CreateFont( const FontSelectPattern
& );
146 typedef std::unordered_map
<sal_IntPtr
,FtFontInfo
*> FontList
;
149 sal_IntPtr mnMaxFontId
;
152 class ImplFTSFontData
: public PhysicalFontFace
155 FtFontInfo
* mpFtFontInfo
;
156 enum { IFTSFONT_MAGIC
= 0x1F150A1C };
159 ImplFTSFontData( FtFontInfo
*, const ImplDevFontAttributes
& );
161 FtFontInfo
* GetFtFontInfo() const { return mpFtFontInfo
; }
163 virtual ImplFontEntry
* CreateFontInstance( FontSelectPattern
& ) const SAL_OVERRIDE
;
164 virtual PhysicalFontFace
* Clone() const SAL_OVERRIDE
{ return new ImplFTSFontData( *this ); }
165 virtual sal_IntPtr
GetFontId() const SAL_OVERRIDE
{ return mpFtFontInfo
->GetFontId(); }
167 static bool CheckFontData( const PhysicalFontFace
& r
) { return r
.CheckMagic( IFTSFONT_MAGIC
); }
170 #endif // INCLUDED_VCL_GENERIC_GLYPHS_GCACH_FTYP_HXX
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */