1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _SV_GCACHFTYP_HXX
29 #define _SV_GCACHFTYP_HXX
31 #include <vcl/glyphcache.hxx>
32 #include <rtl/textcvt.h>
35 #include FT_FREETYPE_H
36 class FreetypeServerFont
;
39 // -----------------------------------------------------------------------
41 // FtFontFile has the responsibility that a font file is only mapped once.
42 // (#86621#) the old directly ft-managed solution caused it to be mapped
43 // in up to nTTC*nSizes*nOrientation*nSynthetic times
47 static FtFontFile
* FindFontFile( const ::rtl::OString
& rNativeFileName
);
52 const unsigned char* GetBuffer() const { return mpFileMap
; }
53 int GetFileSize() const { return mnFileSize
; }
54 const ::rtl::OString
* GetFileName() const { return &maNativeFileName
; }
55 int GetLangBoost() const { return mnLangBoost
; }
58 FtFontFile( const ::rtl::OString
& rNativeFileName
);
60 const ::rtl::OString maNativeFileName
;
61 const unsigned char* mpFileMap
;
67 // -----------------------------------------------------------------------
69 // FtFontInfo corresponds to an unscaled font face
73 FtFontInfo( const ImplDevFontAttributes
&,
74 const ::rtl::OString
& rNativeFileName
,
75 int nFaceNum
, sal_IntPtr nFontId
, int nSynthetic
,
76 const ExtraKernInfo
* );
79 const unsigned char* GetTable( const char*, ULONG
* pLength
=0 ) const;
81 FT_FaceRec_
* GetFaceFT();
82 void ReleaseFaceFT( FT_FaceRec_
* );
84 const ::rtl::OString
* GetFontFileName() const { return mpFontFile
->GetFileName(); }
85 int GetFaceNum() const { return mnFaceNum
; }
86 int GetSynthetic() const { return mnSynthetic
; }
87 sal_IntPtr
GetFontId() const { return mnFontId
; }
88 bool DontUseAntiAlias() const
89 { return maDevFontAttributes
.UseAntiAlias() == ANTIALIAS_FALSE
; }
90 bool DontUseEmbeddedBitmaps() const
91 { return maDevFontAttributes
.UseEmbeddedBitmap() == EMBEDDEDBITMAP_FALSE
; }
92 bool IsSymbolFont() const { return maDevFontAttributes
.IsSymbolFont(); }
93 const ImplFontAttributes
& GetFontAttributes() const { return maDevFontAttributes
; }
95 void AnnounceFont( ImplDevFontList
* );
97 int GetGlyphIndex( sal_UCS4 cChar
) const;
98 void CacheGlyphIndex( sal_UCS4 cChar
, int nGI
) const;
100 bool HasExtraKerning() const;
101 int GetExtraKernPairs( ImplKernPairData
** ) const;
102 int GetExtraGlyphKernValue( int nLeftGlyph
, int nRightGlyph
) const;
105 FT_FaceRec_
* maFaceFT
;
106 FtFontFile
* mpFontFile
;
109 const int mnSynthetic
;
112 ImplDevFontAttributes maDevFontAttributes
;
114 // cache unicode->glyphid mapping because looking it up is expensive
115 // TODO: change to hash_multimap when a use case requires a m:n mapping
116 typedef ::std::hash_map
<int,int> Int2IntMap
;
117 mutable Int2IntMap
* mpChar2Glyph
;
118 mutable Int2IntMap
* mpGlyph2Char
;
119 void InitHashes() const;
121 const ExtraKernInfo
* mpExtraKernInfo
;
124 // these two inlines are very important for performance
126 inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar
) const
130 Int2IntMap::const_iterator it
= mpChar2Glyph
->find( cChar
);
131 if( it
== mpChar2Glyph
->end() )
136 inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar
, int nIndex
) const
140 (*mpChar2Glyph
)[ cChar
] = nIndex
;
141 (*mpGlyph2Char
)[ nIndex
] = cChar
;
144 // -----------------------------------------------------------------------
146 class FreetypeManager
152 long AddFontDir( const String
& rUrlName
);
153 void AddFontFile( const rtl::OString
& rNormalizedName
,
154 int nFaceNum
, sal_IntPtr nFontId
, const ImplDevFontAttributes
&,
155 const ExtraKernInfo
* );
156 void AnnounceFonts( ImplDevFontList
* ) const;
157 void ClearFontList();
159 FreetypeServerFont
* CreateFont( const ImplFontSelectData
& );
162 typedef ::std::hash_map
<sal_IntPtr
,FtFontInfo
*> FontList
;
165 sal_IntPtr mnMaxFontId
;
166 sal_IntPtr mnNextFontId
;
169 // -----------------------------------------------------------------------
171 class FreetypeServerFont
: public ServerFont
174 FreetypeServerFont( const ImplFontSelectData
&, FtFontInfo
* );
175 virtual ~FreetypeServerFont();
177 virtual const ::rtl::OString
* GetFontFileName() const { return mpFontInfo
->GetFontFileName(); }
178 virtual int GetFontFaceNum() const { return mpFontInfo
->GetFaceNum(); }
179 virtual bool TestFont() const;
180 virtual void* GetFtFace() const;
181 virtual int GetLoadFlags() const { return (mnLoadFlags
& ~FT_LOAD_IGNORE_TRANSFORM
); }
182 virtual bool NeedsArtificialBold() const { return mbArtBold
; }
183 virtual bool NeedsArtificialItalic() const { return mbArtItalic
; }
185 virtual void FetchFontMetric( ImplFontMetricData
&, long& rFactor
) const;
187 virtual int GetGlyphIndex( sal_UCS4
) const;
188 int GetRawGlyphIndex( sal_UCS4
) const;
189 int FixupGlyphIndex( int nGlyphIndex
, sal_UCS4
) const;
191 virtual bool GetAntialiasAdvice( void ) const;
192 virtual bool GetGlyphBitmap1( int nGlyphIndex
, RawBitmap
& ) const;
193 virtual bool GetGlyphBitmap8( int nGlyphIndex
, RawBitmap
& ) const;
194 virtual bool GetGlyphOutline( int nGlyphIndex
, ::basegfx::B2DPolyPolygon
& ) const;
195 virtual int GetGlyphKernValue( int nLeftGlyph
, int nRightGlyph
) const;
196 virtual ULONG
GetKernPairs( ImplKernPairData
** ) const;
198 const unsigned char* GetTable( const char* pName
, ULONG
* pLength
)
199 { return mpFontInfo
->GetTable( pName
, pLength
); }
200 int GetEmUnits() const;
201 const FT_Size_Metrics
& GetMetricsFT() const { return maSizeFT
->metrics
; }
204 friend class GlyphCache
;
206 int ApplyGlyphTransform( int nGlyphFlags
, FT_GlyphRec_
*, bool ) const;
207 virtual void InitGlyphData( int nGlyphIndex
, GlyphData
& ) const;
208 virtual bool GetFontCodeRanges( CmapResult
& ) const;
209 bool ApplyGSUB( const ImplFontSelectData
& );
210 virtual ServerFontLayoutEngine
* GetLayoutEngine();
216 FtFontInfo
* mpFontInfo
;
219 FT_FaceRec_
* maFaceFT
;
220 FT_SizeRec_
* maSizeFT
;
227 typedef ::std::hash_map
<int,int> GlyphSubstitution
;
228 GlyphSubstitution maGlyphSubstitution
;
229 rtl_UnicodeToTextConverter maRecodeConverter
;
231 ServerFontLayoutEngine
* mpLayoutEngine
;
234 // -----------------------------------------------------------------------
236 class ImplFTSFontData
: public ImplFontData
239 FtFontInfo
* mpFtFontInfo
;
240 enum { IFTSFONT_MAGIC
= 0x1F150A1C };
243 ImplFTSFontData( FtFontInfo
*, const ImplDevFontAttributes
& );
245 FtFontInfo
* GetFtFontInfo() const { return mpFtFontInfo
; }
247 virtual ImplFontEntry
* CreateFontInstance( ImplFontSelectData
& ) const;
248 virtual ImplFontData
* Clone() const { return new ImplFTSFontData( *this ); }
249 virtual sal_IntPtr
GetFontId() const { return mpFtFontInfo
->GetFontId(); }
251 static bool CheckFontData( const ImplFontData
& r
) { return r
.CheckMagic( IFTSFONT_MAGIC
); }
254 // -----------------------------------------------------------------------
256 #endif // _SV_GCACHFTYP_HXX