Back to index

lightning-sunbird  0.9+nobinonly
nsFreeType.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsFreeType_h__
00041 #define nsFreeType_h__
00042 
00043 #include "gfx-config.h"
00044 #if (defined(MOZ_ENABLE_FREETYPE2))
00045 
00046 #include "nspr.h"
00047 #include "nsHashtable.h"
00048 #include "nsICharsetConverterManager.h"
00049 #include "nsIFontCatalogService.h"
00050 #include <ft2build.h>
00051 #include FT_FREETYPE_H
00052 #include FT_CACHE_H
00053 #include FT_CACHE_IMAGE_H
00054 #include FT_TRUETYPE_TABLES_H
00055 #include "nsIFreeType2.h"
00056 
00057 typedef struct FT_FaceRec_*  FT_Face;
00058 
00059 typedef struct {
00060   const char   *mFontFileName;
00061   time_t        mMTime;
00062   PRUint32      mFlags;
00063   const char   *mFontType;
00064   int           mFaceIndex;
00065   int           mNumFaces;
00066   const char   *mFamilyName;
00067   const char   *mStyleName;
00068   FT_UShort     mWeight;
00069   FT_UShort     mWidth;
00070   int           mNumGlyphs;
00071   int           mNumUsableGlyphs;
00072   FT_Long       mFaceFlags;
00073   FT_Long       mStyleFlags;
00074   FT_Long       mCodePageRange1;
00075   FT_Long       mCodePageRange2;
00076   char          mVendorID[5];
00077   const char   *mFoundryName;
00078   int           mNumEmbeddedBitmaps;
00079   int          *mEmbeddedBitmapHeights;
00080   PRUint16     *mCCMap;       // compressed char map
00081 } nsFontCatalogEntry;
00082 
00083 #define FCE_FLAGS_ISVALID    0x01
00084 #define FCE_FLAGS_UNICODE    0x02
00085 #define FCE_FLAGS_SYMBOL     0x04
00086 #define FCE_FLAGS_SURROGATE  0x08
00087 #define FREE_IF(x) if(x) free((void*)x)
00088 
00089 typedef struct {
00090   const char             *mConverterName;
00091   PRUint8                 mCmapPlatformID;
00092   PRUint8                 mCmapEncoding;
00093   nsIUnicodeEncoder*      mConverter;
00094 } nsTTFontEncoderInfo;
00095 
00096 typedef struct nsTTFontFamilyEncoderInfo {
00097   const char             *mFamilyName;
00098   nsTTFontEncoderInfo    *mEncodingInfo;
00099 } nsTTFontFamilyEncoderInfo;
00100 
00101 typedef struct {
00102   unsigned long bit;
00103   const char *charsetName;
00104 } nsulCodePageRangeCharSetName;
00105 
00106 //
00107 // the FreeType2 function type declarations
00108 //
00109 typedef FT_Error (*FT_Done_Face_t)(FT_Face);
00110 typedef FT_Error (*FT_Done_FreeType_t)(FT_Library);
00111 typedef FT_Error (*FT_Done_Glyph_t)(FT_Glyph);
00112 typedef FT_Error (*FT_Get_Char_Index_t)(FT_Face, FT_ULong);
00113 typedef FT_Error (*FT_Get_Glyph_t)(FT_GlyphSlot, FT_Glyph*);
00114 typedef void*    (*FT_Get_Sfnt_Table_t)(FT_Face, FT_Sfnt_Tag);
00115 typedef FT_Error (*FT_Glyph_Get_CBox_t)(FT_Glyph, FT_UInt, FT_BBox*);
00116 typedef FT_Error (*FT_Init_FreeType_t)(FT_Library*);
00117 typedef FT_Error (*FT_Load_Glyph_t)(FT_Face, FT_UInt, FT_Int);
00118 typedef FT_Error (*FT_Outline_Decompose_t)
00119                       (FT_Outline*, const FT_Outline_Funcs*, void*);
00120 typedef FT_Error (*FT_New_Face_t)(FT_Library, const char*, FT_Long, FT_Face*);
00121 typedef FT_Error (*FT_Set_Charmap_t)(FT_Face face, FT_CharMap  charmap);
00122 typedef FT_Error (*FTC_Image_Cache_Lookup_t)
00123                       (FTC_Image_Cache, FTC_Image_Desc*, FT_UInt, FT_Glyph*);
00124 typedef FT_Error (*FTC_Manager_Lookup_Size_t)
00125                       (FTC_Manager, FTC_Font, FT_Face*, FT_Size*);
00126 typedef FT_Error (*FTC_Manager_Done_t)(FTC_Manager);
00127 typedef FT_Error (*FTC_Manager_New_t)(FT_Library, FT_UInt, FT_UInt, FT_ULong,
00128                        FTC_Face_Requester, FT_Pointer, FTC_Manager*);
00129 typedef FT_Error (*FTC_Image_Cache_New_t)(FTC_Manager, FTC_Image_Cache*);
00130 // #ifdef MOZ_SVG
00131 typedef FT_Error (*FT_Glyph_Transform_t)(FT_Glyph, FT_Matrix*, FT_Vector*);
00132 typedef FT_Error (*FT_Get_Kerning_t)
00133                       (FT_Face, FT_UInt, FT_UInt, FT_UInt, FT_Vector*);
00134 typedef FT_Error (*FT_Glyph_Copy_t)(FT_Glyph, FT_Glyph*);
00135 typedef FT_Error (*FT_Glyph_To_Bitmap_t)
00136                       (FT_Glyph*, FT_Render_Mode, FT_Vector*, FT_Bool);
00137 // #endif
00138 
00139 typedef FT_ULong (*FT_Get_First_Char_t)(FT_Face, FT_UInt*);
00140 typedef FT_ULong (*FT_Get_Next_Char_t)(FT_Face, FT_ULong, FT_UInt*);
00141 
00142 class nsFreeTypeFace;
00143 
00144 nsFreeTypeFace * nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce);
00145 
00146 typedef struct {
00147   const char *FuncName;
00148   long  FuncOffset;
00149   const PRBool Required;
00150 } FtFuncList;
00151 
00152 // class nsFreeType class definition
00153 class nsFreeType2 : nsIFreeType2 {
00154   NS_DECL_ISUPPORTS
00155 
00156 public:
00157   void FreeGlobals();
00158   nsresult Init();
00159   virtual ~nsFreeType2();
00160 
00161   NS_DECL_NSIFREETYPE2
00162 
00163   // these belong in nsFT2FontCatalog
00164   static PRUint16*   GetCCMap(nsFontCatalogEntry *aFce);
00165   static const char* GetRange1CharSetName(unsigned long aBit);
00166   static const char* GetRange2CharSetName(unsigned long aBit);
00167   static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(const char *);
00168 
00169 protected:
00170   // run time loaded function pointers
00171   FT_Done_Face_t            nsFT_Done_Face;
00172   FT_Done_FreeType_t        nsFT_Done_FreeType;
00173   FT_Done_Glyph_t           nsFT_Done_Glyph;
00174   FT_Get_Char_Index_t       nsFT_Get_Char_Index;
00175   FT_Get_Glyph_t            nsFT_Get_Glyph;
00176   FT_Get_Sfnt_Table_t       nsFT_Get_Sfnt_Table;
00177   FT_Glyph_Get_CBox_t       nsFT_Glyph_Get_CBox;
00178   FT_Init_FreeType_t        nsFT_Init_FreeType;
00179   FT_Load_Glyph_t           nsFT_Load_Glyph;
00180   FT_New_Face_t             nsFT_New_Face;
00181   FT_Outline_Decompose_t    nsFT_Outline_Decompose;
00182   FT_Set_Charmap_t          nsFT_Set_Charmap;
00183   FTC_Image_Cache_Lookup_t  nsFTC_Image_Cache_Lookup;
00184   FTC_Manager_Lookup_Size_t nsFTC_Manager_Lookup_Size;
00185   FTC_Manager_Done_t        nsFTC_Manager_Done;
00186   FTC_Manager_New_t         nsFTC_Manager_New;
00187   FTC_Image_Cache_New_t     nsFTC_Image_Cache_New;
00188 // #ifdef MOZ_SVG
00189   FT_Glyph_Transform_t      nsFT_Glyph_Transform;
00190   FT_Get_Kerning_t          nsFT_Get_Kerning;
00191   FT_Glyph_Copy_t           nsFT_Glyph_Copy;
00192   FT_Glyph_To_Bitmap_t      nsFT_Glyph_To_Bitmap;
00193 // #endif
00194   FT_Get_First_Char_t       nsFT_Get_First_Char;
00195   FT_Get_Next_Char_t        nsFT_Get_Next_Char;
00196 
00197   // this array needs to be big enough to hold all the function pointers
00198   // plus one extra for the null at the end
00199 // #ifdef MOZ_SVG
00200   static FtFuncList FtFuncs[24];
00201 // #else
00202 //  static FtFuncList FtFuncs[20];
00203 // #endif
00204   
00205 protected:
00206   PRBool mEnableFreeType2;
00207   char*  mFreeType2SharedLibraryName;
00208 
00209 public:
00210   // these belong in the nsFontFreeType code
00211   static PRBool  gFreeType2Autohinted;
00212   static PRBool  gFreeType2Unhinted;
00213   static PRUint8 gAATTDarkTextMinValue;
00214   static double  gAATTDarkTextGain;
00215   static PRInt32 gAntiAliasMinimum;
00216   static PRInt32 gEmbeddedBitmapMaximumHeight;
00217   static PRBool  gHasExtFunc;
00218 
00219 protected:
00220   void ClearGlobals();
00221   void ClearFunctions();
00222   PRBool InitLibrary();
00223   PRBool LoadSharedLib();
00224   void UnloadSharedLib();
00225 
00226   // this belongs in nsFT2FontCatalog
00227   static nsICharsetConverterManager* GetCharSetManager();
00228 
00229   PRLibrary      *mSharedLib;
00230   FT_Library      mFreeTypeLibrary;
00231   FTC_Manager     mFTCacheManager;
00232   FTC_Image_Cache mImageCache;
00233 
00234   static nsHashtable   *sFontFamilies;
00235   static nsHashtable   *sRange1CharSetNames;
00236   static nsHashtable   *sRange2CharSetNames;
00237   static nsICharsetConverterManager* sCharSetManager;
00238 };
00239 
00240 /* this simple record is used to model a given `installed' face */
00241 class nsFreeTypeFace : public nsITrueTypeFontCatalogEntry {
00242 public:
00243   NS_DECL_ISUPPORTS
00244   NS_DECL_NSITRUETYPEFONTCATALOGENTRY
00245   
00246   nsFreeTypeFace();
00247   virtual ~nsFreeTypeFace();
00248   virtual nsresult Init(nsFontCatalogEntry *aFce);
00249   /* additional members */
00250   NS_IMETHODIMP GetFontCatalogType(PRUint16 *aFontCatalogType);
00251 
00252   static PRBool FreeFace(nsHashKey* aKey, void* aData, void* aClosure);
00253   const char *GetFilename()
00254                   { return mFce->mFontFileName; }
00255   int *GetEmbeddedBitmapHeights()
00256                   { return mFce->mEmbeddedBitmapHeights; } ;
00257   int GetFaceIndex()
00258                   { return mFce->mFaceIndex; }
00259   int GetNumEmbeddedBitmaps()
00260                   { return mFce->mNumEmbeddedBitmaps; } ;
00261   PRUint16 *GetCCMap();
00262   nsFontCatalogEntry* GetFce() { return mFce; };
00263 
00264   PRBool mHasExtendFuncs;
00265 
00266 protected:
00267   nsFontCatalogEntry *mFce;
00268   PRUint16           *mCCMap;
00269 
00270 };
00271 
00272 #endif /* MOZ_ENABLE_FREETYPE2 */
00273 
00274 /*
00275  * Defines for the TrueType codepage bits.
00276  * Used as a hint for the languages supported in a TrueType font.
00277  */
00278 
00279 /*
00280  * ulCodePageRange1
00281  */
00282 #define TT_OS2_CPR1_LATIN1       (0x00000001) /* Latin 1                     */
00283 #define TT_OS2_CPR1_LATIN2       (0x00000002) /* Latin 2: Eastern Europe     */
00284 #define TT_OS2_CPR1_CYRILLIC     (0x00000004) /* Cyrillic                    */
00285 #define TT_OS2_CPR1_GREEK        (0x00000008) /* Greek                       */
00286 #define TT_OS2_CPR1_TURKISH      (0x00000010) /* Turkish                     */
00287 #define TT_OS2_CPR1_HEBREW       (0x00000020) /* Hebrew                      */
00288 #define TT_OS2_CPR1_ARABIC       (0x00000040) /* Arabic                      */
00289 #define TT_OS2_CPR1_BALTIC       (0x00000080) /* Windows Baltic              */
00290 #define TT_OS2_CPR1_VIETNAMESE   (0x00000100) /* Vietnamese                  */
00291                                  /* 9-15     Reserved for Alternate ANSI     */
00292 #define TT_OS2_CPR1_THAI         (0x00010000) /* Thai                        */
00293 #define TT_OS2_CPR1_JAPANESE     (0x00020000) /* JIS/Japan                   */
00294 #define TT_OS2_CPR1_CHINESE_SIMP (0x00040000) /* Chinese: Simplified         */
00295 #define TT_OS2_CPR1_KO_WANSUNG   (0x00080000) /* Korean Wansung              */
00296 #define TT_OS2_CPR1_CHINESE_TRAD (0x00100000) /* Chinese: Traditional        */
00297 #define TT_OS2_CPR1_KO_JOHAB     (0x00200000) /* Korean Johab                */
00298                                  /* 22-28    Reserved for Alternate ANSI&OEM */
00299 #define TT_OS2_CPR1_MAC_ROMAN    (0x20000000) /* Mac (US Roman)              */
00300 #define TT_OS2_CPR1_OEM          (0x40000000) /* OEM Character Set           */
00301 #define TT_OS2_CPR1_SYMBOL       (0x80000000) /* Symbol Character Set        */
00302 
00303 /*
00304  * ulCodePageRange2
00305  */                              /* 32-47    Reserved for OEM                */
00306 #define TT_OS2_CPR2_GREEK        (0x00010000) /* IBM Greek                   */
00307 #define TT_OS2_CPR2_RUSSIAN      (0x00020000) /* MS-DOS Russian              */
00308 #define TT_OS2_CPR2_NORDIC       (0x00040000) /* MS-DOS Nordic               */
00309 #define TT_OS2_CPR2_ARABIC       (0x00080000) /* Arabic                      */
00310 #define TT_OS2_CPR2_CA_FRENCH    (0x00100000) /* MS-DOS Canadian French      */
00311 #define TT_OS2_CPR2_HEBREW       (0x00200000) /* Hebrew                      */
00312 #define TT_OS2_CPR2_ICELANDIC    (0x00400000) /* MS-DOS Icelandic            */
00313 #define TT_OS2_CPR2_PORTUGESE    (0x00800000) /* MS-DOS Portuguese           */
00314 #define TT_OS2_CPR2_TURKISH      (0x01000000) /* IBM Turkish                 */
00315 #define TT_OS2_CPR2_CYRILLIC     (0x02000000)/*IBM Cyrillic; primarily Russian*/
00316 #define TT_OS2_CPR2_LATIN2       (0x04000000) /* Latin 2                     */
00317 #define TT_OS2_CPR2_BALTIC       (0x08000000) /* MS-DOS Baltic               */
00318 #define TT_OS2_CPR2_GREEK_437G   (0x10000000) /* Greek; former 437 G         */
00319 #define TT_OS2_CPR2_ARABIC_708   (0x20000000) /* Arabic; ASMO 708            */
00320 #define TT_OS2_CPR2_WE_LATIN1    (0x40000000) /* WE/Latin 1                  */
00321 #define TT_OS2_CPR2_US           (0x80000000) /* US                          */
00322 
00323 #endif