Back to index

lightning-sunbird  0.9+nobinonly
nsFreeType.cpp
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 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Brian Stell <bstell@netscape.com>
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 #include "math.h"
00041 #include "nsIPref.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIServiceManager.h"
00044 #include "nsICharRepresentable.h"
00045 #include "nsCompressedCharMap.h"
00046 #include "nsICharsetConverterManager.h"
00047 #include "nsIRenderingContext.h"
00048 #include "nsFreeType.h"
00049 
00050 #include <ft2build.h>
00051 #include FT_FREETYPE_H
00052 #include FT_GLYPH_H
00053 #include FT_TRUETYPE_TABLES_H
00054 #include FT_TRUETYPE_IDS_H
00055 
00056 # define FREETYPE_PRINTF(x) \
00057             PR_BEGIN_MACRO \
00058               if (gFreeTypeDebug) { \
00059                 printf x ; \
00060                 printf(", %s %d\n", __FILE__, __LINE__); \
00061               } \
00062             PR_END_MACRO
00063 
00064 PRUint32 gFreeTypeDebug = 0;
00065 
00066 //
00067 // these belong in nsFontFreeType
00068 //
00069 PRBool       nsFreeType2::gFreeType2Autohinted = PR_FALSE;
00070 PRBool       nsFreeType2::gFreeType2Unhinted = PR_TRUE;
00071 PRUint8      nsFreeType2::gAATTDarkTextMinValue = 64;
00072 double       nsFreeType2::gAATTDarkTextGain = 0.8;
00073 PRInt32      nsFreeType2::gAntiAliasMinimum = 8;
00074 PRInt32      nsFreeType2::gEmbeddedBitmapMaximumHeight = 1000000;
00075 nsHashtable* nsFreeType2::sFontFamilies = nsnull;
00076 nsHashtable* nsFreeType2::sRange1CharSetNames = nsnull;
00077 nsHashtable* nsFreeType2::sRange2CharSetNames = nsnull;
00078 nsICharsetConverterManager* nsFreeType2::sCharSetManager = nsnull;
00079 PRBool       nsFreeType2::gHasExtFunc = PR_TRUE;
00080 
00081 extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[];
00082 extern nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[];
00083 extern nsTTFontFamilyEncoderInfo    gFontFamilyEncoderInfo[];
00084 
00085 typedef int Error;
00086 
00087 /*FT_CALLBACK_DEF*/ FT_Error nsFreeTypeFaceRequester(FTC_FaceID, FT_Library, 
00088                                                  FT_Pointer, FT_Face*);
00089 static FT_Error nsFreeType2__DummyFunc();
00090 
00091 static nsHashtable* gFreeTypeFaces = nsnull;
00092 
00093 static NS_DEFINE_CID(kCharSetManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
00094 
00095 //
00096 // Define the FreeType2 functions we resolve at run time.
00097 // see the comment near nsFreeType2::DoneFace() for more info
00098 //
00099 #define NS_FT2_OFFSET(f) (long)&((nsFreeType2*)0)->f
00100 FtFuncList nsFreeType2::FtFuncs [] = {
00101   {"FT_Done_Face",            NS_FT2_OFFSET(nsFT_Done_Face),            PR_TRUE},
00102   {"FT_Done_FreeType",        NS_FT2_OFFSET(nsFT_Done_FreeType),        PR_TRUE},
00103   {"FT_Done_Glyph",           NS_FT2_OFFSET(nsFT_Done_Glyph),           PR_TRUE},
00104   {"FT_Get_Char_Index",       NS_FT2_OFFSET(nsFT_Get_Char_Index),       PR_TRUE},
00105   {"FT_Get_Glyph",            NS_FT2_OFFSET(nsFT_Get_Glyph),            PR_TRUE},
00106   {"FT_Get_Sfnt_Table",       NS_FT2_OFFSET(nsFT_Get_Sfnt_Table),       PR_TRUE},
00107   {"FT_Glyph_Get_CBox",       NS_FT2_OFFSET(nsFT_Glyph_Get_CBox),       PR_TRUE},
00108   {"FT_Init_FreeType",        NS_FT2_OFFSET(nsFT_Init_FreeType),        PR_TRUE},
00109   {"FT_Load_Glyph",           NS_FT2_OFFSET(nsFT_Load_Glyph),           PR_TRUE},
00110   {"FT_New_Face",             NS_FT2_OFFSET(nsFT_New_Face),             PR_TRUE},
00111   {"FT_Outline_Decompose",    NS_FT2_OFFSET(nsFT_Outline_Decompose),    PR_TRUE},
00112   {"FT_Set_Charmap",          NS_FT2_OFFSET(nsFT_Set_Charmap),          PR_TRUE},
00113   {"FTC_Image_Cache_Lookup",  NS_FT2_OFFSET(nsFTC_Image_Cache_Lookup),  PR_TRUE},
00114   {"FTC_Manager_Lookup_Size", NS_FT2_OFFSET(nsFTC_Manager_Lookup_Size), PR_TRUE},
00115   {"FTC_Manager_Done",        NS_FT2_OFFSET(nsFTC_Manager_Done),        PR_TRUE},
00116   {"FTC_Manager_New",         NS_FT2_OFFSET(nsFTC_Manager_New),         PR_TRUE},
00117   {"FTC_Image_Cache_New",     NS_FT2_OFFSET(nsFTC_Image_Cache_New),     PR_TRUE},
00118 // #ifdef MOZ_SVG
00119   {"FT_Glyph_Transform",      NS_FT2_OFFSET(nsFT_Glyph_Transform),      PR_TRUE},
00120   {"FT_Get_Kerning",          NS_FT2_OFFSET(nsFT_Get_Kerning),          PR_TRUE},
00121   {"FT_Glyph_Copy",           NS_FT2_OFFSET(nsFT_Glyph_Copy),           PR_TRUE},
00122   {"FT_Glyph_To_Bitmap",      NS_FT2_OFFSET(nsFT_Glyph_To_Bitmap),      PR_TRUE},
00123 // #endif
00124   {"FT_Get_First_Char",       NS_FT2_OFFSET(nsFT_Get_First_Char),       PR_FALSE},
00125   {"FT_Get_Next_Char",        NS_FT2_OFFSET(nsFT_Get_Next_Char),        PR_FALSE},
00126   {nsnull,                    0, 0}
00127 };
00128 
00129 nsTTFontEncoderInfo FEI_Adobe_Symbol_Encoding = {
00130   "Adobe-Symbol-Encoding", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull
00131 };
00132 nsTTFontEncoderInfo FEI_x_ttf_cmr = {
00133   "x-ttf-cmr", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull
00134 };
00135 nsTTFontEncoderInfo FEI_x_ttf_cmmi = {
00136   "x-ttf-cmmi", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull
00137 };
00138 nsTTFontEncoderInfo FEI_x_ttf_cmsy = {
00139   "x-ttf-cmsy", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull
00140 };
00141 nsTTFontEncoderInfo FEI_x_ttf_cmex = {
00142   "x-ttf-cmex", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull
00143 };
00144 nsTTFontEncoderInfo FEI_x_mathematica1 = {
00145   "x-mathematica1", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull
00146 };
00147 nsTTFontEncoderInfo FEI_x_mathematica2 = {
00148   "x-mathematica2", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull
00149 };
00150 nsTTFontEncoderInfo FEI_x_mathematica3 = {
00151   "x-mathematica3", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull
00152 };
00153 nsTTFontEncoderInfo FEI_x_mathematica4 = {
00154   "x-mathematica4", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull
00155 };
00156 nsTTFontEncoderInfo FEI_x_mathematica5 = {
00157   "x-mathematica5", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull
00158 };
00159 nsTTFontEncoderInfo FEI_x_mtextra = {
00160   "x-mtextra", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull
00161 };
00162 nsTTFontEncoderInfo FEI_windows_1252 = {
00163   "windows-1252", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull
00164 };
00165 
00166 
00168 //
00169 // class nsFreeType2 data/functions
00170 //
00172 
00173 NS_IMPL_ISUPPORTS1(nsFreeType2, nsIFreeType2)
00174 
00175 //
00176 // Since the Freetype2 library may not be available on the user's
00177 // system we cannot link directly to it otherwise the whole app would
00178 // fail to run on those systems.  Instead we access the FreeType2
00179 // functions via function pointers.
00180 //
00181 // If we can load the Freetype2 library with PR_LoadLIbrary we to load 
00182 // pointers to the Ft2 functions. If not, then the function pointers
00183 // point to a dummy function which always returns an error.
00184 //
00185  
00186 NS_IMETHODIMP
00187 nsFreeType2::DoneFace(FT_Face face)
00188 { 
00189   // call the FreeType2 function via the function pointer
00190   FT_Error error = nsFT_Done_Face(face);
00191   return error ? NS_ERROR_FAILURE : NS_OK;
00192 } 
00193  
00194 NS_IMETHODIMP
00195 nsFreeType2::DoneFreeType(FT_Library library)
00196 { 
00197   // call the FreeType2 function via the function pointer
00198   FT_Error error = nsFT_Done_FreeType(library);
00199   return error ? NS_ERROR_FAILURE : NS_OK;
00200 } 
00201  
00202 NS_IMETHODIMP
00203 nsFreeType2::DoneGlyph(FT_Glyph glyph)
00204 { 
00205   // call the FreeType2 function via the function pointer
00206   nsFT_Done_Glyph(glyph);
00207   return NS_OK;
00208 } 
00209  
00210 NS_IMETHODIMP
00211 nsFreeType2::GetCharIndex(FT_Face face, FT_ULong charcode, FT_UInt *index)
00212 { 
00213   // call the FreeType2 function via the function pointer
00214   *index = nsFT_Get_Char_Index(face, charcode);
00215   return NS_OK;
00216 } 
00217 
00218 NS_IMETHODIMP
00219 nsFreeType2::GetGlyph(FT_GlyphSlot slot, FT_Glyph *glyph)
00220 { 
00221   // call the FreeType2 function via the function pointer
00222   FT_Error error = nsFT_Get_Glyph(slot, glyph);
00223   return error ? NS_ERROR_FAILURE : NS_OK;
00224 } 
00225  
00226 NS_IMETHODIMP
00227 nsFreeType2::GetSfntTable(FT_Face face, FT_Sfnt_Tag tag, void** table)
00228 { 
00229   // call the FreeType2 function via the function pointer
00230   *table = nsFT_Get_Sfnt_Table(face, tag);
00231   return NS_OK;
00232 } 
00233  
00234 NS_IMETHODIMP
00235 nsFreeType2::GlyphGetCBox(FT_Glyph glyph, FT_UInt mode, FT_BBox *bbox)
00236 { 
00237   // call the FreeType2 function via the function pointer
00238   nsFT_Glyph_Get_CBox(glyph, mode, bbox);
00239   return NS_OK;
00240 } 
00241  
00242 NS_IMETHODIMP
00243 nsFreeType2::InitFreeType(FT_Library *library)
00244 { 
00245   // call the FreeType2 function via the function pointer
00246   FT_Error error = nsFT_Init_FreeType(library);
00247   if (error)
00248   {
00249     FREETYPE_PRINTF(("\n\n*********\nFreeType initialization error = %d",
00250                          error));
00251     return NS_ERROR_FAILURE;
00252   }
00253   else return NS_OK;
00254 } 
00255  
00256 NS_IMETHODIMP
00257 nsFreeType2::LoadGlyph(FT_Face face, FT_UInt glyph, FT_Int flags)
00258 { 
00259   // call the FreeType2 function via the function pointer
00260   FT_Error error = nsFT_Load_Glyph(face, glyph, flags);
00261   return error ? NS_ERROR_FAILURE : NS_OK;
00262 } 
00263  
00264 NS_IMETHODIMP
00265 nsFreeType2::NewFace(FT_Library library, const char *path,
00266                          FT_Long face_index, FT_Face *face)
00267 { 
00268   // call the FreeType2 function via the function pointer
00269   FT_Error error = nsFT_New_Face(library, path, face_index, face);
00270   return error ? NS_ERROR_FAILURE : NS_OK;
00271 } 
00272  
00273 NS_IMETHODIMP
00274 nsFreeType2::OutlineDecompose(FT_Outline *outline,
00275                               const FT_Outline_Funcs *funcs, void *user)
00276 { 
00277   // call the FreeType2 function via the function pointer
00278   FT_Error error = nsFT_Outline_Decompose(outline, funcs, user);
00279   return error ? NS_ERROR_FAILURE : NS_OK;
00280 } 
00281  
00282 NS_IMETHODIMP
00283 nsFreeType2::SetCharmap(FT_Face face, FT_CharMap  charmap)
00284 { 
00285   // call the FreeType2 function via the function pointer
00286   FT_Error error = nsFT_Set_Charmap(face, charmap);
00287   return error ? NS_ERROR_FAILURE : NS_OK;
00288 } 
00289  
00290 NS_IMETHODIMP
00291 nsFreeType2::ImageCacheLookup(FTC_Image_Cache cache, FTC_Image_Desc *desc,
00292                               FT_UInt glyphID, FT_Glyph *glyph)
00293 { 
00294   // call the FreeType2 function via the function pointer
00295   FT_Error error = nsFTC_Image_Cache_Lookup(cache, desc, glyphID, glyph);
00296   return error ? NS_ERROR_FAILURE : NS_OK;
00297 } 
00298  
00299 NS_IMETHODIMP
00300 nsFreeType2::ManagerLookupSize(FTC_Manager manager, FTC_Font font,
00301                                FT_Face *face, FT_Size *size)
00302 { 
00303   // call the FreeType2 function via the function pointer
00304   FT_Error error = nsFTC_Manager_Lookup_Size(manager, font, face, size);
00305   return error ? NS_ERROR_FAILURE : NS_OK;
00306 } 
00307  
00308 NS_IMETHODIMP
00309 nsFreeType2::ManagerDone(FTC_Manager manager)
00310 { 
00311   // call the FreeType2 function via the function pointer
00312   nsFTC_Manager_Done(manager);
00313   return NS_OK;
00314 } 
00315  
00316 NS_IMETHODIMP
00317 nsFreeType2::ManagerNew(FT_Library library, FT_UInt max_faces,
00318                         FT_UInt max_sizes, FT_ULong max_bytes,
00319                         FTC_Face_Requester requester, FT_Pointer req_data,
00320                         FTC_Manager *manager)
00321 { 
00322   // call the FreeType2 function via the function pointer
00323   FT_Error error = nsFTC_Manager_New(library, max_faces, max_sizes, max_bytes,
00324                                      requester, req_data, manager);
00325   return error ? NS_ERROR_FAILURE : NS_OK;
00326 } 
00327  
00328 NS_IMETHODIMP
00329 nsFreeType2::ImageCacheNew(FTC_Manager manager, FTC_Image_Cache *cache)
00330 { 
00331   // call the FreeType2 function via the function pointer
00332   FT_Error error = nsFTC_Image_Cache_New(manager, cache);
00333   return error ? NS_ERROR_FAILURE : NS_OK;
00334 } 
00335 
00336 // #ifdef MOZ_SVG
00337 NS_IMETHODIMP
00338 nsFreeType2::GlyphTransform(FT_Glyph glyph, FT_Matrix * matrix, FT_Vector * delta)
00339 {
00340   // call the FreeType2 function via the function pointer
00341   FT_Error error = nsFT_Glyph_Transform(glyph, matrix, delta);
00342   return error ? NS_ERROR_FAILURE : NS_OK;
00343 }
00344 
00345 NS_IMETHODIMP
00346 nsFreeType2::GetKerning(FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph,
00347                         FT_UInt kern_mode, FT_Vector *akerning)
00348 {
00349   // call the FreeType2 function via the function pointer
00350   FT_Error error = nsFT_Get_Kerning(face, left_glyph, right_glyph,
00351                                     kern_mode, akerning);
00352   return error ? NS_ERROR_FAILURE : NS_OK;
00353 }
00354 
00355 NS_IMETHODIMP
00356 nsFreeType2::GlyphCopy(FT_Glyph source, FT_Glyph *target)
00357 {
00358   // call the FreeType2 function via the function pointer
00359   FT_Error error = nsFT_Glyph_Copy(source, target);
00360   return error ? NS_ERROR_FAILURE : NS_OK;
00361 }
00362 
00363 NS_IMETHODIMP
00364 nsFreeType2::GlyphToBitmap(FT_Glyph *the_glyph, FT_Render_Mode render_mode,
00365                            FT_Vector * origin, FT_Bool destroy)
00366 {
00367   // call the FreeType2 function via the function pointer
00368   FT_Error error = nsFT_Glyph_To_Bitmap(the_glyph, render_mode, origin, destroy);
00369   return error ? NS_ERROR_FAILURE : NS_OK;
00370 }
00371 
00372 // #endif
00373 
00374 NS_IMETHODIMP
00375 nsFreeType2::GetFirstChar(FT_Face face, FT_UInt *gindex, FT_ULong *charcode)
00376 { 
00377   // call the FreeType2 function via the function pointer
00378   *charcode = nsFT_Get_First_Char(face, gindex);
00379   return NS_OK;
00380 } 
00381 
00382 NS_IMETHODIMP
00383 nsFreeType2::GetNextChar(FT_Face face, FT_ULong charcode, FT_UInt *gindex, FT_ULong *ncharcode)
00384 { 
00385   // call the FreeType2 function via the function pointer
00386   *ncharcode = nsFT_Get_Next_Char(face, charcode, gindex);
00387   return NS_OK;
00388 } 
00389 
00390 NS_IMETHODIMP
00391 nsFreeType2::SupportsExtFunc(PRBool *res)
00392 { 
00393   *res = gHasExtFunc;
00394   return NS_OK;
00395 } 
00396  
00397 NS_IMETHODIMP
00398 nsFreeType2::GetImageCache(FTC_Image_Cache *aCache)
00399 {
00400   *aCache = mImageCache;
00401   return NS_OK;
00402 }
00403 
00404 NS_IMETHODIMP
00405 nsFreeType2::GetFTCacheManager(FTC_Manager *aManager)
00406 { 
00407   *aManager = mFTCacheManager;
00408   return NS_OK;
00409 } 
00410  
00411 NS_IMETHODIMP
00412 nsFreeType2::GetLibrary(FT_Library *aLibrary)
00413 { 
00414   *aLibrary = mFreeTypeLibrary;
00415   return NS_OK;
00416 } 
00417 
00418 void
00419 nsFreeType2::ClearFunctions()
00420 {
00421   FtFuncList *p;
00422   void *ptr = this;
00423   for (p=FtFuncs; p->FuncName; p++) {
00424     *((PRFuncPtr*)((char*)ptr+p->FuncOffset)) = 
00425                         (PRFuncPtr)&nsFreeType2__DummyFunc;
00426   }
00427 }
00428 
00429 void
00430 nsFreeType2::ClearGlobals()
00431 {
00432   mSharedLib = nsnull;
00433   mFreeTypeLibrary = nsnull;
00434   mFTCacheManager  = nsnull;
00435   mImageCache      = nsnull;
00436 }
00437 
00438 // I would like to make this a static member function but the compilier 
00439 // warning about converting a data pointer to a function pointer cannot
00440 // distinguish static member functions from static data members
00441 static FT_Error
00442 nsFreeType2__DummyFunc()
00443 {
00444   NS_ERROR("nsFreeType2__DummyFunc should never be called");
00445   return 1;
00446 }
00447 
00448 nsFreeType2::~nsFreeType2()
00449 {
00450   FreeGlobals();
00451 }
00452 
00453 void
00454 nsFreeType2::FreeGlobals()
00455 {
00456   if (mFreeType2SharedLibraryName) {
00457     free(mFreeType2SharedLibraryName);
00458     mFreeType2SharedLibraryName = nsnull;
00459   }
00460   if (gFreeTypeFaces) {
00461     gFreeTypeFaces->Reset(nsFreeTypeFace::FreeFace, nsnull);
00462     delete gFreeTypeFaces;
00463     gFreeTypeFaces = nsnull;
00464   }
00465   // mImageCache released by cache manager
00466   if (mFTCacheManager) {
00467     // use "this->" to make sure it is obivious we are calling the member func
00468     this->ManagerDone(mFTCacheManager);
00469     mFTCacheManager = nsnull;
00470   }
00471   if (mFreeTypeLibrary) {
00472     // use "this->" to make sure it is obivious we are calling the member func
00473     this->DoneFreeType(mFreeTypeLibrary);
00474     mFreeTypeLibrary = nsnull;
00475   }
00476   
00477   if (sRange1CharSetNames)
00478     delete sRange1CharSetNames;
00479   if (sRange2CharSetNames)
00480     delete sRange2CharSetNames;
00481   if (sFontFamilies)
00482     delete sFontFamilies;
00483   
00484   NS_IF_RELEASE(sCharSetManager);
00485   
00486   // release any encoders that were created
00487   int i;
00488   for (i=0; gFontFamilyEncoderInfo[i].mFamilyName; i++) {
00489     nsTTFontFamilyEncoderInfo *ffei = &gFontFamilyEncoderInfo[i];
00490     nsTTFontEncoderInfo *fei = ffei->mEncodingInfo;
00491     NS_IF_RELEASE(fei->mConverter);
00492   }
00493 
00494   UnloadSharedLib();
00495   ClearFunctions();
00496   ClearGlobals();
00497 }
00498 
00499 nsresult
00500 nsFreeType2::Init()
00501 {
00502   // set all the globals to default values
00503   ClearGlobals();
00504 
00505   nsulCodePageRangeCharSetName *crn = nsnull;
00506   nsTTFontFamilyEncoderInfo *ff = gFontFamilyEncoderInfo;
00507   nsCOMPtr<nsIPref> mPref = do_GetService(NS_PREF_CONTRACTID);
00508   
00509   if (!mPref) {
00510     FreeGlobals();
00511     return NS_ERROR_FAILURE;
00512   }
00513   nsresult rv;
00514 
00515   PRBool enable_freetype2 = PR_TRUE;
00516   rv = mPref->GetBoolPref("font.FreeType2.enable", &enable_freetype2);
00517   if (NS_SUCCEEDED(rv)) {
00518     mEnableFreeType2 = enable_freetype2;
00519     FREETYPE_PRINTF(("mEnableFreeType2 = %d", mEnableFreeType2));
00520   }
00521 
00522   rv = mPref->GetCharPref("font.freetype2.shared-library",
00523                           &mFreeType2SharedLibraryName);
00524   if (NS_FAILED(rv)) {
00525     enable_freetype2 = PR_FALSE;
00526     FREETYPE_PRINTF((
00527                   "mFreeType2SharedLibraryName missing, FreeType2 disabled"));
00528     mFreeType2SharedLibraryName = nsnull;
00529   }
00530 
00531   PRBool freetype2_autohinted = PR_FALSE;
00532   rv = mPref->GetBoolPref("font.FreeType2.autohinted", &freetype2_autohinted);
00533   if (NS_SUCCEEDED(rv)) {
00534     gFreeType2Autohinted = freetype2_autohinted;
00535     FREETYPE_PRINTF(("gFreeType2Autohinted = %d", gFreeType2Autohinted));
00536   }
00537   
00538   PRBool freetype2_unhinted = PR_TRUE;
00539   rv = mPref->GetBoolPref("font.FreeType2.unhinted", &freetype2_unhinted);
00540   if (NS_SUCCEEDED(rv)) {
00541     gFreeType2Unhinted = freetype2_unhinted;
00542     FREETYPE_PRINTF(("gFreeType2Unhinted = %d", gFreeType2Unhinted));
00543   }
00544 
00545   PRInt32 int_val = 0;
00546   rv = mPref->GetIntPref("font.scale.tt_bitmap.dark_text.min", &int_val);
00547   if (NS_SUCCEEDED(rv)) {
00548     gAATTDarkTextMinValue = int_val;
00549     FREETYPE_PRINTF(("gAATTDarkTextMinValue = %d", gAATTDarkTextMinValue));
00550   }
00551 
00552   nsXPIDLCString str;
00553   rv = mPref->GetCharPref("font.scale.tt_bitmap.dark_text.gain",
00554                            getter_Copies(str));
00555   if (NS_SUCCEEDED(rv)) {
00556     gAATTDarkTextGain = atof(str.get());
00557     FREETYPE_PRINTF(("gAATTDarkTextGain = %g", gAATTDarkTextGain));
00558   }
00559 
00560   PRInt32 antialias_minimum = 8;
00561   rv = mPref->GetIntPref("font.antialias.min", &antialias_minimum);
00562   if (NS_SUCCEEDED(rv)) {
00563     gAntiAliasMinimum = antialias_minimum;
00564     FREETYPE_PRINTF(("gAntiAliasMinimum = %d", gAntiAliasMinimum));
00565   }
00566 
00567   PRInt32 embedded_bitmaps_maximum = 1000000;
00568   rv = mPref->GetIntPref("font.embedded_bitmaps.max",&embedded_bitmaps_maximum);
00569   if (NS_SUCCEEDED(rv)) {
00570     gEmbeddedBitmapMaximumHeight = embedded_bitmaps_maximum;
00571     FREETYPE_PRINTF(("gEmbeddedBitmapMaximumHeight = %d",
00572                              gEmbeddedBitmapMaximumHeight));
00573   }
00574   
00575   if (NS_FAILED(rv)) {
00576     mEnableFreeType2 = PR_FALSE;
00577     mFreeType2SharedLibraryName = nsnull;
00578     gFreeType2Autohinted = PR_FALSE;
00579     gFreeType2Unhinted = PR_TRUE;
00580     gAATTDarkTextMinValue = 64;
00581     gAATTDarkTextGain = 0.8;
00582     gAntiAliasMinimum = 8;
00583     gEmbeddedBitmapMaximumHeight = 1000000;
00584   }
00585   
00586   mPref = nsnull;
00587   
00588   if (!InitLibrary()) {
00589     FreeGlobals();
00590     return NS_ERROR_OUT_OF_MEMORY;
00591   }
00592   gFreeTypeFaces = new nsHashtable();
00593   if (!gFreeTypeFaces) {
00594     FreeGlobals();
00595     return NS_ERROR_OUT_OF_MEMORY;
00596   }
00597 
00598   sRange1CharSetNames = new nsHashtable();
00599   if (!sRange1CharSetNames) {
00600     FreeGlobals();
00601     return NS_ERROR_OUT_OF_MEMORY;
00602   }
00603   crn = ulCodePageRange1CharSetNames;
00604   while (crn->charsetName) {
00605     char buf[32];
00606     sprintf(buf, "0x%08lx", crn->bit);
00607     nsCStringKey key(buf);
00608     sRange1CharSetNames->Put(&key, (void*)crn->charsetName);
00609     crn++;
00610   }
00611 
00612   sRange2CharSetNames = new nsHashtable();
00613   if (!sRange2CharSetNames) {
00614     FreeGlobals();
00615     return NS_ERROR_OUT_OF_MEMORY;
00616   }
00617   crn = ulCodePageRange2CharSetNames;
00618   while (crn->charsetName) {
00619     char buf[32];
00620     sprintf(buf, "0x%08lx", crn->bit);
00621     nsCStringKey key(buf);
00622     sRange2CharSetNames->Put(&key, (void*)crn->charsetName);
00623     crn++;
00624   }
00625 
00626   sFontFamilies = new nsHashtable();
00627   if (!sFontFamilies) {
00628     FreeGlobals();
00629     return NS_ERROR_OUT_OF_MEMORY;
00630   }
00631   while (ff->mFamilyName) {
00632     nsCAutoString name(ff->mFamilyName);
00633     ToLowerCase(name);
00634     nsCStringKey key(name);
00635     sFontFamilies->Put(&key, (void*)ff);
00636     ff++;
00637   }
00638 
00639   return NS_OK;
00640 }
00641 
00642 PRBool
00643 nsFreeType2::InitLibrary()
00644 {
00645 #ifdef MOZ_MATHML
00646   // do not yet support MathML
00647   // goto cleanup_and_return;
00648 #endif
00649 
00650   if (!mEnableFreeType2)
00651     return PR_FALSE;
00652 
00653   // since the library may not be available on any given system
00654   // failing to load is not considered a fatal error
00655   if (!LoadSharedLib())
00656     return PR_FALSE;
00657 
00658   // use "this->" to make sure it is obivious we are calling the member func
00659   nsresult rv = this->InitFreeType(&mFreeTypeLibrary);
00660   if (NS_FAILED(rv)) {
00661     mFreeTypeLibrary = nsnull;
00662     goto cleanup_and_return;
00663   }
00664   // use "this->" to make sure it is obivious we are calling the member func
00665   rv = this->ManagerNew(mFreeTypeLibrary, 0, 0, 0, nsFreeTypeFaceRequester,
00666                          this, &mFTCacheManager);
00667   NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create FreeType Cache manager");
00668   if (NS_FAILED(rv))
00669     goto cleanup_and_return;
00670   // use "this->" to make sure it is obivious we are calling the member func
00671   rv = this->ImageCacheNew(mFTCacheManager, &mImageCache);
00672   NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create FreeType image cache");
00673   if (NS_FAILED(rv))
00674     goto cleanup_and_return;
00675   return PR_TRUE;
00676 
00677 cleanup_and_return:
00678   // clean everything up but note that init was called
00679   FreeGlobals();
00680   return(PR_FALSE);
00681 }
00682 
00683 PRBool
00684 nsFreeType2::LoadSharedLib()
00685 {
00686   NS_ASSERTION(mSharedLib==nsnull, "library already loaded");
00687 
00688   if (!mFreeType2SharedLibraryName)
00689     return PR_FALSE;
00690   mSharedLib = PR_LoadLibrary(mFreeType2SharedLibraryName);
00691   // since the library may not be available on any given system
00692   // failing to load is not considered a fatal error
00693   if (!mSharedLib) {
00694     NS_WARNING("freetype library not found");
00695     return PR_FALSE;
00696   }
00697 
00698   // checking FT_Get_First_Char() and FT_Get_Next_Char() for fast lookup methods
00699   gHasExtFunc = PR_TRUE;
00700   FtFuncList *p;
00701   PRFuncPtr func;
00702   void *ptr = this;
00703   for (p=FtFuncs; p->FuncName; p++) {
00704     func = PR_FindFunctionSymbol(mSharedLib, p->FuncName);
00705     if (!func) {
00706       if (p->Required == PR_TRUE) {
00707         NS_WARNING("nsFreeType2::LoadSharedLib Error");
00708         ClearFunctions();
00709         return PR_FALSE;
00710       } else {
00711         // should not return, but disable fast lookup methods
00712         gHasExtFunc = PR_FALSE;
00713       }
00714     }
00715     *((PRFuncPtr*)((char*)ptr+p->FuncOffset)) = func;
00716   }
00717 
00718   return PR_TRUE;
00719 
00720 }
00721 
00722 void
00723 nsFreeType2::UnloadSharedLib()
00724 {
00725   if (mSharedLib)
00726     PR_UnloadLibrary(mSharedLib);
00727   mSharedLib = nsnull;
00728 }
00729 
00730 const char *
00731 nsFreeType2::GetRange1CharSetName(unsigned long aBit)
00732 {
00733   char buf[32];
00734   sprintf(buf, "0x%08lx", aBit);
00735   nsCStringKey key(buf);
00736   const char *charsetName = (const char *)sRange1CharSetNames->Get(&key);
00737   return charsetName;
00738 }
00739 
00740 const char *
00741 nsFreeType2::GetRange2CharSetName(unsigned long aBit)
00742 {
00743   char buf[32];
00744   sprintf(buf, "0x%08lx", aBit);
00745   nsCStringKey key(buf);
00746   const char *charsetName = (const char *)sRange2CharSetNames->Get(&key);
00747   return charsetName;
00748 }
00749 
00750 nsTTFontFamilyEncoderInfo*
00751 nsFreeType2::GetCustomEncoderInfo(const char * aFamilyName)
00752 {
00753   if (!sFontFamilies)
00754     return nsnull;
00755 
00756   nsTTFontFamilyEncoderInfo *ffei;
00757   nsCAutoString name(aFamilyName);
00758   ToLowerCase(name);
00759   nsCStringKey key(name);
00760   ffei = (nsTTFontFamilyEncoderInfo*)sFontFamilies->Get(&key);
00761   if (!ffei)
00762     return nsnull;
00763 
00764   // init the converter
00765   if (!ffei->mEncodingInfo->mConverter) {
00766     nsTTFontEncoderInfo *fei = ffei->mEncodingInfo;
00767     //
00768     // build the converter
00769     //
00770     nsICharsetConverterManager* charSetManager = GetCharSetManager();
00771     if (!charSetManager)
00772       return nsnull;
00773     nsresult res;
00774     res = charSetManager->GetUnicodeEncoderRaw(fei->mConverterName, &fei->mConverter);
00775     if (NS_FAILED(res)) {
00776       return nsnull;
00777     }
00778   }
00779   return ffei;
00780 }
00781 
00782 nsICharsetConverterManager*
00783 nsFreeType2::GetCharSetManager()
00784 {
00785   if (!sCharSetManager) {
00786     //
00787     // get the sCharSetManager
00788     //
00789     CallGetService(kCharSetManagerCID, &sCharSetManager);
00790     NS_ASSERTION(sCharSetManager,"failed to create the charset manager");
00791   }
00792   return sCharSetManager;
00793 }
00794 
00795 PRUint16*
00796 nsFreeType2::GetCCMap(nsFontCatalogEntry *aFce)
00797 {
00798   nsCompressedCharMap ccmapObj;
00799   if (aFce->mFlags & FCE_FLAGS_SURROGATE) {
00800     ccmapObj.Extend();
00801   }
00802   ccmapObj.SetChars(aFce->mCCMap);
00803   return ccmapObj.NewCCMap();
00804 }
00805 
00807 //
00808 // class nsFreeTypeFace data/functions
00809 //
00811 NS_IMPL_ISUPPORTS1(nsFreeTypeFace, nsITrueTypeFontCatalogEntry)
00812 
00813 nsFreeTypeFace::nsFreeTypeFace()
00814 {
00815 }
00816 
00817 nsresult nsFreeTypeFace::Init(nsFontCatalogEntry *aFce)
00818 {
00819   NS_ASSERTION(aFce, "init of nsFreeTypeFace needs nsFontCatalogEntry");
00820   if (aFce)
00821     mFce = aFce;
00822   else {
00823     mFce = new nsFontCatalogEntry;
00824     NS_ASSERTION(mFce, "memory error while creating nsFontCatalogEntry");
00825     if (!mFce)
00826       return NS_ERROR_OUT_OF_MEMORY;
00827   }
00828   mCCMap = nsnull;
00829   return NS_OK;
00830 }
00831 
00832 nsFreeTypeFace::~nsFreeTypeFace()
00833 {
00834   if (mCCMap)
00835     FreeCCMap(mCCMap);
00836 }
00837 
00838 NS_IMETHODIMP nsFreeTypeFace::GetFontCatalogType(
00839                               PRUint16 *aFontCatalogType)
00840 {
00841   *aFontCatalogType = FONT_CATALOG_TRUETYPE;
00842   return NS_OK;
00843 }
00844 
00845 /* readonly attribute ACString fileName; */
00846 NS_IMETHODIMP nsFreeTypeFace::GetFileName(nsACString & aFileName)
00847 {
00848   aFileName.Assign(mFce->mFontFileName);
00849   return NS_OK;
00850 }
00851 
00852 /* readonly attribute ACString familyName; */
00853 NS_IMETHODIMP nsFreeTypeFace::GetFamilyName(nsACString & aFamilyName)
00854 {
00855   aFamilyName.Assign(mFce->mFamilyName);
00856   return NS_OK;
00857 }
00858 
00859 /* readonly attribute ACString styleName; */
00860 NS_IMETHODIMP nsFreeTypeFace::GetStyleName(nsACString & aStyleName)
00861 {
00862   aStyleName.Assign(mFce->mStyleName);
00863   return NS_OK;
00864 }
00865 
00866 /* readonly attribute ACString vendorID; */
00867 NS_IMETHODIMP nsFreeTypeFace::GetVendorID(nsACString & aVendorID)
00868 {
00869   aVendorID.Assign(mFce->mVendorID);
00870   return NS_OK;
00871 }
00872 
00873 /* readonly attribute short faceIndex; */
00874 NS_IMETHODIMP nsFreeTypeFace::GetFaceIndex(PRInt16 *aFaceIndex)
00875 {
00876   *aFaceIndex = mFce->mFaceIndex;
00877   return NS_OK;
00878 }
00879 
00880 /* readonly attribute short numFaces; */
00881 NS_IMETHODIMP nsFreeTypeFace::GetNumFaces(PRInt16 *aNumFaces)
00882 {
00883   *aNumFaces = mFce->mNumFaces;
00884   return NS_OK;
00885 }
00886 
00887 /* readonly attribute short numEmbeddedBitmaps; */
00888 NS_IMETHODIMP nsFreeTypeFace::GetNumEmbeddedBitmaps(
00889                               PRInt16 *aNumEmbeddedBitmaps)
00890 {
00891   *aNumEmbeddedBitmaps = mFce->mNumEmbeddedBitmaps;
00892   return NS_OK;
00893 }
00894 
00895 /* readonly attribute long numGlyphs; */
00896 NS_IMETHODIMP nsFreeTypeFace::GetNumGlyphs(PRInt32 *aNumGlyphs)
00897 {
00898   *aNumGlyphs = mFce->mNumGlyphs;
00899   return NS_OK;
00900 }
00901 
00902 /* readonly attribute long numUsableGlyphs; */
00903 NS_IMETHODIMP nsFreeTypeFace::GetNumUsableGlyphs(
00904                               PRInt32 *aNumUsableGlyphs)
00905 {
00906   *aNumUsableGlyphs = mFce->mNumUsableGlyphs;
00907   return NS_OK;
00908 }
00909 
00910 /* readonly attribute unsigned short weight; */
00911 NS_IMETHODIMP nsFreeTypeFace::GetWeight(PRUint16 *aWeight)
00912 {
00913   *aWeight = mFce->mWeight;
00914   return NS_OK;
00915 }
00916 
00917 /* readonly attribute unsigned short width; */
00918 NS_IMETHODIMP nsFreeTypeFace::GetWidth(PRUint16 *aWidth)
00919 {
00920   *aWidth = mFce->mWidth;
00921   return NS_OK;
00922 }
00923 
00924 /* readonly attribute unsigned long flags; */
00925 NS_IMETHODIMP nsFreeTypeFace::GetFlags(PRUint32 *aFlags)
00926 {
00927   *aFlags = mFce->mFlags;
00928   return NS_OK;
00929 }
00930 
00931 /* readonly attribute long long faceFlags; */
00932 NS_IMETHODIMP nsFreeTypeFace::GetFaceFlags(PRInt64 *aFaceFlags)
00933 {
00934   *aFaceFlags = mFce->mFaceFlags;
00935   return NS_OK;
00936 }
00937 
00938 /* readonly attribute long long styleFlags; */
00939 NS_IMETHODIMP nsFreeTypeFace::GetStyleFlags(PRInt64 *aStyleFlags)
00940 {
00941   *aStyleFlags = mFce->mStyleFlags;
00942   return NS_OK;
00943 }
00944 
00945 /* readonly attribute unsigned long codePageRange1; */
00946 NS_IMETHODIMP nsFreeTypeFace::GetCodePageRange1(
00947                               PRUint32 *aCodePageRange1)
00948 {
00949   *aCodePageRange1 = mFce->mCodePageRange1;
00950   return NS_OK;
00951 }
00952 
00953 /* readonly attribute unsigned long codePageRange2; */
00954 NS_IMETHODIMP nsFreeTypeFace::GetCodePageRange2(
00955                               PRUint32 *aCodePageRange2)
00956 {
00957   *aCodePageRange2 = mFce->mCodePageRange2;
00958   return NS_OK;
00959 }
00960 
00961 /* readonly attribute long long time; */
00962 NS_IMETHODIMP nsFreeTypeFace::GetFileModTime(PRInt64 *aTime)
00963 {
00964   *aTime = mFce->mMTime;
00965   return NS_OK;
00966 }
00967 
00968 /* void getCCMap (out unsigned long size,
00969  * [array, size_is (size), retval] out unsigned short ccMaps); */
00970 NS_IMETHODIMP nsFreeTypeFace::GetCCMap(
00971                               PRUint32 *size, PRUint16 **ccMaps)
00972 {
00973   *ccMaps = nsFreeType2::GetCCMap(mFce);
00974   *size = CCMAP_SIZE(*ccMaps);
00975   return NS_OK;
00976 }
00977 
00978 /* void getEmbeddedBitmapHeights (out unsigned long size,
00979  * [array, size_is (size), retval] out short heights); */
00980 NS_IMETHODIMP nsFreeTypeFace::GetEmbeddedBitmapHeights(
00981                               PRUint32 *size, PRInt32 **heights)
00982 {
00983   *heights = mFce->mEmbeddedBitmapHeights;
00984   *size = mFce->mNumEmbeddedBitmaps;
00985   return NS_OK;
00986 }
00987 
00988 PRBool
00989 nsFreeTypeFace::FreeFace(nsHashKey* aKey, void* aData, void* aClosure)
00990 {
00991   nsFreeTypeFace *face = (nsFreeTypeFace*) aData;
00992   NS_RELEASE(face);
00993 
00994   return PR_TRUE;
00995 }
00996 
00997 PRUint16 *
00998 nsFreeTypeFace::GetCCMap()
00999 {
01000   if (!mCCMap) {
01001     mCCMap = nsFreeType2::GetCCMap(mFce);
01002   }
01003   return mCCMap;
01004 }
01005 
01007 //
01008 // miscellaneous routines in alphabetic order
01009 //
01011 
01012 /*FT_CALLBACK_DEF*/
01013 FT_Error
01014 nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib,
01015                   FT_Pointer request_data, FT_Face* aFace)
01016 {
01017   nsFreeTypeFace *faceID = (nsFreeTypeFace *)face_id;
01018   FT_Error fterror = 0;
01019   nsFreeType2 *ft2 = (nsFreeType2 *)request_data;
01020   nsresult rv;
01021 
01022   rv = ft2->NewFace(lib, faceID->GetFilename(), faceID->GetFaceIndex(), aFace);
01023   if (NS_FAILED(rv))
01024     return fterror;
01025 
01026   FT_Face face = *aFace;
01027   FT_UShort platform_id = TT_PLATFORM_MICROSOFT;
01028   FT_UShort encoding_id = TT_MS_ID_UNICODE_CS;
01029   nsFontCatalogEntry* fce = faceID->GetFce();
01030   nsTTFontFamilyEncoderInfo *ffei =
01031                      nsFreeType2::GetCustomEncoderInfo(fce->mFamilyName);
01032   if (ffei) {
01033     platform_id = ffei->mEncodingInfo->mCmapPlatformID;
01034     encoding_id = ffei->mEncodingInfo->mCmapEncoding;
01035   }
01036 
01037   for (int i=0; i < face->num_charmaps; i++) {
01038     if (face->charmaps[i]->platform_id == platform_id) {
01039 #if defined(TT_MS_ID_UCS_4)
01040       if (face->charmaps[i]->encoding_id == TT_MS_ID_UCS_4) {
01041         rv = ft2->SetCharmap(face, face->charmaps[i]);
01042         if (NS_FAILED(rv)) {
01043           FREETYPE_PRINTF(("failed to set cmap"));
01044           ft2->DoneFace(face);
01045           *aFace = nsnull;
01046           fterror = 1;
01047         }
01048         // UCS_4 is the most prefered cmap since it supports surrogates
01049         // so stop here to avoid the possibly of getting UNICODE_CS which
01050         // is the 2nd prefered choice.
01051         break;
01052       } else
01053 #endif /* defined(TT_MS_ID_UCS_4) */
01054       if (face->charmaps[i]->encoding_id == encoding_id) {
01055         rv = ft2->SetCharmap(face, face->charmaps[i]);
01056         if (NS_FAILED(rv)) {
01057           FREETYPE_PRINTF(("failed to set cmap"));
01058           ft2->DoneFace(face);
01059           *aFace = nsnull;
01060           fterror = 1;
01061         }
01062       }
01063     }
01064   }
01065 
01066   return fterror;
01067 }
01068 
01069 nsFreeTypeFace *
01070 nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce)
01071 {
01072   // We need to have separate keys for the different faces in a ttc file.
01073   // We append a slash and the face index to the file name to give us a 
01074   // unique key for each ttc face.
01075   nsCAutoString key_str(aFce->mFontFileName);
01076   key_str.Append('/');
01077   key_str.AppendInt(aFce->mFaceIndex);
01078   nsCStringKey key(key_str);
01079   nsFreeTypeFace *face = (nsFreeTypeFace *)gFreeTypeFaces->Get(&key);
01080   if (!face) {
01081     face = new nsFreeTypeFace;
01082     NS_ASSERTION(face, "memory error while creating nsFreeTypeFace");
01083     if (!face)
01084       return nsnull;
01085     NS_ADDREF(face);
01086     nsresult rv = face->Init(aFce);
01087     if (NS_FAILED(rv)) {
01088       NS_RELEASE(face);
01089       return nsnull;
01090     }
01091     gFreeTypeFaces->Put(&key, face);
01092   }
01093   return face;
01094 }
01095 
01096 nsTTFontFamilyEncoderInfo gFontFamilyEncoderInfo[] = {
01097   { "symbol",         &FEI_Adobe_Symbol_Encoding },
01098   { "cmr10",          &FEI_x_ttf_cmr,            },
01099   { "cmmi10",         &FEI_x_ttf_cmmi,           },
01100   { "cmsy10",         &FEI_x_ttf_cmsy,           },
01101   { "cmex10",         &FEI_x_ttf_cmex,           },
01102   { "math1",          &FEI_x_mathematica1,       },
01103   { "math1-bold",     &FEI_x_mathematica1,       },
01104   { "math1mono",      &FEI_x_mathematica1,       },
01105   { "math1mono-bold", &FEI_x_mathematica1,       },
01106   { "math2",          &FEI_x_mathematica2,       },
01107   { "math2-bold",     &FEI_x_mathematica2,       },
01108   { "math2mono",      &FEI_x_mathematica2,       },
01109   { "math2mono-bold", &FEI_x_mathematica2,       },
01110   { "ahMn",           &FEI_x_mathematica3,       }, // weird name for Math3
01111   { "math3",          &FEI_x_mathematica3,       },
01112   { "math3-bold",     &FEI_x_mathematica3,       },
01113   { "math3mono",      &FEI_x_mathematica3,       },
01114   { "math3mono-bold", &FEI_x_mathematica3,       },
01115   { "math4",          &FEI_x_mathematica4,       },
01116   { "math4-bold",     &FEI_x_mathematica4,       },
01117   { "math4mono",      &FEI_x_mathematica4,       },
01118   { "math4mono-bold", &FEI_x_mathematica4,       },
01119   { "math5",          &FEI_x_mathematica5,       },
01120   { "math5-bold",     &FEI_x_mathematica5,       },
01121   { "math5bold",      &FEI_x_mathematica5,       },
01122   { "math5mono",      &FEI_x_mathematica5,       },
01123   { "math5mono-bold", &FEI_x_mathematica5,       },
01124   { "math5monobold",  &FEI_x_mathematica5,       },
01125   { "mtextra",        &FEI_x_mtextra,            },
01126   { "mt extra",       &FEI_x_mtextra,            },
01127   { "wingdings",      &FEI_windows_1252,         },
01128   { "webdings",       &FEI_windows_1252,         },
01129   { nsnull },
01130 };
01131 
01132 nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[] = {
01133 { TT_OS2_CPR1_LATIN1,       "iso8859-1"         },
01134 { TT_OS2_CPR1_LATIN2,       "iso8859-2"         },
01135 { TT_OS2_CPR1_CYRILLIC,     "iso8859-5"         },
01136 { TT_OS2_CPR1_GREEK,        "iso8859-7"         },
01137 { TT_OS2_CPR1_TURKISH,      "iso8859-9"         },
01138 { TT_OS2_CPR1_HEBREW,       "iso8859-8"         },
01139 { TT_OS2_CPR1_ARABIC,       "iso8859-6"         },
01140 { TT_OS2_CPR1_BALTIC,       "iso8859-13"        },
01141 { TT_OS2_CPR1_VIETNAMESE,   "viscii1.1-1"       },
01142 { TT_OS2_CPR1_THAI,         "tis620.2533-1"     },
01143 { TT_OS2_CPR1_JAPANESE,     "jisx0208.1990-0"   },
01144 { TT_OS2_CPR1_CHINESE_SIMP, "gb2312.1980-1"     },
01145 { TT_OS2_CPR1_KO_WANSUNG,   "ksc5601.1992-3"    },
01146 { TT_OS2_CPR1_CHINESE_TRAD, "big5-0"            },
01147 { TT_OS2_CPR1_KO_JOHAB,     "ksc5601.1992-3"    },
01148 { TT_OS2_CPR1_MAC_ROMAN,    "iso8859-1"         },
01149 { TT_OS2_CPR1_OEM,          "fontspecific-0"    },
01150 { TT_OS2_CPR1_SYMBOL,       "fontspecific-0"    },
01151 { 0,                         nsnull             },
01152 };
01153 
01154 nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[] = {
01155 { TT_OS2_CPR2_GREEK,        "iso8859-7"         },
01156 { TT_OS2_CPR2_RUSSIAN,      "koi8-r"            },
01157 { TT_OS2_CPR2_NORDIC,       "iso8859-10"        },
01158 { TT_OS2_CPR2_ARABIC,       "iso8859-6"         },
01159 { TT_OS2_CPR2_CA_FRENCH,    "iso8859-1"         },
01160 { TT_OS2_CPR2_HEBREW,       "iso8859-8"         },
01161 { TT_OS2_CPR2_ICELANDIC,    "iso8859-1"         },
01162 { TT_OS2_CPR2_PORTUGESE,    "iso8859-1"         },
01163 { TT_OS2_CPR2_TURKISH,      "iso8859-9"         },
01164 { TT_OS2_CPR2_CYRILLIC,     "iso8859-5"         },
01165 { TT_OS2_CPR2_LATIN2,       "iso8859-2"         },
01166 { TT_OS2_CPR2_BALTIC,       "iso8859-4"         },
01167 { TT_OS2_CPR2_GREEK_437G,   "iso8859-7"         },
01168 { TT_OS2_CPR2_ARABIC_708,   "iso8859-6"         },
01169 { TT_OS2_CPR2_WE_LATIN1,    "iso8859-1"         },
01170 { TT_OS2_CPR2_US,           "iso8859-1"         },
01171 { 0,                         nsnull             },
01172 };
01173