Back to index

lightning-sunbird  0.9+nobinonly
nsFT2FontCatalog.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 /* ***** 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 #ifndef NS_FT2_FONT_CATALOG_H
00041 #define NS_FT2_FONT_CATALOG_H
00042 
00043 #include "gfx-config.h"
00044 #include "nsIFontCatalogService.h"
00045 
00046 #if (defined(MOZ_ENABLE_FREETYPE2))
00047 #include "nsFreeType.h"
00048 #include "nsICharRepresentable.h"
00049 #include "nsCompressedCharMap.h"
00050 
00051 #include "nsString.h"
00052 #include "nsIPref.h"
00053 #include "nsNameValuePairDB.h"
00054 #include "nsICharsetConverterManager.h"
00055 
00056 //
00057 // To limit the potential for namespace collision we limit the 
00058 // number of Moz files that include FreeType's include (and hence 
00059 // have FreeType typedefs, macros, and defines).
00060 //
00061 struct FT_LibraryRec_;
00062 typedef signed long FT_Long;
00063 typedef unsigned short FT_UShort;
00064 
00065 #define PUBLIC_FONT_SUMMARY_NAME  NS_LITERAL_CSTRING(".mozilla_font_summary.ndb")
00066 #define FONT_SUMMARIES_SUBDIR     NS_LITERAL_CSTRING("catalog")
00067 #define FONT_DOWNLOAD_SUBDIR      NS_LITERAL_CSTRING("fonts")
00068 #define FONT_SUMMARIES_EXTENSION  NS_LITERAL_CSTRING(".ndb")
00069 #define FONT_SUMMARY_VERSION_TAG "FontSummaryVersion"
00070 #define FONT_SUMMARY_VERSION_MAJOR 1
00071 #define FONT_SUMMARY_VERSION_MINOR 0
00072 #define FONT_SUMMARY_VERSION_REV   0
00073 
00074 
00075 #define FC_FILE_OKAY     0
00076 #define FC_FILE_GARBLED  1
00077 #define FC_FILE_MODIFIED 2
00078 
00079 #define STRMATCH(s1,s2) (strcmp((s1),(s2))==0)
00080 #define STRNMATCH(s1,s2,l) (strncmp((s1),(s2),(l))==0)
00081 #define STRCASEMATCH(s1,s2) (strcasecmp((s1),(s2))==0)
00082 
00083 typedef struct {
00084   const char   *mDirName; // encoded in the native charset
00085 } nsDirCatalogEntry;
00086 
00087 #define CPR1 1  // designate CodePageRange1 to use for "GetRangeLanguage"
00088 #define CPR2 2  // designate CodePageRange2 to use for "GetRangeLanguage"
00089 
00090 typedef struct {
00091   nsFontCatalogEntry **fonts;
00092   int numFonts;
00093   int numSlots;
00094 } nsFontCatalog;
00095 
00096 typedef struct {
00097   nsDirCatalogEntry **dirs;
00098   int numDirs;
00099   int numSlots;
00100 } nsDirCatalog;
00101 
00102 typedef struct {
00103   const char *vendorID;
00104   const char *vendorName;
00105 } nsFontVendorName;
00106 
00107 typedef struct {
00108   unsigned long bit;
00109   const char *language;
00110 } nsulCodePageRangeLanguage;
00111 
00112 #endif
00113 
00114 class nsFT2FontCatalog : public nsIFontCatalogService {
00115 public:
00116   NS_DECL_ISUPPORTS
00117   NS_DECL_NSIFONTCATALOGSERVICE
00118 
00119   nsFT2FontCatalog();
00120   virtual ~nsFT2FontCatalog();
00121 
00122 #if (defined(MOZ_ENABLE_FREETYPE2))
00123 
00124   void        FreeGlobals();
00125   PRBool      InitGlobals(FT_LibraryRec_ *);
00126   void        GetFontNames(const nsACString & aFamilyName,
00127                            const nsACString & aLanguage,
00128                            PRUint16       aWeight,
00129                            PRUint16       aWidth,
00130                            PRUint16       aSlant,
00131                            PRUint16       aSpacing,
00132                            nsFontCatalog* aFC);
00133   static const char* GetFileName(nsFontCatalogEntry *aFce);
00134   static const char* GetFamilyName(nsFontCatalogEntry *aFce);
00135   static PRInt32*    GetEmbeddedBitmapHeights(nsFontCatalogEntry *aFce);
00136   static PRInt32     GetFaceIndex(nsFontCatalogEntry *aFce);
00137   static PRInt32     GetNumEmbeddedBitmaps(nsFontCatalogEntry *aFce);
00138   static const char* GetFoundry(nsFontCatalogEntry *aFce);
00139 
00140 protected:
00141   static void   AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir);
00142   PRBool AddFceIfCurrent(const char*, nsHashtable*, PRInt64, nsFontCatalog*);
00143   void   AddFont(nsFontCatalog *fc, nsFontCatalogEntry *fce);
00144   int    CheckFontSummaryVersion(nsNameValuePairDB *aDB);
00145 #ifdef DEBUG
00146   void   DumpFontCatalog(nsFontCatalog *fc);
00147   void   DumpFontCatalogEntry(nsFontCatalogEntry *);
00148 #endif
00149   void   FixUpFontCatalog(nsFontCatalog *fc);
00150   static PRBool FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure);
00151   void   FreeFontCatalog(nsFontCatalog *fc);
00152   static void   FreeFontCatalogEntry(nsFontCatalogEntry *);
00153   void   FreeDirCatalog(nsDirCatalog *dc);
00154   void   FreeDirCatalogEntry(nsDirCatalogEntry *);
00155   static void GetDirsPrefEnumCallback(const char* aName, void* aClosure);
00156   int    GetFontCatalog(FT_LibraryRec_*, nsFontCatalog *, nsDirCatalog *);
00157   PRBool GetFontSummaryName(const nsACString &, const nsACString &,
00158                                    nsACString &, nsACString &);
00159   unsigned long GetRangeLanguage(const nsACString &, PRInt16 aRange);
00160   PRBool HandleFontDir(FT_LibraryRec_ *, nsFontCatalog *,
00161                        const nsACString &, const nsACString &);
00162   void   HandleFontFile(FT_LibraryRec_ *, nsFontCatalog *, const char*);
00163   PRBool IsSpace(FT_Long);
00164   nsDirCatalog *NewDirCatalog();
00165   nsFontCatalogEntry* NewFceFromFontFile(FT_LibraryRec_*, const char*,int,int*);
00166   nsFontCatalogEntry* NewFceFromSummary(nsNameValuePairDB *aDB);
00167   nsFontCatalog *NewFontCatalog();
00168   PRBool ReadFontDirSummary(const nsACString&, nsHashtable*);
00169   PRBool ParseCCMapLine(nsCompressedCharMap*,long,const char*);
00170   void   PrintCCMap(nsNameValuePairDB *aDB, PRUint16 *aCCMap);
00171   void   PrintFontSummaries(nsNameValuePairDB *, nsFontCatalog *);
00172   void   PrintFontSummaryVersion(nsNameValuePairDB *aDB);
00173   void   PrintPageBits(nsNameValuePairDB*,PRUint16*,PRUint32);
00174   int    ReadFontSummaries(nsHashtable*, nsNameValuePairDB *);
00175 
00176   static nsIPref* sPref;
00177   nsFontCatalog *mFontCatalog;
00178 
00179   PRPackedBool   mIsNewCatalog;
00180   static nsHashtable   *sVendorNames;
00181   nsHashtable   *mRange1Language;
00182   nsHashtable   *mRange2Language;
00183   PRBool         mAvailableFontCatalogService;
00184   nsCOMPtr<nsIFreeType2> mFt2;
00185 #endif
00186 };
00187 
00188 #endif /* NS_FT2_FONT_CATALOG_H */
00189