xref: /aoo41x/main/vcl/source/glyphs/gcach_ftyp.hxx (revision 248a599f)
10d63794cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
30d63794cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40d63794cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50d63794cSAndrew Rist  * distributed with this work for additional information
60d63794cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70d63794cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
80d63794cSAndrew Rist  * "License"); you may not use this file except in compliance
90d63794cSAndrew Rist  * with the License.  You may obtain a copy of the License at
100d63794cSAndrew Rist  *
110d63794cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
120d63794cSAndrew Rist  *
130d63794cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
140d63794cSAndrew Rist  * software distributed under the License is distributed on an
150d63794cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160d63794cSAndrew Rist  * KIND, either express or implied.  See the License for the
170d63794cSAndrew Rist  * specific language governing permissions and limitations
180d63794cSAndrew Rist  * under the License.
190d63794cSAndrew Rist  *
200d63794cSAndrew Rist  *************************************************************/
210d63794cSAndrew Rist 
220d63794cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SV_GCACHFTYP_HXX
25cdf0e10cSrcweir #define _SV_GCACHFTYP_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <glyphcache.hxx>
28cdf0e10cSrcweir #include <rtl/textcvt.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <ft2build.h>
31cdf0e10cSrcweir #include FT_FREETYPE_H
32cdf0e10cSrcweir 
33cdf0e10cSrcweir class FreetypeServerFont;
34cdf0e10cSrcweir struct FT_GlyphRec_;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // -----------------------------------------------------------------------
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // FtFontFile has the responsibility that a font file is only mapped once.
39cdf0e10cSrcweir // (#86621#) the old directly ft-managed solution caused it to be mapped
40cdf0e10cSrcweir // in up to nTTC*nSizes*nOrientation*nSynthetic times
41cdf0e10cSrcweir class FtFontFile
42cdf0e10cSrcweir {
43cdf0e10cSrcweir public:
44cdf0e10cSrcweir     static FtFontFile*      FindFontFile( const ::rtl::OString& rNativeFileName );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     bool                    Map();
47cdf0e10cSrcweir     void                    Unmap();
48cdf0e10cSrcweir 
GetBuffer() const49cdf0e10cSrcweir     const unsigned char*    GetBuffer() const { return mpFileMap; }
GetFileSize() const50cdf0e10cSrcweir     int                     GetFileSize() const { return mnFileSize; }
GetFileName() const51cdf0e10cSrcweir     const ::rtl::OString*   GetFileName() const { return &maNativeFileName; }
GetLangBoost() const52cdf0e10cSrcweir     int                     GetLangBoost() const { return mnLangBoost; }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir private:
55cdf0e10cSrcweir                             FtFontFile( const ::rtl::OString& rNativeFileName );
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     const ::rtl::OString    maNativeFileName;
58cdf0e10cSrcweir     const unsigned char*    mpFileMap;
59cdf0e10cSrcweir     int                     mnFileSize;
60cdf0e10cSrcweir     int                     mnRefCount;
61cdf0e10cSrcweir     int                     mnLangBoost;
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // -----------------------------------------------------------------------
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // FtFontInfo corresponds to an unscaled font face
67cdf0e10cSrcweir class FtFontInfo
68cdf0e10cSrcweir {
69cdf0e10cSrcweir public:
70cdf0e10cSrcweir                            FtFontInfo( const ImplDevFontAttributes&,
71cdf0e10cSrcweir                                const ::rtl::OString& rNativeFileName,
72cdf0e10cSrcweir                                int nFaceNum, sal_IntPtr nFontId, int nSynthetic,
73cdf0e10cSrcweir                                 const ExtraKernInfo* );
74cdf0e10cSrcweir                           ~FtFontInfo();
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     const unsigned char*  GetTable( const char*, sal_uLong* pLength=0 ) const;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     FT_FaceRec_*          GetFaceFT();
79cdf0e10cSrcweir     void                  ReleaseFaceFT( FT_FaceRec_* );
80cdf0e10cSrcweir 
GetFontFileName() const81cdf0e10cSrcweir     const ::rtl::OString* GetFontFileName() const   { return mpFontFile->GetFileName(); }
GetFaceNum() const82cdf0e10cSrcweir     int                   GetFaceNum() const        { return mnFaceNum; }
GetSynthetic() const83cdf0e10cSrcweir     int                   GetSynthetic() const      { return mnSynthetic; }
GetFontId() const84cdf0e10cSrcweir     sal_IntPtr            GetFontId() const         { return mnFontId; }
IsSymbolFont() const85cdf0e10cSrcweir     bool                  IsSymbolFont() const      { return maDevFontAttributes.IsSymbolFont(); }
GetFontAttributes() const86cdf0e10cSrcweir     const ImplFontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     void                  AnnounceFont( ImplDevFontList* );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     int                   GetGlyphIndex( sal_UCS4 cChar ) const;
91cdf0e10cSrcweir     void                  CacheGlyphIndex( sal_UCS4 cChar, int nGI ) const;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     bool                  GetFontCodeRanges( CmapResult& ) const;
94cdf0e10cSrcweir     const ImplFontCharMap* GetImplFontCharMap( void );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     bool                  HasExtraKerning() const;
97cdf0e10cSrcweir     int                   GetExtraKernPairs( ImplKernPairData** ) const;
98cdf0e10cSrcweir     int                   GetExtraGlyphKernValue( int nLeftGlyph, int nRightGlyph ) const;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir private:
101cdf0e10cSrcweir     FT_FaceRec_*    maFaceFT;
102cdf0e10cSrcweir     FtFontFile*     mpFontFile;
103cdf0e10cSrcweir     const int       mnFaceNum;
104cdf0e10cSrcweir     int             mnRefCount;
105cdf0e10cSrcweir     const int       mnSynthetic;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     sal_IntPtr      mnFontId;
108cdf0e10cSrcweir     ImplDevFontAttributes maDevFontAttributes;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     const ImplFontCharMap* mpFontCharMap;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     // cache unicode->glyphid mapping because looking it up is expensive
113cdf0e10cSrcweir     // TODO: change to hash_multimap when a use case requires a m:n mapping
114cdf0e10cSrcweir     typedef ::std::hash_map<int,int> Int2IntMap;
115cdf0e10cSrcweir     mutable Int2IntMap* mpChar2Glyph;
116cdf0e10cSrcweir     mutable Int2IntMap* mpGlyph2Char;
117cdf0e10cSrcweir     void InitHashes() const;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     const ExtraKernInfo* mpExtraKernInfo;
120cdf0e10cSrcweir };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // these two inlines are very important for performance
123cdf0e10cSrcweir 
GetGlyphIndex(sal_UCS4 cChar) const124cdf0e10cSrcweir inline int FtFontInfo::GetGlyphIndex( sal_UCS4 cChar ) const
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     if( !mpChar2Glyph )
127cdf0e10cSrcweir         return -1;
128cdf0e10cSrcweir     Int2IntMap::const_iterator it = mpChar2Glyph->find( cChar );
129cdf0e10cSrcweir     if( it == mpChar2Glyph->end() )
130cdf0e10cSrcweir         return -1;
131cdf0e10cSrcweir     return it->second;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
CacheGlyphIndex(sal_UCS4 cChar,int nIndex) const134cdf0e10cSrcweir inline void FtFontInfo::CacheGlyphIndex( sal_UCS4 cChar, int nIndex ) const
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     if( !mpChar2Glyph )
137cdf0e10cSrcweir         InitHashes();
138cdf0e10cSrcweir     (*mpChar2Glyph)[ cChar ] = nIndex;
139cdf0e10cSrcweir     (*mpGlyph2Char)[ nIndex ] = cChar;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir // -----------------------------------------------------------------------
143cdf0e10cSrcweir 
144cdf0e10cSrcweir class FreetypeManager
145cdf0e10cSrcweir {
146cdf0e10cSrcweir public:
147cdf0e10cSrcweir                         FreetypeManager();
148cdf0e10cSrcweir                         ~FreetypeManager();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     long                AddFontDir( const String& rUrlName );
151cdf0e10cSrcweir     void                AddFontFile( const rtl::OString& rNormalizedName,
152cdf0e10cSrcweir                             int nFaceNum, sal_IntPtr nFontId, const ImplDevFontAttributes&,
153cdf0e10cSrcweir                             const ExtraKernInfo* );
154cdf0e10cSrcweir     void                AnnounceFonts( ImplDevFontList* ) const;
155cdf0e10cSrcweir     void                ClearFontList();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     FreetypeServerFont* CreateFont( const ImplFontSelectData& );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir private:
160cdf0e10cSrcweir     typedef ::std::hash_map<sal_IntPtr,FtFontInfo*> FontList;
161cdf0e10cSrcweir     FontList            maFontList;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     sal_IntPtr          mnMaxFontId;
164cdf0e10cSrcweir     sal_IntPtr          mnNextFontId;
165cdf0e10cSrcweir };
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // -----------------------------------------------------------------------
168cdf0e10cSrcweir 
169cdf0e10cSrcweir class FreetypeServerFont : public ServerFont
170cdf0e10cSrcweir {
171cdf0e10cSrcweir public:
172cdf0e10cSrcweir                                 FreetypeServerFont( const ImplFontSelectData&, FtFontInfo* );
173cdf0e10cSrcweir     virtual                     ~FreetypeServerFont();
174cdf0e10cSrcweir 
GetFontFileName() const175cdf0e10cSrcweir     virtual const ::rtl::OString* GetFontFileName() const { return mpFontInfo->GetFontFileName(); }
GetFontFaceNum() const176cdf0e10cSrcweir     virtual int                 GetFontFaceNum() const { return mpFontInfo->GetFaceNum(); }
177cdf0e10cSrcweir     virtual bool                TestFont() const;
178cdf0e10cSrcweir     virtual void*               GetFtFace() const;
179cdf0e10cSrcweir     virtual void                SetFontOptions( const ImplFontOptions&);
GetLoadFlags() const180cdf0e10cSrcweir     virtual int                 GetLoadFlags() const { return (mnLoadFlags & ~FT_LOAD_IGNORE_TRANSFORM); }
NeedsArtificialBold() const181cdf0e10cSrcweir     virtual bool                NeedsArtificialBold() const { return mbArtBold; }
NeedsArtificialItalic() const182cdf0e10cSrcweir     virtual bool                NeedsArtificialItalic() const { return mbArtItalic; }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     virtual void                FetchFontMetric( ImplFontMetricData&, long& rFactor ) const;
185cdf0e10cSrcweir     virtual const ImplFontCharMap* GetImplFontCharMap( void ) const;
186cdf0e10cSrcweir 
187*248a599fSHerbert Dürr     virtual sal_GlyphId         GetGlyphIndex( sal_UCS4 ) const;
188*248a599fSHerbert Dürr     sal_GlyphId                 GetRawGlyphIndex( sal_UCS4 ) const;
189*248a599fSHerbert Dürr     sal_GlyphId                 FixupGlyphIndex( sal_GlyphId, sal_UCS4 ) const;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     virtual bool                GetAntialiasAdvice( void ) const;
192*248a599fSHerbert Dürr     virtual bool                GetGlyphBitmap1( sal_GlyphId, RawBitmap& ) const;
193*248a599fSHerbert Dürr     virtual bool                GetGlyphBitmap8( sal_GlyphId, RawBitmap& ) const;
194*248a599fSHerbert Dürr     virtual bool                GetGlyphOutline( sal_GlyphId, ::basegfx::B2DPolyPolygon& ) const;
195cdf0e10cSrcweir     virtual int                 GetGlyphKernValue( int nLeftGlyph, int nRightGlyph ) const;
196cdf0e10cSrcweir     virtual sal_uLong               GetKernPairs( ImplKernPairData** ) const;
197cdf0e10cSrcweir 
GetTable(const char * pName,sal_uLong * pLength)198cdf0e10cSrcweir     const unsigned char*        GetTable( const char* pName, sal_uLong* pLength )
199cdf0e10cSrcweir                                 { return mpFontInfo->GetTable( pName, pLength ); }
200cdf0e10cSrcweir     int                         GetEmUnits() const;
GetMetricsFT() const201cdf0e10cSrcweir     const FT_Size_Metrics&      GetMetricsFT() const { return maSizeFT->metrics; }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir protected:
204cdf0e10cSrcweir     friend class GlyphCache;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     int                         ApplyGlyphTransform( int nGlyphFlags, FT_GlyphRec_*, bool ) const;
207*248a599fSHerbert Dürr     virtual void                InitGlyphData( sal_GlyphId, GlyphData& ) const;
208cdf0e10cSrcweir     bool                        ApplyGSUB( const ImplFontSelectData& );
209cdf0e10cSrcweir     virtual ServerFontLayoutEngine* GetLayoutEngine();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir private:
212cdf0e10cSrcweir     int                         mnWidth;
213cdf0e10cSrcweir     int                         mnPrioEmbedded;
214cdf0e10cSrcweir     int                         mnPrioAntiAlias;
215cdf0e10cSrcweir     int                         mnPrioAutoHint;
216cdf0e10cSrcweir     FtFontInfo*                 mpFontInfo;
217cdf0e10cSrcweir     FT_Int                      mnLoadFlags;
218cdf0e10cSrcweir     double                      mfStretch;
219cdf0e10cSrcweir     FT_FaceRec_*                maFaceFT;
220cdf0e10cSrcweir     FT_SizeRec_*                maSizeFT;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     bool                        mbFaceOk;
223cdf0e10cSrcweir     bool			mbArtItalic;
224cdf0e10cSrcweir     bool			mbArtBold;
225cdf0e10cSrcweir     bool			mbUseGamma;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     typedef ::std::hash_map<int,int> GlyphSubstitution;
228cdf0e10cSrcweir     GlyphSubstitution           maGlyphSubstitution;
229cdf0e10cSrcweir     rtl_UnicodeToTextConverter  maRecodeConverter;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     ServerFontLayoutEngine*     mpLayoutEngine;
232cdf0e10cSrcweir };
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // -----------------------------------------------------------------------
235cdf0e10cSrcweir 
236cdf0e10cSrcweir class ImplFTSFontData : public ImplFontData
237cdf0e10cSrcweir {
238cdf0e10cSrcweir private:
239cdf0e10cSrcweir     FtFontInfo*             mpFtFontInfo;
240cdf0e10cSrcweir     enum { IFTSFONT_MAGIC = 0x1F150A1C };
241cdf0e10cSrcweir 
242cdf0e10cSrcweir public:
243cdf0e10cSrcweir                             ImplFTSFontData( FtFontInfo*, const ImplDevFontAttributes& );
244cdf0e10cSrcweir 
GetFtFontInfo() const245cdf0e10cSrcweir     FtFontInfo*             GetFtFontInfo() const { return mpFtFontInfo; }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     virtual ImplFontEntry*  CreateFontInstance( ImplFontSelectData& ) const;
Clone() const248cdf0e10cSrcweir     virtual ImplFontData*   Clone() const   { return new ImplFTSFontData( *this ); }
GetFontId() const249cdf0e10cSrcweir     virtual sal_IntPtr      GetFontId() const { return mpFtFontInfo->GetFontId(); }
250cdf0e10cSrcweir 
CheckFontData(const ImplFontData & r)251cdf0e10cSrcweir     static bool             CheckFontData( const ImplFontData& r ) { return r.CheckMagic( IFTSFONT_MAGIC ); }
252cdf0e10cSrcweir };
253cdf0e10cSrcweir 
254cdf0e10cSrcweir // -----------------------------------------------------------------------
255cdf0e10cSrcweir 
256cdf0e10cSrcweir #endif // _SV_GCACHFTYP_HXX
257