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 _SV_GCACHFTYP_HXX
21 #define _SV_GCACHFTYP_HXX
23 #include "generic/glyphcache.hxx"
25 #include <rtl/textcvt.h>
27 #include <config_graphite.h>
29 class GraphiteFaceWrapper
;
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
40 static FtFontFile
* FindFontFile( const OString
& rNativeFileName
);
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
; }
51 FtFontFile( const OString
& rNativeFileName
);
53 const OString maNativeFileName
;
54 const unsigned char* mpFileMap
;
60 // -----------------------------------------------------------------------
62 // FtFontInfo corresponds to an unscaled font face
66 FtFontInfo( const ImplDevFontAttributes
&,
67 const OString
& rNativeFileName
,
68 int nFaceNum
, sal_IntPtr nFontId
, int nSynthetic
,
69 const ExtraKernInfo
* );
72 const unsigned char* GetTable( const char*, sal_uLong
* pLength
=0 ) const;
74 FT_FaceRec_
* GetFaceFT();
76 GraphiteFaceWrapper
* GetGraphiteFace();
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;
99 FT_FaceRec_
* maFaceFT
;
100 FtFontFile
* mpFontFile
;
103 const int mnSynthetic
;
105 bool mbCheckedGraphite
;
106 GraphiteFaceWrapper
* mpGraphiteFace
;
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
129 Int2IntMap::const_iterator it
= mpChar2Glyph
->find( cChar
);
130 if( it
== mpChar2Glyph
->end() )
135 inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar
, int nIndex
) const
139 (*mpChar2Glyph
)[ cChar
] = nIndex
;
140 (*mpGlyph2Char
)[ nIndex
] = cChar
;
143 // -----------------------------------------------------------------------
145 class 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
& );
160 typedef ::boost::unordered_map
<sal_IntPtr
,FtFontInfo
*> FontList
;
163 sal_IntPtr mnMaxFontId
;
166 // -----------------------------------------------------------------------
168 class ImplFTSFontData
: public PhysicalFontFace
171 FtFontInfo
* mpFtFontInfo
;
172 enum { IFTSFONT_MAGIC
= 0x1F150A1C };
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: */