From ce3bdb174dfa46d90e8ad49299f5cdcedddf8701 Mon Sep 17 00:00:00 2001 From: "pete.zha%sun.com" Date: Fri, 15 Nov 2002 04:59:17 +0000 Subject: [PATCH] Font Catalog Service b=144664 r=bstell@ix.netcom.com sr=bryner@netscape.com patch=louie.zhao@sun.com git-svn-id: svn://10.0.0.236/trunk@133886 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/idl/Makefile.in | 1 + mozilla/gfx/idl/nsIFontCatalogService.idl | 118 +++ mozilla/gfx/public/nsGfxCIID.h | 5 + mozilla/gfx/src/Makefile.in | 4 + mozilla/gfx/src/freetype/Makefile.in | 54 ++ mozilla/gfx/src/freetype/nsFreeType.cpp | 504 ++++++++++++- mozilla/gfx/src/freetype/nsFreeType.h | 97 ++- mozilla/gfx/src/gtk/Makefile.in | 3 +- mozilla/gfx/src/gtk/nsFontMetricsGTK.h | 3 +- mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp | 6 + .../gfx/src/x11shared/nsFT2FontCatalog.cpp | 683 +++++++----------- mozilla/gfx/src/x11shared/nsFT2FontCatalog.h | 125 ++-- mozilla/gfx/src/x11shared/nsFT2FontNode.cpp | 260 +++++-- mozilla/gfx/src/x11shared/nsFT2FontNode.h | 9 +- mozilla/gfx/src/x11shared/nsFontFreeType.cpp | 66 +- mozilla/gfx/src/x11shared/nsFontFreeType.h | 28 +- 16 files changed, 1315 insertions(+), 651 deletions(-) create mode 100644 mozilla/gfx/idl/nsIFontCatalogService.idl create mode 100644 mozilla/gfx/src/freetype/Makefile.in diff --git a/mozilla/gfx/idl/Makefile.in b/mozilla/gfx/idl/Makefile.in index 48d9ce861b3..7bb87147934 100644 --- a/mozilla/gfx/idl/Makefile.in +++ b/mozilla/gfx/idl/Makefile.in @@ -39,6 +39,7 @@ XPIDLSRCS = \ nsIPrintOptions.idl \ nsIPrintSettings.idl \ nsIPrintSettingsService.idl \ + nsIFontCatalogService.idl \ nsIPrintSession.idl \ gfxIFormats.idl \ gfxIImageFrame.idl \ diff --git a/mozilla/gfx/idl/nsIFontCatalogService.idl b/mozilla/gfx/idl/nsIFontCatalogService.idl new file mode 100644 index 00000000000..3b2171b0cc4 --- /dev/null +++ b/mozilla/gfx/idl/nsIFontCatalogService.idl @@ -0,0 +1,118 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Christopher Blizzard + * . Portions created by the Initial Developer + * are Copyright (C) 2002 the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Pete Zha + * Brian Stell + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" +#include "nsISupportsArray.idl" + +[noscript, uuid(70406f93-5b53-49a0-b5a7-ebf533bfe59b)] +interface nsIFontCatalogEntry : nsISupports +{ + const short FONT_CATALOG_TRUETYPE = 1; + + readonly attribute unsigned short fontCatalogType; +}; + +[noscript, uuid(11f3efad-316e-4982-b9cf-9c304b0d5237)] +interface nsITrueTypeFontCatalogEntry : nsIFontCatalogEntry +{ + readonly attribute ACString fileName; + readonly attribute ACString familyName; + readonly attribute ACString styleName; + readonly attribute ACString vendorID; + readonly attribute short faceIndex; + readonly attribute short numFaces; + readonly attribute short numEmbeddedBitmaps; + readonly attribute long numGlyphs; + readonly attribute long numUsableGlyphs; + readonly attribute unsigned short weight; + readonly attribute unsigned short width; + readonly attribute unsigned long flags; + readonly attribute long long faceFlags; + readonly attribute long long styleFlags; + readonly attribute unsigned long codePageRange1; + readonly attribute unsigned long codePageRange2; + readonly attribute long long fileModTime; + + void getCCMap(out unsigned long size, + [retval, array, size_is(size)] out unsigned short ccMaps); + + void getEmbeddedBitmapHeights(out unsigned long size, + [retval, array, size_is(size)] out long heights); +}; + +[noscript, uuid(a3057187-c40f-4ffa-9160-2b16482053b1)] +interface nsIFontCatalogService : nsISupports +{ + nsISupportsArray getFontCatalogEntries(in ACString familyName, + in ACString language, + in unsigned short weight, + in unsigned short width, + in unsigned short slant, + in unsigned short spacing); + + // Definition for weight + const unsigned short kFCWeightLight = 300; + const unsigned short kFCWeightBook = 400; + const unsigned short kFCWeightMedium = 400; + const unsigned short kFCWeightRegular = 400; + const unsigned short kFCWeightDemi = 600; + const unsigned short kFCWeightDemibold = 600; + const unsigned short kFCWeightBold = 700; + const unsigned short kFCWeighBlack = 900; + + // Definition for width + const unsigned short kFCWidthNarrow = 3; + const unsigned short kFCWidthSemicondensed = 4; + const unsigned short kFCWidthBlock = 5; + const unsigned short kFCWidthMedium = 5; + const unsigned short kFCWidthNormal = 5; + const unsigned short kFCWidthBold = 7; + const unsigned short kFCWidthWide = 7; + const unsigned short kFCWidthDoubleWide = 9; + + // Definition for slant + const unsigned short kFCSlantRoman = 1; + const unsigned short kFCSlantItalic = 2; + const unsigned short kFCSlantOblique = 3; + const unsigned short kFCSlantReverseItalic = 4; + const unsigned short kFCSlantReverseOblique = 5; + + // Definition for spacing + const unsigned short kFCSpacingMonospace = 1; + const unsigned short kFCSpacingProportional = 2; +}; diff --git a/mozilla/gfx/public/nsGfxCIID.h b/mozilla/gfx/public/nsGfxCIID.h index e2e6f4499f5..a53bf13124a 100644 --- a/mozilla/gfx/public/nsGfxCIID.h +++ b/mozilla/gfx/public/nsGfxCIID.h @@ -111,4 +111,9 @@ { 0x2f977d53, 0x5485, 0x11d4, \ { 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } } +#define NS_FONTCATALOGSERVICE_CID \ +{ 0xa3057187, 0xc40f, 0x4ffa, \ +{ 0x91, 0x60, 0x2b, 0x16, 0x48, 0x20, 0x53, 0xb1 } } + + #endif diff --git a/mozilla/gfx/src/Makefile.in b/mozilla/gfx/src/Makefile.in index ed5146db89e..14fcdf15c42 100644 --- a/mozilla/gfx/src/Makefile.in +++ b/mozilla/gfx/src/Makefile.in @@ -45,6 +45,10 @@ REQUIRES = xpcom \ DIRS = shared +ifdef MOZ_ENABLE_FREETYPE2 +DIRS += freetype +endif + ifdef MOZ_ENABLE_POSTSCRIPT DIRS += ps endif diff --git a/mozilla/gfx/src/freetype/Makefile.in b/mozilla/gfx/src/freetype/Makefile.in new file mode 100644 index 00000000000..6ef21d152d3 --- /dev/null +++ b/mozilla/gfx/src/freetype/Makefile.in @@ -0,0 +1,54 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = gfx +LIBRARY_NAME = gfxft2 +EXPORT_LIBRARY = 1 +MODULE_NAME = nsGfxFT2Module +REQUIRES = xpcom \ + string \ + pref \ + uconv \ + $(NULL) + +CPPSRCS = \ + nsFreeType.cpp \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +LOCAL_INCLUDES = \ + -I$(srcdir)/../x11shared \ + $(NULL) + +ifdef MOZ_ENABLE_FREETYPE2 +DEFINES += -DMOZ_ENABLE_FREETYPE2 +INCLUDES += $(FT2_CFLAGS) +# due to runtime linking with PR_LoadLibrary +# EXTRA_DSO_LDOPTS does not need $(FT2_LIBS) +endif + diff --git a/mozilla/gfx/src/freetype/nsFreeType.cpp b/mozilla/gfx/src/freetype/nsFreeType.cpp index 09c23797cc4..21ed0f2a7d3 100644 --- a/mozilla/gfx/src/freetype/nsFreeType.cpp +++ b/mozilla/gfx/src/freetype/nsFreeType.cpp @@ -38,25 +38,14 @@ * ***** END LICENSE BLOCK ***** */ #include "math.h" +#include "nsIPref.h" #include "nsCOMPtr.h" +#include "nsIServiceManager.h" +#include "nsCompressedCharMap.h" #include "nsICharsetConverterManager.h" #include "nsIRenderingContext.h" -#include "nsFontDebug.h" #include "nsFreeType.h" -PRUint32 gFontDebug = 0 | NS_FONT_DEBUG_FONT_SCAN; - -#if (!defined(MOZ_ENABLE_FREETYPE2)) -// nsFreeType stubs for development systems without a FreeType dev env -nsresult nsFreeTypeInitGlobals() { - FREETYPE_FONT_PRINTF(("direct freetype not compiled in")); - NS_WARNING("direct freetype not compiled in"); - return NS_OK; -}; - -void nsFreeTypeFreeGlobals() {}; - -#else #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -66,6 +55,16 @@ void nsFreeTypeFreeGlobals() {}; #include "freetype/ftcache.h" #include "freetype/cache/ftcimage.h" +# define FREETYPE_PRINTF(x) \ + PR_BEGIN_MACRO \ + if (gFreeTypeDebug) { \ + printf x ; \ + printf(", %s %d\n", __FILE__, __LINE__); \ + } \ + PR_END_MACRO + +PRUint32 gFreeTypeDebug = 0; + char* nsFreeType::gFreeType2SharedLibraryName = nsnull; PRBool nsFreeType::gEnableFreeType2 = PR_FALSE; PRBool nsFreeType::gFreeType2Autohinted = PR_FALSE; @@ -74,7 +73,14 @@ PRUint8 nsFreeType::gAATTDarkTextMinValue = 64; double nsFreeType::gAATTDarkTextGain = 0.8; PRInt32 nsFreeType::gAntiAliasMinimum = 8; PRInt32 nsFreeType::gEmbeddedBitmapMaximumHeight = 1000000; +nsHashtable* nsFreeType::sFontFamilies = nsnull; +nsHashtable* nsFreeType::sRange1CharSetNames = nsnull; +nsHashtable* nsFreeType::sRange2CharSetNames = nsnull; +nsICharsetConverterManager2* nsFreeType::sCharSetManager = nsnull; +extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[]; +extern nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[]; +extern nsTTFontFamilyEncoderInfo gFontFamilyEncoderInfo[]; typedef int Error; @@ -141,6 +147,44 @@ static FtFuncList FtFuncs [] = { {nsnull, (PRFuncPtr*)nsnull}, }; +nsTTFontEncoderInfo FEI_Adobe_Symbol_Encoding = { + "Adobe-Symbol-Encoding", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull +}; +nsTTFontEncoderInfo FEI_x_ttf_cmr = { + "x-ttf-cmr", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull +}; +nsTTFontEncoderInfo FEI_x_ttf_cmmi = { + "x-ttf-cmmi", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull +}; +nsTTFontEncoderInfo FEI_x_ttf_cmsy = { + "x-ttf-cmsy", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull +}; +nsTTFontEncoderInfo FEI_x_ttf_cmex = { + "x-ttf-cmex", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull +}; +nsTTFontEncoderInfo FEI_x_mathematica1 = { + "x-mathematica1", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull +}; +nsTTFontEncoderInfo FEI_x_mathematica2 = { + "x-mathematica2", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull +}; +nsTTFontEncoderInfo FEI_x_mathematica3 = { + "x-mathematica3", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull +}; +nsTTFontEncoderInfo FEI_x_mathematica4 = { + "x-mathematica4", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull +}; +nsTTFontEncoderInfo FEI_x_mathematica5 = { + "x-mathematica5", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull +}; +nsTTFontEncoderInfo FEI_x_mtextra = { + "x-mtextra", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull +}; +nsTTFontEncoderInfo FEI_windows_1252 = { + "windows-1252", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull +}; + + /////////////////////////////////////////////////////////////////////// // // class nsFreeType data/functions @@ -157,13 +201,14 @@ nsFreeTypeFreeGlobals() nsresult nsFreeTypeInitGlobals() { - FREETYPE_FONT_PRINTF(("initialize freetype")); + FREETYPE_PRINTF(("initialize freetype")); nsresult rv = nsFreeType::InitGlobals(); return rv; } + // FREETYPE Globals PRLibrary *nsFreeType::sSharedLib; PRBool nsFreeType::sInited; @@ -225,7 +270,24 @@ nsFreeType::FreeGlobals() (*nsFreeType::nsFT_Done_FreeType)(sFreeTypeLibrary); sFreeTypeLibrary = nsnull; } - nsFT2FontCatalog::FreeGlobals(); + + if (sRange1CharSetNames) + delete sRange1CharSetNames; + if (sRange2CharSetNames) + delete sRange2CharSetNames; + if (sFontFamilies) + delete sFontFamilies; + + NS_IF_RELEASE(sCharSetManager); + + // release any encoders that were created + int i; + for (i=0; gFontFamilyEncoderInfo[i].mFamilyName; i++) { + nsTTFontFamilyEncoderInfo *ffei = &gFontFamilyEncoderInfo[i]; + nsTTFontEncoderInfo *fei = ffei->mEncodingInfo; + NS_IF_RELEASE(fei->mConverter); + } + UnloadSharedLib(); ClearFunctions(); ClearGlobals(); @@ -237,7 +299,9 @@ nsFreeType::InitGlobals(void) NS_ASSERTION(sInited==PR_FALSE, "InitGlobals called more than once"); // set all the globals to default values ClearGlobals(); - + + nsulCodePageRangeCharSetName *crn = nsnull; + nsTTFontFamilyEncoderInfo *ff = gFontFamilyEncoderInfo; nsCOMPtr mPref = do_GetService(NS_PREF_CONTRACTID); if (!mPref) { @@ -250,14 +314,14 @@ nsFreeType::InitGlobals(void) rv = mPref->GetBoolPref("font.FreeType2.enable", &enable_freetype2); if (NS_SUCCEEDED(rv)) { gEnableFreeType2 = enable_freetype2; - FREETYPE_FONT_PRINTF(("gEnableFreeType2 = %d", gEnableFreeType2)); + FREETYPE_PRINTF(("gEnableFreeType2 = %d", gEnableFreeType2)); } rv = mPref->GetCharPref("font.freetype2.shared-library", &gFreeType2SharedLibraryName); if (NS_FAILED(rv)) { enable_freetype2 = PR_FALSE; - FREETYPE_FONT_PRINTF(( + FREETYPE_PRINTF(( "gFreeType2SharedLibraryName missing, FreeType2 disabled")); gFreeType2SharedLibraryName = nsnull; } @@ -266,21 +330,21 @@ nsFreeType::InitGlobals(void) rv = mPref->GetBoolPref("font.FreeType2.autohinted", &freetype2_autohinted); if (NS_SUCCEEDED(rv)) { gFreeType2Autohinted = freetype2_autohinted; - FREETYPE_FONT_PRINTF(("gFreeType2Autohinted = %d", gFreeType2Autohinted)); + FREETYPE_PRINTF(("gFreeType2Autohinted = %d", gFreeType2Autohinted)); } PRBool freetype2_unhinted = PR_TRUE; rv = mPref->GetBoolPref("font.FreeType2.unhinted", &freetype2_unhinted); if (NS_SUCCEEDED(rv)) { gFreeType2Unhinted = freetype2_unhinted; - FREETYPE_FONT_PRINTF(("gFreeType2Unhinted = %d", gFreeType2Unhinted)); + FREETYPE_PRINTF(("gFreeType2Unhinted = %d", gFreeType2Unhinted)); } PRInt32 int_val = 0; rv = mPref->GetIntPref("font.scale.tt_bitmap.dark_text.min", &int_val); if (NS_SUCCEEDED(rv)) { gAATTDarkTextMinValue = int_val; - SIZE_FONT_PRINTF(("gAATTDarkTextMinValue = %d", gAATTDarkTextMinValue)); + FREETYPE_PRINTF(("gAATTDarkTextMinValue = %d", gAATTDarkTextMinValue)); } nsXPIDLCString str; @@ -288,21 +352,21 @@ nsFreeType::InitGlobals(void) getter_Copies(str)); if (NS_SUCCEEDED(rv)) { gAATTDarkTextGain = atof(str.get()); - SIZE_FONT_PRINTF(("gAATTDarkTextGain = %g", gAATTDarkTextGain)); + FREETYPE_PRINTF(("gAATTDarkTextGain = %g", gAATTDarkTextGain)); } PRInt32 antialias_minimum = 8; rv = mPref->GetIntPref("font.antialias.min", &antialias_minimum); if (NS_SUCCEEDED(rv)) { gAntiAliasMinimum = antialias_minimum; - FREETYPE_FONT_PRINTF(("gAntiAliasMinimum = %d", gAntiAliasMinimum)); + FREETYPE_PRINTF(("gAntiAliasMinimum = %d", gAntiAliasMinimum)); } PRInt32 embedded_bitmaps_maximum = 1000000; rv = mPref->GetIntPref("font.embedded_bitmaps.max",&embedded_bitmaps_maximum); if (NS_SUCCEEDED(rv)) { gEmbeddedBitmapMaximumHeight = embedded_bitmaps_maximum; - FREETYPE_FONT_PRINTF(("gEmbeddedBitmapMaximumHeight = %d", + FREETYPE_PRINTF(("gEmbeddedBitmapMaximumHeight = %d", gEmbeddedBitmapMaximumHeight)); } @@ -328,10 +392,49 @@ nsFreeType::InitGlobals(void) } gFreeTypeFaces = new nsHashtable(); if (!gFreeTypeFaces) { + FreeGlobals(); return NS_ERROR_OUT_OF_MEMORY; } - if (!nsFT2FontCatalog::InitGlobals(nsFreeType::GetLibrary())) { - return NS_ERROR_FAILURE; + + sRange1CharSetNames = new nsHashtable(); + if (!sRange1CharSetNames) { + FreeGlobals(); + return NS_ERROR_OUT_OF_MEMORY; + } + crn = ulCodePageRange1CharSetNames; + while (crn->charsetName) { + char buf[32]; + sprintf(buf, "0x%08lx", crn->bit); + nsCStringKey key(buf); + sRange1CharSetNames->Put(&key, (void*)crn->charsetName); + crn++; + } + + sRange2CharSetNames = new nsHashtable(); + if (!sRange2CharSetNames) { + FreeGlobals(); + return NS_ERROR_OUT_OF_MEMORY; + } + crn = ulCodePageRange2CharSetNames; + while (crn->charsetName) { + char buf[32]; + sprintf(buf, "0x%08lx", crn->bit); + nsCStringKey key(buf); + sRange2CharSetNames->Put(&key, (void*)crn->charsetName); + crn++; + } + + sFontFamilies = new nsHashtable(); + if (!sFontFamilies) { + FreeGlobals(); + return NS_ERROR_OUT_OF_MEMORY; + } + while (ff->mFamilyName) { + nsCAutoString name(ff->mFamilyName); + ToLowerCase(name); + nsCStringKey key(name); + sFontFamilies->Put(&key, (void*)ff); + ff++; } return NS_OK; @@ -358,7 +461,7 @@ nsFreeType::InitLibrary() sInitError = (*nsFreeType::nsFT_Init_FreeType)(&sFreeTypeLibrary); if (sInitError) { - FREETYPE_FONT_PRINTF(("\n\n*********\nFreeType initialization error = %d", + FREETYPE_PRINTF(("\n\n*********\nFreeType initialization error = %d", sInitError)); sFreeTypeLibrary = nsnull; goto cleanup_and_return; @@ -423,16 +526,109 @@ nsFreeType::UnloadSharedLib() sSharedLib = nsnull; } +const char * +nsFreeType::GetRange1CharSetName(unsigned long aBit) +{ + char buf[32]; + sprintf(buf, "0x%08lx", aBit); + nsCStringKey key(buf); + const char *charsetName = (const char *)sRange1CharSetNames->Get(&key); + return charsetName; +} + +const char * +nsFreeType::GetRange2CharSetName(unsigned long aBit) +{ + char buf[32]; + sprintf(buf, "0x%08lx", aBit); + nsCStringKey key(buf); + const char *charsetName = (const char *)sRange2CharSetNames->Get(&key); + return charsetName; +} + +nsTTFontFamilyEncoderInfo* +nsFreeType::GetCustomEncoderInfo(const char * aFamilyName) +{ + if (!sFontFamilies) + return nsnull; + + nsTTFontFamilyEncoderInfo *ffei; + nsCAutoString name(aFamilyName); + ToLowerCase(name); + nsCStringKey key(name); + ffei = (nsTTFontFamilyEncoderInfo*)sFontFamilies->Get(&key); + if (!ffei) + return nsnull; + + // init the converter + if (!ffei->mEncodingInfo->mConverter) { + nsTTFontEncoderInfo *fei = ffei->mEncodingInfo; + // + // build the converter + // + nsICharsetConverterManager2* charSetManager = GetCharSetManager(); + if (!charSetManager) + return nsnull; + nsCOMPtr charset(dont_AddRef(NS_NewAtom(fei->mConverterName))); + if (charset) { + nsresult res; + res = charSetManager->GetUnicodeEncoder(charset, &fei->mConverter); + if (NS_FAILED(res)) { + return nsnull; + } + } + } + return ffei; +} + +nsICharsetConverterManager2* +nsFreeType::GetCharSetManager() +{ + if (!sCharSetManager) { + // + // get the sCharSetManager + // + nsServiceManager::GetService(kCharSetManagerCID, + NS_GET_IID(nsICharsetConverterManager2), + (nsISupports**) &sCharSetManager); + NS_ASSERTION(sCharSetManager,"failed to create the charset manager"); + } + return sCharSetManager; +} + +PRUint16* +nsFreeType::GetCCMap(nsFontCatalogEntry *aFce) +{ + nsCompressedCharMap ccmapObj; + ccmapObj.SetChars(aFce->mCCMap); + return ccmapObj.NewCCMap(); +} + /////////////////////////////////////////////////////////////////////// // // class nsFreeTypeFace data/functions // /////////////////////////////////////////////////////////////////////// +NS_IMPL_ISUPPORTS1(nsFreeTypeFace, nsITrueTypeFontCatalogEntry) -nsFreeTypeFace::nsFreeTypeFace(nsFontCatalogEntry *aFce) +nsFreeTypeFace::nsFreeTypeFace() { - mFce = aFce; +} + +nsresult nsFreeTypeFace::Init(nsFontCatalogEntry *aFce) +{ + NS_ASSERTION(aFce, "init of nsFreeTypeFace needs nsFontCatalogEntry"); + NS_INIT_ISUPPORTS(); + if (aFce) + mFce = aFce; + else { + mFce = new nsFontCatalogEntry; + NS_ASSERTION(mFce, "memory error while creating nsFontCatalogEntry"); + if (!mFce) + return NS_ERROR_OUT_OF_MEMORY; + } mCCMap = nsnull; + return NS_OK; } nsFreeTypeFace::~nsFreeTypeFace() @@ -441,6 +637,156 @@ nsFreeTypeFace::~nsFreeTypeFace() FreeCCMap(mCCMap); } +NS_IMETHODIMP nsFreeTypeFace::GetFontCatalogType( + PRUint16 *aFontCatalogType) +{ + *aFontCatalogType = FONT_CATALOG_TRUETYPE; + return NS_OK; +} + +/* readonly attribute ACString fileName; */ +NS_IMETHODIMP nsFreeTypeFace::GetFileName(nsACString & aFileName) +{ + aFileName.Assign(mFce->mFontFileName); + return NS_OK; +} + +/* readonly attribute ACString familyName; */ +NS_IMETHODIMP nsFreeTypeFace::GetFamilyName(nsACString & aFamilyName) +{ + aFamilyName.Assign(mFce->mFamilyName); + return NS_OK; +} + +/* readonly attribute ACString styleName; */ +NS_IMETHODIMP nsFreeTypeFace::GetStyleName(nsACString & aStyleName) +{ + aStyleName.Assign(mFce->mStyleName); + return NS_OK; +} + +/* readonly attribute ACString vendorID; */ +NS_IMETHODIMP nsFreeTypeFace::GetVendorID(nsACString & aVendorID) +{ + aVendorID.Assign(mFce->mVendorID); + return NS_OK; +} + +/* readonly attribute short faceIndex; */ +NS_IMETHODIMP nsFreeTypeFace::GetFaceIndex(PRInt16 *aFaceIndex) +{ + *aFaceIndex = mFce->mFaceIndex; + return NS_OK; +} + +/* readonly attribute short numFaces; */ +NS_IMETHODIMP nsFreeTypeFace::GetNumFaces(PRInt16 *aNumFaces) +{ + *aNumFaces = mFce->mNumFaces; + return NS_OK; +} + +/* readonly attribute short numEmbeddedBitmaps; */ +NS_IMETHODIMP nsFreeTypeFace::GetNumEmbeddedBitmaps( + PRInt16 *aNumEmbeddedBitmaps) +{ + *aNumEmbeddedBitmaps = mFce->mNumEmbeddedBitmaps; + return NS_OK; +} + +/* readonly attribute long numGlyphs; */ +NS_IMETHODIMP nsFreeTypeFace::GetNumGlyphs(PRInt32 *aNumGlyphs) +{ + *aNumGlyphs = mFce->mNumGlyphs; + return NS_OK; +} + +/* readonly attribute long numUsableGlyphs; */ +NS_IMETHODIMP nsFreeTypeFace::GetNumUsableGlyphs( + PRInt32 *aNumUsableGlyphs) +{ + *aNumUsableGlyphs = mFce->mNumUsableGlyphs; + return NS_OK; +} + +/* readonly attribute unsigned short weight; */ +NS_IMETHODIMP nsFreeTypeFace::GetWeight(PRUint16 *aWeight) +{ + *aWeight = mFce->mWeight; + return NS_OK; +} + +/* readonly attribute unsigned short width; */ +NS_IMETHODIMP nsFreeTypeFace::GetWidth(PRUint16 *aWidth) +{ + *aWidth = mFce->mWidth; + return NS_OK; +} + +/* readonly attribute unsigned long flags; */ +NS_IMETHODIMP nsFreeTypeFace::GetFlags(PRUint32 *aFlags) +{ + *aFlags = mFce->mFlags; + return NS_OK; +} + +/* readonly attribute long long faceFlags; */ +NS_IMETHODIMP nsFreeTypeFace::GetFaceFlags(PRInt64 *aFaceFlags) +{ + *aFaceFlags = mFce->mFaceFlags; + return NS_OK; +} + +/* readonly attribute long long styleFlags; */ +NS_IMETHODIMP nsFreeTypeFace::GetStyleFlags(PRInt64 *aStyleFlags) +{ + *aStyleFlags = mFce->mStyleFlags; + return NS_OK; +} + +/* readonly attribute unsigned long codePageRange1; */ +NS_IMETHODIMP nsFreeTypeFace::GetCodePageRange1( + PRUint32 *aCodePageRange1) +{ + *aCodePageRange1 = mFce->mCodePageRange1; + return NS_OK; +} + +/* readonly attribute unsigned long codePageRange2; */ +NS_IMETHODIMP nsFreeTypeFace::GetCodePageRange2( + PRUint32 *aCodePageRange2) +{ + *aCodePageRange2 = mFce->mCodePageRange2; + return NS_OK; +} + +/* readonly attribute long long time; */ +NS_IMETHODIMP nsFreeTypeFace::GetFileModTime(PRInt64 *aTime) +{ + *aTime = mFce->mMTime; + return NS_OK; +} + +/* void getCCMap (out unsigned long size, + * [array, size_is (size), retval] out unsigned short ccMaps); */ +NS_IMETHODIMP nsFreeTypeFace::GetCCMap( + PRUint32 *size, PRUint16 **ccMaps) +{ + *ccMaps = nsFreeType::GetCCMap(mFce); + *size = CCMAP_SIZE(*ccMaps); + return NS_OK; +} + +/* void getEmbeddedBitmapHeights (out unsigned long size, + * [array, size_is (size), retval] out short heights); */ +NS_IMETHODIMP nsFreeTypeFace::GetEmbeddedBitmapHeights( + PRUint32 *size, PRInt32 **heights) +{ + *heights = mFce->mEmbeddedBitmapHeights; + *size = mFce->mNumEmbeddedBitmaps; + return NS_OK; +} + PRBool nsFreeTypeFace::FreeFace(nsHashKey* aKey, void* aData, void* aClosure) { @@ -454,12 +800,11 @@ PRUint16 * nsFreeTypeFace::GetCCMap() { if (!mCCMap) { - mCCMap = nsFT2FontCatalog::GetCCMap(mFce); + mCCMap = nsFreeType::GetCCMap(mFce); } return mCCMap; } - /////////////////////////////////////////////////////////////////////// // // miscellaneous routines in alphabetic order @@ -478,7 +823,7 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib, // since all interesting data is in the nsFreeTypeFace object // we do not currently need to use request_data fterror = (*nsFreeType::nsFT_New_Face)(nsFreeType::GetLibrary(), - faceID->GetFilename(), + faceID->GetFilename(), faceID->GetFaceIndex(), aFace); if (fterror) return fterror; @@ -487,7 +832,8 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib, FT_UShort platform_id = TT_PLATFORM_MICROSOFT; FT_UShort encoding_id = TT_MS_ID_UNICODE_CS; nsFontCatalogEntry* fce = faceID->GetFce(); - nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); + nsTTFontFamilyEncoderInfo *ffei = + nsFreeType::GetCustomEncoderInfo(fce->mFamilyName); if (ffei) { platform_id = ffei->mEncodingInfo->mCmapPlatformID; encoding_id = ffei->mEncodingInfo->mCmapEncoding; @@ -497,7 +843,7 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib, && (face->charmaps[i]->encoding_id == encoding_id)) { fterror = (*nsFreeType::nsFT_Set_Charmap)(face, face->charmaps[i]); if (fterror) { - FREETYPE_FONT_PRINTF(("failed to set cmap")); + FREETYPE_PRINTF(("failed to set cmap")); (*nsFreeType::nsFT_Done_Face)(face); *aFace = nsnull; } @@ -513,19 +859,99 @@ nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce) // We need to have separate keys for the different faces in a ttc file. // We append a slash and the face index to the file name to give us a // unique key for each ttc face. - nsCAutoString key_str(nsFT2FontCatalog::GetFileName(aFce)); + nsCAutoString key_str(aFce->mFontFileName); key_str.Append('/'); - key_str.AppendInt(nsFT2FontCatalog::GetFaceIndex(aFce)); + key_str.AppendInt(aFce->mFaceIndex); nsCStringKey key(key_str); nsFreeTypeFace *face = (nsFreeTypeFace *)gFreeTypeFaces->Get(&key); if (!face) { - face = new nsFreeTypeFace(aFce); + face = new nsFreeTypeFace; NS_ASSERTION(face, "memory error while creating nsFreeTypeFace"); if (!face) return nsnull; + nsresult rv = face->Init(aFce); + if (NS_FAILED(rv)) + return nsnull; gFreeTypeFaces->Put(&key, face); } return face; } -#endif /* (!defined(MOZ_ENABLE_FREETYPE2)) */ +nsTTFontFamilyEncoderInfo gFontFamilyEncoderInfo[] = { + { "symbol", &FEI_Adobe_Symbol_Encoding }, + { "cmr10", &FEI_x_ttf_cmr, }, + { "cmmi10", &FEI_x_ttf_cmmi, }, + { "cmsy10", &FEI_x_ttf_cmsy, }, + { "cmex10", &FEI_x_ttf_cmex, }, + { "math1", &FEI_x_mathematica1, }, + { "math1-bold", &FEI_x_mathematica1, }, + { "math1mono", &FEI_x_mathematica1, }, + { "math1mono-bold", &FEI_x_mathematica1, }, + { "math2", &FEI_x_mathematica2, }, + { "math2-bold", &FEI_x_mathematica2, }, + { "math2mono", &FEI_x_mathematica2, }, + { "math2mono-bold", &FEI_x_mathematica2, }, + { "ahMn", &FEI_x_mathematica3, }, // weird name for Math3 + { "math3", &FEI_x_mathematica3, }, + { "math3-bold", &FEI_x_mathematica3, }, + { "math3mono", &FEI_x_mathematica3, }, + { "math3mono-bold", &FEI_x_mathematica3, }, + { "math4", &FEI_x_mathematica4, }, + { "math4-bold", &FEI_x_mathematica4, }, + { "math4mono", &FEI_x_mathematica4, }, + { "math4mono-bold", &FEI_x_mathematica4, }, + { "math5", &FEI_x_mathematica5, }, + { "math5-bold", &FEI_x_mathematica5, }, + { "math5bold", &FEI_x_mathematica5, }, + { "math5mono", &FEI_x_mathematica5, }, + { "math5mono-bold", &FEI_x_mathematica5, }, + { "math5monobold", &FEI_x_mathematica5, }, + { "mtextra", &FEI_x_mtextra, }, + { "mt extra", &FEI_x_mtextra, }, + { "wingdings", &FEI_windows_1252, }, + { "webdings", &FEI_windows_1252, }, + { nsnull }, +}; + +nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[] = { +{ TT_OS2_CPR1_LATIN1, "iso8859-1" }, +{ TT_OS2_CPR1_LATIN2, "iso8859-2" }, +{ TT_OS2_CPR1_CYRILLIC, "iso8859-5" }, +{ TT_OS2_CPR1_GREEK, "iso8859-7" }, +{ TT_OS2_CPR1_TURKISH, "iso8859-9" }, +{ TT_OS2_CPR1_HEBREW, "iso8859-8" }, +{ TT_OS2_CPR1_ARABIC, "iso8859-6" }, +{ TT_OS2_CPR1_BALTIC, "iso8859-13" }, +{ TT_OS2_CPR1_VIETNAMESE, "viscii1.1-1" }, +{ TT_OS2_CPR1_THAI, "tis620.2533-1" }, +{ TT_OS2_CPR1_JAPANESE, "jisx0208.1990-0" }, +{ TT_OS2_CPR1_CHINESE_SIMP, "gb2312.1980-1" }, +{ TT_OS2_CPR1_KO_WANSUNG, "ksc5601.1992-3" }, +{ TT_OS2_CPR1_CHINESE_TRAD, "big5-0" }, +{ TT_OS2_CPR1_KO_JOHAB, "ksc5601.1992-3" }, +{ TT_OS2_CPR1_MAC_ROMAN, "iso8859-1" }, +{ TT_OS2_CPR1_OEM, "fontspecific-0" }, +{ TT_OS2_CPR1_SYMBOL, "fontspecific-0" }, +{ 0, nsnull }, +}; + +nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[] = { +{ TT_OS2_CPR2_GREEK, "iso8859-7" }, +{ TT_OS2_CPR2_RUSSIAN, "koi8-r" }, +{ TT_OS2_CPR2_NORDIC, "iso8859-10" }, +{ TT_OS2_CPR2_ARABIC, "iso8859-6" }, +{ TT_OS2_CPR2_CA_FRENCH, "iso8859-1" }, +{ TT_OS2_CPR2_HEBREW, "iso8859-8" }, +{ TT_OS2_CPR2_ICELANDIC, "iso8859-1" }, +{ TT_OS2_CPR2_PORTUGESE, "iso8859-1" }, +{ TT_OS2_CPR2_TURKISH, "iso8859-9" }, +{ TT_OS2_CPR2_CYRILLIC, "iso8859-5" }, +{ TT_OS2_CPR2_LATIN2, "iso8859-2" }, +{ TT_OS2_CPR2_BALTIC, "iso8859-4" }, +{ TT_OS2_CPR2_GREEK_437G, "iso8859-7" }, +{ TT_OS2_CPR2_ARABIC_708, "iso8859-6" }, +{ TT_OS2_CPR2_WE_LATIN1, "iso8859-1" }, +{ TT_OS2_CPR2_US, "iso8859-1" }, +{ 0, nsnull }, +}; + diff --git a/mozilla/gfx/src/freetype/nsFreeType.h b/mozilla/gfx/src/freetype/nsFreeType.h index e949d65be7f..58d1caa20da 100644 --- a/mozilla/gfx/src/freetype/nsFreeType.h +++ b/mozilla/gfx/src/freetype/nsFreeType.h @@ -24,23 +24,68 @@ #ifndef nsFreeType_h__ #define nsFreeType_h__ +#if (defined(MOZ_ENABLE_FREETYPE2)) + void nsFreeTypeFreeGlobals(void); nsresult nsFreeTypeInitGlobals(void); -#if (defined(MOZ_ENABLE_FREETYPE2)) - +#include "nspr.h" +#include "nsHashtable.h" +#include "nsICharsetConverterManager2.h" +#include "nsIFontCatalogService.h" #include #include FT_FREETYPE_H #include FT_CACHE_H #include FT_CACHE_IMAGE_H #include FT_TRUETYPE_TABLES_H -#include "nsFT2FontCatalog.h" typedef struct FT_FaceRec_* FT_Face; -class nsFreeTypeFace; +typedef struct { + const char *mFontFileName; + time_t mMTime; + PRUint32 mFlags; + const char *mFontType; + int mFaceIndex; + int mNumFaces; + const char *mFamilyName; + const char *mStyleName; + FT_UShort mWeight; + FT_UShort mWidth; + int mNumGlyphs; + int mNumUsableGlyphs; + FT_Long mFaceFlags; + FT_Long mStyleFlags; + FT_Long mCodePageRange1; + FT_Long mCodePageRange2; + char mVendorID[5]; + const char *mFoundryName; + int mNumEmbeddedBitmaps; + int *mEmbeddedBitmapHeights; + PRUint16 *mCCMap; // compressed char map +} nsFontCatalogEntry; -nsFreeTypeFace * nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce); +#define FCE_FLAGS_ISVALID 0x01 +#define FCE_FLAGS_UNICODE 0x02 +#define FCE_FLAGS_SYMBOL 0x04 +#define FREE_IF(x) if(x) free((void*)x) + +typedef struct { + const char *mConverterName; + PRUint8 mCmapPlatformID; + PRUint8 mCmapEncoding; + nsIUnicodeEncoder* mConverter; +} nsTTFontEncoderInfo; + +typedef struct nsTTFontFamilyEncoderInfo { + const char *mFamilyName; + nsTTFontEncoderInfo *mEncodingInfo; +} nsTTFontFamilyEncoderInfo; + +typedef struct { + unsigned long bit; + const char *charsetName; +} nsulCodePageRangeCharSetName; // // the FreeType2 function type declarations @@ -65,6 +110,10 @@ typedef FT_Error (*FTC_Manager_New_t)(FT_Library, FT_UInt, FT_UInt, FT_ULong, FTC_Face_Requester, FT_Pointer, FTC_Manager*); typedef FT_Error (*FTC_Image_Cache_New_t)(FTC_Manager, FTC_Image_Cache*); +class nsFreeTypeFace; + +nsFreeTypeFace * nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce); + // class nsFreeType class definition class nsFreeType { public: @@ -75,6 +124,11 @@ public: static void FreeGlobals(); static nsresult InitGlobals(); + static PRUint16* GetCCMap(nsFontCatalogEntry *aFce); + static const char* GetRange1CharSetName(unsigned long aBit); + static const char* GetRange2CharSetName(unsigned long aBit); + static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(const char *); + // run time loaded (function pointers) static FT_Done_Face_t nsFT_Done_Face; static FT_Done_FreeType_t nsFT_Done_FreeType; @@ -108,6 +162,7 @@ protected: static PRBool InitLibrary(); static PRBool LoadSharedLib(); static void UnloadSharedLib(); + static nsICharsetConverterManager2* GetCharSetManager(); static PRLibrary *sSharedLib; static PRBool sInited; @@ -116,21 +171,35 @@ protected: static FT_Library sFreeTypeLibrary; static FTC_Manager sFTCacheManager; static FTC_Image_Cache sImageCache; + + static nsHashtable *sFontFamilies; + static nsHashtable *sRange1CharSetNames; + static nsHashtable *sRange2CharSetNames; + static nsICharsetConverterManager2* sCharSetManager; }; // class nsFreeTypeFace definition /* this simple record is used to model a given `installed' face */ -class nsFreeTypeFace { +class nsFreeTypeFace : public nsITrueTypeFontCatalogEntry { public: - nsFreeTypeFace(nsFontCatalogEntry *aFce); - ~nsFreeTypeFace(); + NS_DECL_ISUPPORTS + NS_DECL_NSITRUETYPEFONTCATALOGENTRY + + nsFreeTypeFace(); + virtual ~nsFreeTypeFace(); + virtual nsresult Init(nsFontCatalogEntry *aFce); + /* additional members */ + NS_IMETHODIMP GetFontCatalogType(PRUint16 *aFontCatalogType); + static PRBool FreeFace(nsHashKey* aKey, void* aData, void* aClosure); - const char *GetFilename() { return nsFT2FontCatalog::GetFileName(mFce); } - int *GetEmbeddedBitmapHeights() { - return nsFT2FontCatalog::GetEmbeddedBitmapHeights(mFce); } ; - int GetFaceIndex() { return nsFT2FontCatalog::GetFaceIndex(mFce); } - int GetNumEmbeddedBitmaps() { - return nsFT2FontCatalog::GetNumEmbeddedBitmaps(mFce); } ; + const char *GetFilename() + { return mFce->mFontFileName; } + int *GetEmbeddedBitmapHeights() + { return mFce->mEmbeddedBitmapHeights; } ; + int GetFaceIndex() + { return mFce->mFaceIndex; } + int GetNumEmbeddedBitmaps() + { return mFce->mNumEmbeddedBitmaps; } ; PRUint16 *GetCCMap(); nsFontCatalogEntry* GetFce() { return mFce; }; diff --git a/mozilla/gfx/src/gtk/Makefile.in b/mozilla/gfx/src/gtk/Makefile.in index 1bc1d9ab54f..7714b57f8d2 100644 --- a/mozilla/gfx/src/gtk/Makefile.in +++ b/mozilla/gfx/src/gtk/Makefile.in @@ -60,7 +60,6 @@ CSRCS = nsPrintdGTK.c X11SHARED_LCPPSRCS = \ nsAntiAliasedGlyph.cpp \ nsFontFreeType.cpp \ - nsFreeType.cpp \ nsFT2FontNode.cpp \ nsFT2FontCatalog.cpp \ nsX11AlphaBlend.cpp \ @@ -187,12 +186,14 @@ LOCAL_INCLUDES = \ -I$(srcdir)/. \ -I$(srcdir)/.. \ -I$(srcdir)/../shared \ + -I$(srcdir)/../freetype \ -I$(srcdir)/../x11shared \ $(NULL) ifdef MOZ_ENABLE_FREETYPE2 DEFINES += -DMOZ_ENABLE_FREETYPE2 INCLUDES += $(FT2_CFLAGS) +EXTRA_DSO_LDOPTS += $(LIBS_DIR) -lgfxft2 # due to runtime linking with PR_LoadLibrary # EXTRA_DSO_LDOPTS does not need $(FT2_LIBS) endif diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h index b6bafa5c4fe..cd90a491d5e 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h @@ -52,6 +52,7 @@ #include "nsICharRepresentable.h" #include "nsCompressedCharMap.h" #include "nsIFontMetricsGTK.h" +#include "nsIFontCatalogService.h" #include #include @@ -91,7 +92,7 @@ struct nsFontStretch char* mScalable; PRBool mOutlineScaled; nsVoidArray mScaledFonts; - nsFreeTypeFace * mFreeTypeFaceID; + nsITrueTypeFontCatalogEntry* mFreeTypeFaceID; }; struct nsFontStyle diff --git a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp index 2adbd36cd6a..fb2d5585cd6 100644 --- a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp +++ b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp @@ -70,6 +70,7 @@ #include "nsFontMetricsUtils.h" #include "nsPrintSession.h" #include "gfxImageFrame.h" +#include "x11shared/nsFT2FontCatalog.h" // objects that just require generic constructors @@ -89,6 +90,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK) #endif NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFT2FontCatalog) // our custom constructors @@ -284,6 +286,10 @@ static const nsModuleComponentInfo components[] = NS_PRINTSESSION_CID, "@mozilla.org/gfx/printsession;1", nsPrintSessionConstructor }, + { "TrueType Font Catalog Service", + NS_FONTCATALOGSERVICE_CID, + "@mozilla.org/gfx/xfontcatalogservice;1", + nsFT2FontCatalogConstructor }, #ifdef NATIVE_THEME_SUPPORT { "Native Theme Renderer", NS_THEMERENDERER_CID, diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp index a891d0e9d2f..1e2a243750a 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp @@ -38,6 +38,21 @@ * * ***** END LICENSE BLOCK ***** */ +/* + * since this patch won't delete "gfx/src/freetype/nsFT2FontCatalog.h", + * using "x11shared/nsFT2FontCatalog.h" will prevent this file from + * including that "nsFT2FontCatalog.h". This can be changed to + * "#include nsFT2FontCatalog.h" safely after deleting + * unused "freetype/nsFT2FontCatalog.h" + */ + +#include "x11shared/nsFT2FontCatalog.h" +#include "nsFontDebug.h" + +PRUint32 gFontDebug = 0 | NS_FONT_DEBUG_FONT_SCAN; + +#if (defined(MOZ_ENABLE_FREETYPE2)) + #include #include #include @@ -50,9 +65,7 @@ #include "nsLocalFileUnix.h" #include "nsIEnumerator.h" #include "nsITimelineService.h" -#include "nsFT2FontCatalog.h" -#if (defined(MOZ_ENABLE_FREETYPE2)) // // Short overview: // This code is here primarily to solve this problem: getting the list @@ -95,133 +108,103 @@ extern "C" {char *ctime(const time_t *timep);} #include FT_FREETYPE_H #include FT_TRUETYPE_TABLES_H #include FT_TRUETYPE_IDS_H -#include "nsFreeType.h" -#include "nsFontDebug.h" // these should be static but the compilier complains extern nsFontVendorName sVendorNamesList[]; -extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[]; -extern nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[]; +extern nsulCodePageRangeLanguage ulCodePageRange1Language[]; +extern nsulCodePageRangeLanguage ulCodePageRange2Language[]; -nsFT2FontCatalog* gFT2FontCatalog = nsnull; static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kCharSetManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); -nsICharsetConverterManager2* nsFT2FontCatalog::sCharSetManager = nsnull; -nsTTFontEncoderInfo FEI_Adobe_Symbol_Encoding = { - "Adobe-Symbol-Encoding", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull -}; -nsTTFontEncoderInfo FEI_x_ttf_cmr = { - "x-ttf-cmr", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull -}; -nsTTFontEncoderInfo FEI_x_ttf_cmmi = { - "x-ttf-cmmi", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull -}; -nsTTFontEncoderInfo FEI_x_ttf_cmsy = { - "x-ttf-cmsy", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull -}; -nsTTFontEncoderInfo FEI_x_ttf_cmex = { - "x-ttf-cmex", TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, nsnull -}; -nsTTFontEncoderInfo FEI_x_mathematica1 = { - "x-mathematica1", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull -}; -nsTTFontEncoderInfo FEI_x_mathematica2 = { - "x-mathematica2", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull -}; -nsTTFontEncoderInfo FEI_x_mathematica3 = { - "x-mathematica3", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull -}; -nsTTFontEncoderInfo FEI_x_mathematica4 = { - "x-mathematica4", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull -}; -nsTTFontEncoderInfo FEI_x_mathematica5 = { - "x-mathematica5", TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, nsnull -}; -nsTTFontEncoderInfo FEI_x_mtextra = { - "x-mtextra", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull -}; -nsTTFontEncoderInfo FEI_windows_1252 = { - "windows-1252", TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, nsnull -}; +nsHashtable* nsFT2FontCatalog::sVendorNames = nsnull; +nsIPref* nsFT2FontCatalog::sPref = nsnull; -nsTTFontFamilyEncoderInfo gFontFamilyEncoderInfo[] = { - { "symbol", &FEI_Adobe_Symbol_Encoding }, - { "cmr10", &FEI_x_ttf_cmr, }, - { "cmmi10", &FEI_x_ttf_cmmi, }, - { "cmsy10", &FEI_x_ttf_cmsy, }, - { "cmex10", &FEI_x_ttf_cmex, }, - { "math1", &FEI_x_mathematica1, }, - { "math1-bold", &FEI_x_mathematica1, }, - { "math1mono", &FEI_x_mathematica1, }, - { "math1mono-bold", &FEI_x_mathematica1, }, - { "math2", &FEI_x_mathematica2, }, - { "math2-bold", &FEI_x_mathematica2, }, - { "math2mono", &FEI_x_mathematica2, }, - { "math2mono-bold", &FEI_x_mathematica2, }, - { "ahMn", &FEI_x_mathematica3, }, // weird name for Math3 - { "math3", &FEI_x_mathematica3, }, - { "math3-bold", &FEI_x_mathematica3, }, - { "math3mono", &FEI_x_mathematica3, }, - { "math3mono-bold", &FEI_x_mathematica3, }, - { "math4", &FEI_x_mathematica4, }, - { "math4-bold", &FEI_x_mathematica4, }, - { "math4mono", &FEI_x_mathematica4, }, - { "math4mono-bold", &FEI_x_mathematica4, }, - { "math5", &FEI_x_mathematica5, }, - { "math5-bold", &FEI_x_mathematica5, }, - { "math5bold", &FEI_x_mathematica5, }, - { "math5mono", &FEI_x_mathematica5, }, - { "math5mono-bold", &FEI_x_mathematica5, }, - { "math5monobold", &FEI_x_mathematica5, }, - { "mtextra", &FEI_x_mtextra, }, - { "mt extra", &FEI_x_mtextra, }, - { "wingdings", &FEI_windows_1252, }, - { "webdings", &FEI_windows_1252, }, - { nsnull }, -}; +#endif -nsTTFontFamilyEncoderInfo* -nsFT2FontCatalog::GetCustomEncoderInfo(nsFontCatalogEntry *aFce) +// +// Implementation of Interfaces nsIFontCatalogService +// +NS_IMPL_ISUPPORTS1(nsFT2FontCatalog, nsIFontCatalogService) + +nsFT2FontCatalog::nsFT2FontCatalog() { - return GetCustomEncoderInfo(GetFamilyName(aFce)); -} - -nsTTFontFamilyEncoderInfo* -nsFT2FontCatalog::GetCustomEncoderInfo(const char * aFamilyName) -{ - if (!gFT2FontCatalog) - return nsnull; - - nsTTFontFamilyEncoderInfo *ffei; - nsCAutoString name(aFamilyName); - ToLowerCase(name); - nsCStringKey key(name); - ffei = (nsTTFontFamilyEncoderInfo*)gFT2FontCatalog->mFontFamilies->Get(&key); - if (!ffei) - return nsnull; - - // init the converter - if (!ffei->mEncodingInfo->mConverter) { - nsTTFontEncoderInfo *fei = ffei->mEncodingInfo; - // - // build the converter - // - nsICharsetConverterManager2* charSetManager = GetCharSetManager(); - if (!charSetManager) - return nsnull; - nsCOMPtr charset(dont_AddRef(NS_NewAtom(fei->mConverterName))); - if (charset) { - nsresult res; - res = charSetManager->GetUnicodeEncoder(charset, &fei->mConverter); - if (NS_FAILED(res)) { - return nsnull; - } - } + NS_INIT_ISUPPORTS(); + +#if (defined(MOZ_ENABLE_FREETYPE2)) + nsresult rv; + mAvailableFontCatalogService = PR_FALSE; + rv = nsFreeType::InitGlobals(); + if (NS_FAILED(rv)) { + // FreeType is not available + return; } - return ffei; + if (!InitGlobals(nsFreeType::GetLibrary())) { + // Font Catalog Service is not available + return; + } + mAvailableFontCatalogService = PR_TRUE; +#endif } +nsFT2FontCatalog::~nsFT2FontCatalog() +{ +#if (defined(MOZ_ENABLE_FREETYPE2)) + /* destructor code */ + FreeGlobals(); + // assumption: no one else use nsFreeType + nsFreeType::FreeGlobals(); +#endif +} + +NS_IMETHODIMP +nsFT2FontCatalog::GetFontCatalogEntries(const nsACString & aFamilyName, + const nsACString & aLanguage, + PRUint16 aWeight, + PRUint16 aWidth, + PRUint16 aSlant, + PRUint16 aSpacing, + nsISupportsArray **_retval) +{ +#if (!defined(MOZ_ENABLE_FREETYPE2)) + *_retval = nsnull; + return NS_OK; +#else + if (mAvailableFontCatalogService == PR_FALSE) { + *_retval = nsnull; + return NS_OK; + } + + nsFontCatalog *fc = NewFontCatalog(); + if (!fc) + return NS_ERROR_OUT_OF_MEMORY; + + GetFontNames(aFamilyName, aLanguage, aWeight, aWidth, aSlant, aSpacing, fc); + nsCOMPtr aFce; + nsCOMPtr genericFce; + nsCOMPtr entries; + NS_NewISupportsArray(getter_AddRefs(entries)); + if (!entries) + return NS_ERROR_OUT_OF_MEMORY; + + int i; + for (i = 0; i < fc->numFonts; i++) { + aFce = nsFreeTypeGetFaceID(fc->fonts[i]); + genericFce = do_QueryInterface(aFce); + entries->InsertElementAt(genericFce, 0); + } + + free(fc); + *_retval = entries; + NS_ADDREF(*_retval); +#endif + return NS_OK; +} + +//-------------------------------------------------- + +#if (defined(MOZ_ENABLE_FREETYPE2)) + void nsFT2FontCatalog::AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir) { @@ -520,7 +503,7 @@ nsFT2FontCatalog::FixUpFontCatalog(nsFontCatalog *fc) ToLowerCase(vendorID); vendorID.StripChars(" "); nsCStringKey key(vendorID); - const char *vendorStr = (const char *)mVendorNames->Get(&key); + const char *vendorStr = (const char *)sVendorNames->Get(&key); if (!vendorStr) { if (fce->mVendorID[0]) vendorStr = fce->mVendorID; @@ -551,8 +534,7 @@ PRBool nsFT2FontCatalog::FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure) { nsFontCatalogEntry *fce = (nsFontCatalogEntry *)aData; - gFT2FontCatalog->FreeFontCatalogEntry(fce); - + FreeFontCatalogEntry(fce); return PR_TRUE; } @@ -589,69 +571,23 @@ nsFT2FontCatalog::FreeFontCatalogEntry(nsFontCatalogEntry *fce) void nsFT2FontCatalog::FreeGlobals() -{ - if (gFT2FontCatalog) { - gFT2FontCatalog->doFreeGlobals(); - gFT2FontCatalog = nsnull; - } -} - -void -nsFT2FontCatalog::doFreeGlobals() { if (mFontCatalog) { - gFT2FontCatalog->FreeFontCatalog(mFontCatalog); + FreeFontCatalog(mFontCatalog); mFontCatalog = nsnull; } - // mVendorNames elements are not alloc'd so no need call Reset - delete mVendorNames; - // mFontFamilies elements are not alloc'd so no need call Reset - delete mFontFamilies; + // sVendorNames elements are not alloc'd so no need call Reset + delete sVendorNames; + + delete mRange1Language; + delete mRange2Language; - // - // release any encoders that were created - // - int i; - for (i=0; gFontFamilyEncoderInfo[i].mFamilyName; i++) { - nsTTFontFamilyEncoderInfo *ffei = &gFontFamilyEncoderInfo[i]; - nsTTFontEncoderInfo *fei = ffei->mEncodingInfo; - NS_IF_RELEASE(fei->mConverter); - } - NS_IF_RELEASE(sCharSetManager); -} - -PRUint16* -nsFT2FontCatalog::GetCCMap(nsFontCatalogEntry *aFce) -{ - nsCompressedCharMap ccmapObj; - ccmapObj.SetChars(aFce->mCCMap); - return ccmapObj.NewCCMap(); -} - -nsICharsetConverterManager2* -nsFT2FontCatalog::GetCharSetManager() -{ - if (!sCharSetManager) { - // - // get the sCharSetManager - // - nsServiceManager::GetService(kCharSetManagerCID, - NS_GET_IID(nsICharsetConverterManager2), - (nsISupports**) &sCharSetManager); - NS_ASSERTION(sCharSetManager,"failed to create the charset manager"); - } - return sCharSetManager; + NS_IF_RELEASE(sPref); } void nsFT2FontCatalog::GetDirsPrefEnumCallback(const char* aName, void* aClosure) -{ - gFT2FontCatalog->doGetDirsPrefEnumCallback(aName, aClosure); -} - -void -nsFT2FontCatalog::doGetDirsPrefEnumCallback(const char* aName, void* aClosure) { nsDirCatalog *dirCatalog = (nsDirCatalog *)aClosure; nsDirCatalogEntry *dce; @@ -659,7 +595,7 @@ nsFT2FontCatalog::doGetDirsPrefEnumCallback(const char* aName, void* aClosure) if (!dce) return; // native charset?! - mPref->CopyCharPref(aName, (char **)&dce->mDirName); + sPref->CopyCharPref(aName, (char **)&dce->mDirName); if (!dce->mDirName) return; AddDir(dirCatalog, dce); @@ -774,52 +710,105 @@ cleanup_and_return: } void -nsFT2FontCatalog::GetFontNames(const char* aPattern, nsFontCatalog* aFC) -{ - gFT2FontCatalog->doGetFontNames(aPattern, aFC); -} - -void -nsFT2FontCatalog::doGetFontNames(const char* aPattern, nsFontCatalog* aFC) +nsFT2FontCatalog::GetFontNames(const nsACString & aFamilyName, + const nsACString & aLanguage, + PRUint16 aWeight, + PRUint16 aWidth, + PRUint16 aSlant, + PRUint16 aSpacing, + nsFontCatalog* aFC) { int i; - PRBool rslt; - char *pattern, *foundry, *family, *charset, *encoding; + nsCAutoString familyName, language; + FONT_CATALOG_PRINTF(("looking for FreeType font matching")); - FONT_CATALOG_PRINTF(("looking for FreeType font matching %s", aPattern)); - nsCAutoString patt(aPattern); - ToLowerCase(patt); - pattern = strdup(patt.get()); - NS_ASSERTION(pattern, "failed to copy pattern"); - if (!pattern) - goto cleanup_and_return; + ToLowerCase(aFamilyName, familyName); + ToLowerCase(aLanguage, language); + + FONT_CATALOG_PRINTF(("familyName=%s; language=%s; " + "weight=%d; width=%d; slant=%d; spacing=%d", + familyName.get(), language.get(), + aWeight, aWidth, aSlant, aSpacing)); - rslt = ParseXLFD(pattern, &foundry, &family, &charset, &encoding); - if (!rslt) - goto cleanup_and_return; + unsigned long bit1 = GetRangeLanguage(language, CPR1); + unsigned long bit2 = GetRangeLanguage(language, CPR2); - // unable to handle "name-charset-*" - if (charset && !encoding) { - goto cleanup_and_return; + PRUint16 italicBit = 0; + switch (aSlant) { + case kFCSlantRoman: + break; + case kFCSlantItalic: + case kFCSlantOblique: + case kFCSlantReverseItalic: + case kFCSlantReverseOblique: + italicBit = 1; + break; + default: + break; } + + PRUint16 monoBit = 0; + switch (aSpacing) { + case kFCSpacingMonospace: + monoBit = 0; + break; + case kFCSpacingProportional: + monoBit = 1; + break; + default: + break; + } + + /* column headers for the debug output*/ + FONT_CATALOG_PRINTF(("%s\t%-20s\t%-8s\t%-8s\t%-8s%-8s%-8s\t%-8s\t%-8s", + "mFlags", + "mFamilyName", + "CodePageRange1", + "mCodePageRange2", + "mWeight", + "mWidth", + "mStyleFlags", + "fce->mFaceFlags", + "Ismatched")); for (i=0; inumFonts; i++) { nsFontCatalogEntry *fce = mFontCatalog->fonts[i]; - if (!(fce->mFlags&FCE_FLAGS_ISVALID)) + FONT_CATALOG_PRINTF(("%0x\t%-20s\t%08lx\t%08lx\t%i\t%i\t%08lx\t%08lx\t", + fce->mFlags, + fce->mFamilyName, + fce->mCodePageRange1, + fce->mCodePageRange2, + fce->mWeight, + fce->mWidth, + fce->mStyleFlags, + fce->mFaceFlags)); + // not all "fce" are valid + if (!fce->mFlags&FCE_FLAGS_ISVALID) continue; - if (foundry && !STRMATCH(foundry,fce->mFoundryName)) + // family + if (!familyName.IsEmpty() && !familyName.Equals(fce->mFamilyName)) continue; - if (family && !STRMATCH(family,fce->mFamilyName)) + // language + if (!language.IsEmpty() && + !((fce->mCodePageRange1 & bit1) || (fce->mCodePageRange2 & bit2))) continue; + // weight + if (aWeight && (aWeight != fce->mWeight)) + continue; + // width + if (aWidth && (aWidth != fce->mWidth)) + continue; + // slant + if (aSlant && !((fce->mStyleFlags & FT_STYLE_FLAG_ITALIC) == italicBit)) + continue; + // spacing + if (aSpacing && !((fce->mFaceFlags & FT_FACE_FLAG_FIXED_WIDTH) == monoBit)) + continue; + // match all patterns + FONT_CATALOG_PRINTF(("%s", "matching")); AddFont(aFC, fce); } - - FREE_IF(pattern); - return; - -cleanup_and_return: - FONT_CATALOG_PRINTF(("nsFT2FontCatalog::GetFontNames failed")); - FREE_IF(pattern); + FONT_CATALOG_PRINTF(("\n")); return; } @@ -950,7 +939,7 @@ nsFT2FontCatalog::GetFoundry(nsFontCatalogEntry *aFce) ToLowerCase(foundry); foundry.StripChars(" "); nsCStringKey key(foundry); - const char *vendorName = (const char *)mVendorNames->Get(&key); + const char *vendorName = (const char *)sVendorNames->Get(&key); if (!vendorName) { if (aFce->mVendorID[0]) vendorName = aFce->mVendorID; @@ -966,26 +955,6 @@ nsFT2FontCatalog::GetNumEmbeddedBitmaps(nsFontCatalogEntry *aFce) return aFce->mNumEmbeddedBitmaps; } -const char * -nsFT2FontCatalog::GetRange1CharSetName(unsigned long aBit) -{ - char buf[32]; - sprintf(buf, "0x%08lx", aBit); - nsCStringKey key(buf); - const char *charsetName = (const char *)mRange1CharSetNames->Get(&key); - return charsetName; -} - -const char * -nsFT2FontCatalog::GetRange2CharSetName(unsigned long aBit) -{ - char buf[32]; - sprintf(buf, "0x%08lx", aBit); - nsCStringKey key(buf); - const char *charsetName = (const char *)mRange2CharSetNames->Get(&key); - return charsetName; -} - PRBool nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, nsFontCatalog *aFontCatalog, @@ -1205,15 +1174,6 @@ nsFT2FontCatalog::HandleFontFile(FT_Library aFreeTypeLibrary, PRBool nsFT2FontCatalog::InitGlobals(FT_Library lib) -{ - gFT2FontCatalog = new nsFT2FontCatalog; - if (!gFT2FontCatalog) - return PR_FALSE; - return gFT2FontCatalog->doInitGlobals(lib); -} - -PRBool -nsFT2FontCatalog::doInitGlobals(FT_Library lib) { nsDirCatalog *dirCatalog = nsnull; nsCAutoString prefix("font.directory.truetype."); @@ -1223,68 +1183,55 @@ nsFT2FontCatalog::doInitGlobals(FT_Library lib) int i; #endif nsFontVendorName *vn = sVendorNamesList; - nsTTFontFamilyEncoderInfo *ff = gFontFamilyEncoderInfo; - nsulCodePageRangeCharSetName *crn = nsnull; - mPref = do_GetService(NS_PREF_CONTRACTID); - if (!mPref) + nsulCodePageRangeLanguage *crl = nsnull; + + nsServiceManager::GetService(NS_PREF_CONTRACTID, + NS_GET_IID(nsIPref), + (nsISupports**) &sPref); + if (!sPref) goto cleanup_and_return; mFontCatalog = NewFontCatalog(); if (!mFontCatalog) goto cleanup_and_return; - mVendorNames = new nsHashtable(); - if (!mVendorNames) + sVendorNames = new nsHashtable(); + if (!sVendorNames) goto cleanup_and_return; while (vn->vendorID) { nsCAutoString name(vn->vendorID); ToLowerCase(name); nsCStringKey key(name); - mVendorNames->Put(&key, (void*)vn->vendorName); + sVendorNames->Put(&key, (void*)vn->vendorName); vn++; } - mFontFamilies = new nsHashtable(); - if (!mFontFamilies) + mRange1Language = new nsHashtable(); + if (!mRange1Language) goto cleanup_and_return; - while (ff->mFamilyName) { - nsCAutoString name(ff->mFamilyName); - ToLowerCase(name); - nsCStringKey key(name); - mFontFamilies->Put(&key, (void*)ff); - ff++; + crl = ulCodePageRange1Language; + while (crl->language) { + nsCStringKey key(crl->language); + mRange1Language->Put(&key, &(crl->bit)); + crl++; } - mRange1CharSetNames = new nsHashtable(); - if (!mRange1CharSetNames) + mRange2Language = new nsHashtable(); + if (!mRange2Language) goto cleanup_and_return; - crn = ulCodePageRange1CharSetNames; - while (crn->charsetName) { - char buf[32]; - sprintf(buf, "0x%08lx", crn->bit); - nsCStringKey key(buf); - mRange1CharSetNames->Put(&key, (void*)crn->charsetName); - crn++; - } - - mRange2CharSetNames = new nsHashtable(); - if (!mRange2CharSetNames) - goto cleanup_and_return; - crn = ulCodePageRange2CharSetNames; - while (crn->charsetName) { - char buf[32]; - sprintf(buf, "0x%08lx", crn->bit); - nsCStringKey key(buf); - mRange2CharSetNames->Put(&key, (void*)crn->charsetName); - crn++; + crl = ulCodePageRange2Language; + while (crl->language) { + nsCStringKey key(crl->language); + mRange2Language->Put(&key, &(crl->bit)); + crl++; } // get dirs list from prefs dirCatalog = NewDirCatalog(); if (!dirCatalog) goto cleanup_and_return; - mPref->EnumerateChildren(prefix.get(), GetDirsPrefEnumCallback, + sPref->EnumerateChildren(prefix.get(), GetDirsPrefEnumCallback, dirCatalog); NS_TIMELINE_START_TIMER("nsFT2FontCatalog::GetFontCatalog"); @@ -1412,7 +1359,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary, if (!face->family_name) goto cleanup_and_return; nsTTFontFamilyEncoderInfo *ffei; - ffei = nsFT2FontCatalog::GetCustomEncoderInfo(face->family_name); + ffei = nsFreeType::GetCustomEncoderInfo(face->family_name); if (ffei) { fce->mFlags = FCE_FLAGS_ISVALID | FCE_FLAGS_SYMBOL; } @@ -1994,105 +1941,6 @@ nsFT2FontCatalog::ParseCCMapLine(nsCompressedCharMap *aCCMapObj, long base, return PR_TRUE; } -// -// Parse XLFD -// The input is a typical XLFD string. -// -// the XLFD entries look like this: -// -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1 -// -adobe-courier-medium-r-*-*-12-*-*-*-*-*-*-* -// -// the fields are: -// -foundry-family-weight-slant-width-style-pixelsize-pointsize- -// resolution_x-resolution_y-spacing-avg_width-registry-encoding -// -// see ftp://ftp.x.org/pub/R6.4/xc/doc/hardcopy/XLFD -// -PRBool -nsFT2FontCatalog::ParseXLFD(char *aPattern, char** aFoundry, char** aFamily, - char** aCharset, char** aEncoding) -{ - char *p; - int i; - - *aFoundry = nsnull; - *aFamily = nsnull; - *aCharset = nsnull; - *aEncoding = nsnull; - - // start of pattern - p = aPattern; - NS_ASSERTION(*p == '-',"garbled pattern: does not start with a '-'"); - if (*p++ != '-') - return PR_FALSE; - - // foundry - NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); - if (!*p) - return PR_FALSE; - if (*p == '*') - *aFoundry = nsnull; - else - *aFoundry = p; - while (*p && (*p!='-')) - p++; - if (!*p) - return PR_TRUE; // short XLFD - NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of foundry"); - *p++ = '\0'; - - // family - if (!*p) - return PR_TRUE; // short XLFD - if (*p == '*') - *aFamily = nsnull; - else - *aFamily = p; - while (*p && (*p!='-')) - p++; - if (!*p) - return PR_TRUE; // short XLFD - NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of family"); - *p++ = '\0'; - - // skip forward to charset - for (i=0; i<10; i++) { - while (*p && (*p!='-')) - p++; - if (!*p) - return PR_TRUE; // short XLFD - *p++ = '\0'; - } - - // charset - NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); - if (!*p) - return PR_FALSE; - if (*p == '*') - *aCharset = nsnull; - else - *aCharset = p; - while (*p && (*p!='-')) - p++; - if (!*p) - return PR_TRUE; // short XLFD - NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of charset"); - *p++ = '\0'; - - // encoding - NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); - if (!*p) - return PR_FALSE; - if (*p == '*') - *aEncoding = nsnull; - else - *aEncoding = p; - while (*p && (*p!='-')) - p++; - if (*p) - return PR_TRUE; // short XLFD - return PR_TRUE; -} void nsFT2FontCatalog::PrintCCMap(nsNameValuePairDB *aDB, PRUint16 *aCCMap) @@ -2299,6 +2147,23 @@ cleanup_and_return: return 0; } +unsigned long +nsFT2FontCatalog::GetRangeLanguage(const nsACString & aLanguage, + PRInt16 aRange) +{ + unsigned long *bit; + if (aLanguage.IsEmpty()) + return 0; + nsCStringKey key(aLanguage); + if (aRange == CPR1) + bit = (unsigned long *)(mRange1Language->Get(&key)); + if (aRange == CPR2) + bit = (unsigned long *)(mRange2Language->Get(&key)); + if (bit) + return *bit; + return 0; +} + nsFontVendorName sVendorNamesList[] = { { "2REB", "2Rebels" }, { "39BC", "Finley's Barcode Fonts" }, @@ -2488,46 +2353,42 @@ nsFontVendorName sVendorNamesList[] = { { nsnull, nsnull }, }; -nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[] = { -{ TT_OS2_CPR1_LATIN1, "iso8859-1" }, -{ TT_OS2_CPR1_LATIN2, "iso8859-2" }, -{ TT_OS2_CPR1_CYRILLIC, "iso8859-5" }, -{ TT_OS2_CPR1_GREEK, "iso8859-7" }, -{ TT_OS2_CPR1_TURKISH, "iso8859-9" }, -{ TT_OS2_CPR1_HEBREW, "iso8859-8" }, -{ TT_OS2_CPR1_ARABIC, "iso8859-6" }, -{ TT_OS2_CPR1_BALTIC, "iso8859-13" }, -{ TT_OS2_CPR1_VIETNAMESE, "viscii1.1-1" }, -{ TT_OS2_CPR1_THAI, "tis620.2533-1" }, -{ TT_OS2_CPR1_JAPANESE, "jisx0208.1990-0" }, -{ TT_OS2_CPR1_CHINESE_SIMP, "gb2312.1980-1" }, -{ TT_OS2_CPR1_KO_WANSUNG, "ksc5601.1992-3" }, -{ TT_OS2_CPR1_CHINESE_TRAD, "big5-0" }, -{ TT_OS2_CPR1_KO_JOHAB, "ksc5601.1992-3" }, -{ TT_OS2_CPR1_MAC_ROMAN, "iso8859-1" }, -{ TT_OS2_CPR1_OEM, "fontspecific-0" }, -{ TT_OS2_CPR1_SYMBOL, "fontspecific-0" }, -{ 0, nsnull }, + +// TODO: what TT_OS2_CPR1_OEM standard for. use "oem" temporarily. +nsulCodePageRangeLanguage ulCodePageRange1Language[] = { +{ TT_OS2_CPR1_LATIN1 | TT_OS2_CPR1_MAC_ROMAN, "latin1" }, +{ TT_OS2_CPR1_LATIN2, "latin2" }, +{ TT_OS2_CPR1_CYRILLIC, "cyrillic" }, +{ TT_OS2_CPR1_GREEK, "greek" }, +{ TT_OS2_CPR1_TURKISH, "turkish" }, +{ TT_OS2_CPR1_HEBREW, "hebrew" }, +{ TT_OS2_CPR1_ARABIC, "arabic" }, +{ TT_OS2_CPR1_BALTIC, "baltic" }, +{ TT_OS2_CPR1_VIETNAMESE, "vietnamese" }, +{ TT_OS2_CPR1_THAI, "thai" }, +{ TT_OS2_CPR1_JAPANESE, "apanese" }, +{ TT_OS2_CPR1_CHINESE_SIMP, "simplified chinese" }, +{ TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, "korean" }, +{ TT_OS2_CPR1_CHINESE_TRAD, "traditional chinese" }, +{ TT_OS2_CPR1_OEM, "oem" }, +{ TT_OS2_CPR1_SYMBOL, "symbol" }, +{ 0, nsnull }, }; -nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[] = { -{ TT_OS2_CPR2_GREEK, "iso8859-7" }, -{ TT_OS2_CPR2_RUSSIAN, "koi8-r" }, -{ TT_OS2_CPR2_NORDIC, "iso8859-10" }, -{ TT_OS2_CPR2_ARABIC, "iso8859-6" }, -{ TT_OS2_CPR2_CA_FRENCH, "iso8859-1" }, -{ TT_OS2_CPR2_HEBREW, "iso8859-8" }, -{ TT_OS2_CPR2_ICELANDIC, "iso8859-1" }, -{ TT_OS2_CPR2_PORTUGESE, "iso8859-1" }, -{ TT_OS2_CPR2_TURKISH, "iso8859-9" }, -{ TT_OS2_CPR2_CYRILLIC, "iso8859-5" }, -{ TT_OS2_CPR2_LATIN2, "iso8859-2" }, -{ TT_OS2_CPR2_BALTIC, "iso8859-4" }, -{ TT_OS2_CPR2_GREEK_437G, "iso8859-7" }, -{ TT_OS2_CPR2_ARABIC_708, "iso8859-6" }, -{ TT_OS2_CPR2_WE_LATIN1, "iso8859-1" }, -{ TT_OS2_CPR2_US, "iso8859-1" }, -{ 0, nsnull }, +nsulCodePageRangeLanguage ulCodePageRange2Language[] = { +{ TT_OS2_CPR2_GREEK | TT_OS2_CPR2_GREEK_437G, "greek" }, +{ TT_OS2_CPR2_RUSSIAN, "russian" }, +{ TT_OS2_CPR2_NORDIC, "nordic" }, +{ TT_OS2_CPR2_ARABIC | TT_OS2_CPR2_ARABIC_708, "arabic" }, +{ TT_OS2_CPR2_CA_FRENCH, "canadian french" }, +{ TT_OS2_CPR2_HEBREW, "hebrew" }, +{ TT_OS2_CPR2_ICELANDIC, "icelandic" }, +{ TT_OS2_CPR2_PORTUGESE, "portugese" }, +{ TT_OS2_CPR2_TURKISH, "turkish" }, +{ TT_OS2_CPR2_CYRILLIC, "cyrillic" }, +{ TT_OS2_CPR2_LATIN2, "latin2" }, +{ TT_OS2_CPR2_BALTIC, "baltic" }, +{ TT_OS2_CPR2_WE_LATIN1 || TT_OS2_CPR2_US, "latin1" }, +{ 0, nsnull }, }; - #endif /* #if (!defined(MOZ_ENABLE_FREETYPE2)) */ diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h index 29c5b346f27..e8621d015a4 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h @@ -41,9 +41,17 @@ #ifndef NS_FT2_FONT_CATALOG_H #define NS_FT2_FONT_CATALOG_H -#include "nspr.h" -#include "nsHashtable.h" -#include "nsIServiceManager.h" +#include "nsIFontCatalogService.h" + +#if (defined(MOZ_ENABLE_FREETYPE2)) +/* + * since this patch won't delete "gfx/src/x11shared/nsFreeType.h", + * using "freetype/nsFreeType.h" will prevent this file from + * including the one under "x11shared". This can be changed to + * "#include nsFreeType.h" safely after deleting + * unused "x11shared/nsFreeType.h". + */ +#include "freetype/nsFreeType.h" #include "nsCompressedCharMap.h" #include "nsICharRepresentable.h" @@ -51,8 +59,7 @@ #include "nsIPref.h" #include "nsNameValuePairDB.h" #include "nsICharsetConverterManager.h" -#include "nsICharsetConverterManager2.h" -#if (defined(MOZ_ENABLE_FREETYPE2)) + // // To limit the potential for namespace collision we limit the // number of Moz files that include FreeType's include (and hence @@ -80,52 +87,12 @@ typedef unsigned short FT_UShort; #define STRNMATCH(s1,s2,l) (strncmp((s1),(s2),(l))==0) #define STRCASEMATCH(s1,s2) (strcasecmp((s1),(s2))==0) -#define FREE_IF(x) if(x) free((void*)x) - -typedef struct { - const char *mConverterName; - PRUint8 mCmapPlatformID; - PRUint8 mCmapEncoding; - nsIUnicodeEncoder* mConverter; -} nsTTFontEncoderInfo; - -typedef struct nsTTFontFamilyEncoderInfo { - const char *mFamilyName; - nsTTFontEncoderInfo *mEncodingInfo; -} nsTTFontFamilyEncoderInfo; - typedef struct { const char *mDirName; // encoded in the native charset } nsDirCatalogEntry; - -#define FCE_FLAGS_ISVALID 0x01 -#define FCE_FLAGS_UNICODE 0x02 -#define FCE_FLAGS_SYMBOL 0x04 - -typedef struct { - const char *mFontFileName; - time_t mMTime; - PRUint32 mFlags; - const char *mFontType; - int mFaceIndex; - int mNumFaces; - const char *mFamilyName; - const char *mStyleName; - FT_UShort mWeight; - FT_UShort mWidth; - int mNumGlyphs; - int mNumUsableGlyphs; - FT_Long mFaceFlags; - FT_Long mStyleFlags; - FT_Long mCodePageRange1; - FT_Long mCodePageRange2; - char mVendorID[5]; - const char *mFoundryName; - int mNumEmbeddedBitmaps; - int *mEmbeddedBitmapHeights; - PRUint16 *mCCMap; // compressed char map -} nsFontCatalogEntry; +#define CPR1 1 // designate CodePageRange1 to use for "GetRangeLanguage" +#define CPR2 2 // designate CodePageRange2 to use for "GetRangeLanguage" typedef struct { nsFontCatalogEntry **fonts; @@ -146,28 +113,39 @@ typedef struct { typedef struct { unsigned long bit; - const char *charsetName; -} nsulCodePageRangeCharSetName; + const char *language; +} nsulCodePageRangeLanguage; -class nsFT2FontCatalog { -friend class nsFT2FontNode; +#endif + +class nsFT2FontCatalog : public nsIFontCatalogService { public: - static void FreeGlobals(); - static PRBool InitGlobals(FT_LibraryRec_ *); - static void GetFontNames(const char* aPattern, nsFontCatalog* aFC); + NS_DECL_ISUPPORTS + NS_DECL_NSIFONTCATALOGSERVICE - static PRUint16* GetCCMap(nsFontCatalogEntry *aFce); - static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(const char *); - static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(nsFontCatalogEntry *); + nsFT2FontCatalog(); + virtual ~nsFT2FontCatalog(); + +#if (defined(MOZ_ENABLE_FREETYPE2)) + + void FreeGlobals(); + PRBool InitGlobals(FT_LibraryRec_ *); + void GetFontNames(const nsACString & aFamilyName, + const nsACString & aLanguage, + PRUint16 aWeight, + PRUint16 aWidth, + PRUint16 aSlant, + PRUint16 aSpacing, + nsFontCatalog* aFC); static const char* GetFileName(nsFontCatalogEntry *aFce); static const char* GetFamilyName(nsFontCatalogEntry *aFce); static PRInt32* GetEmbeddedBitmapHeights(nsFontCatalogEntry *aFce); static PRInt32 GetFaceIndex(nsFontCatalogEntry *aFce); static PRInt32 GetNumEmbeddedBitmaps(nsFontCatalogEntry *aFce); - + static const char* GetFoundry(nsFontCatalogEntry *aFce); protected: - void AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir); + static void AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir); PRBool AddFceIfCurrent(const char*, nsHashtable*, PRInt64, nsFontCatalog*); void AddFont(nsFontCatalog *fc, nsFontCatalogEntry *fce); int CheckFontSummaryVersion(nsNameValuePairDB *aDB); @@ -178,22 +156,15 @@ protected: void FixUpFontCatalog(nsFontCatalog *fc); static PRBool FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure); void FreeFontCatalog(nsFontCatalog *fc); - void FreeFontCatalogEntry(nsFontCatalogEntry *); - void doFreeGlobals(); - static nsICharsetConverterManager2* GetCharSetManager(); + static void FreeFontCatalogEntry(nsFontCatalogEntry *); static void GetDirsPrefEnumCallback(const char* aName, void* aClosure); - void doGetDirsPrefEnumCallback(const char* aName, void* aClosure); int GetFontCatalog(FT_LibraryRec_*, nsFontCatalog *, nsDirCatalog *); - void doGetFontNames(const char* aPattern, nsFontCatalog* aFC); PRBool GetFontSummaryName(const nsACString &, const nsACString &, nsACString &, nsACString &); - const char* GetFoundry(nsFontCatalogEntry *aFce); - const char* GetRange1CharSetName(unsigned long aBit); - const char* GetRange2CharSetName(unsigned long aBit); + unsigned long GetRangeLanguage(const nsACString &, PRInt16 aRange); PRBool HandleFontDir(FT_LibraryRec_ *, nsFontCatalog *, const nsACString &, const nsACString &); void HandleFontFile(FT_LibraryRec_ *, nsFontCatalog *, const char*); - PRBool doInitGlobals(FT_LibraryRec_ *); PRBool IsSpace(FT_Long); nsDirCatalog *NewDirCatalog(); nsFontCatalogEntry* NewFceFromFontFile(FT_LibraryRec_*, const char*,int,int*); @@ -201,26 +172,22 @@ protected: nsFontCatalog *NewFontCatalog(); PRBool ReadFontDirSummary(const nsACString&, nsHashtable*); PRBool ParseCCMapLine(nsCompressedCharMap*,long,const char*); - PRBool ParseXLFD(char *, char**, char**, char**, char**); void PrintCCMap(nsNameValuePairDB *aDB, PRUint16 *aCCMap); void PrintFontSummaries(nsNameValuePairDB *, nsFontCatalog *); void PrintFontSummaryVersion(nsNameValuePairDB *aDB); void PrintPageBits(nsNameValuePairDB*,PRUint16*,PRUint32); int ReadFontSummaries(nsHashtable*, nsNameValuePairDB *); - nsCOMPtr mPref; + static nsIPref* sPref; nsFontCatalog *mFontCatalog; - nsHashtable *mFontFamilies; + PRPackedBool mIsNewCatalog; - nsHashtable *mVendorNames; - nsHashtable *mRange1CharSetNames; - nsHashtable *mRange2CharSetNames; - static nsICharsetConverterManager2* sCharSetManager; -}; - -extern nsFT2FontCatalog* gFT2FontCatalog; - + static nsHashtable *sVendorNames; + nsHashtable *mRange1Language; + nsHashtable *mRange2Language; + PRBool mAvailableFontCatalogService; #endif +}; #endif /* NS_FT2_FONT_CATALOG_H */ diff --git a/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp b/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp index 5fefab3c1f7..1d58ace41eb 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp @@ -39,9 +39,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsFT2FontNode.h" -#include "nsFreeType.h" #include "nsFontDebug.h" -#include "nsFontFreeType.h" #if (!defined(MOZ_ENABLE_FREETYPE2)) @@ -58,9 +56,21 @@ void nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) {}; #else +/* + * since this patch won't delete "gfx/src/x11shared/nsFreeType.h", + * using "freetype/nsFreeType.h" will prevent this file from + * including the one under "x11shared". This can be changed to + * "#include nsFreeType.h" safely after deleting + * unused "x11shared/nsFreeType.h". + */ + +#include "freetype/nsFreeType.h" +#include "nsFontFreeType.h" +#include "nsIServiceManager.h" nsHashtable* nsFT2FontNode::mFreeTypeNodes = nsnull; PRBool nsFT2FontNode::sInited = PR_FALSE; +nsIFontCatalogService* nsFT2FontNode::sFcs = nsnull; void nsFT2FontNode::FreeGlobals() @@ -70,7 +80,6 @@ nsFT2FontNode::FreeGlobals() delete mFreeTypeNodes; mFreeTypeNodes = nsnull; } - nsFreeTypeFreeGlobals(); sInited = PR_FALSE; } @@ -82,22 +91,19 @@ nsFT2FontNode::InitGlobals() sInited = PR_TRUE; - nsresult rv; - rv = nsFreeTypeInitGlobals(); - if (NS_FAILED(rv)) - return rv; - - if (!gFT2FontCatalog) + nsServiceManager::GetService("@mozilla.org/gfx/xfontcatalogservice;1", + NS_GET_IID(nsIFontCatalogService), + (nsISupports**) &sFcs); + if (!sFcs) { + NS_ERROR("Font Catalog Service init failed\n"); return NS_ERROR_FAILURE; + } mFreeTypeNodes = new nsHashtable(); if (!mFreeTypeNodes) return NS_ERROR_FAILURE; - if (gFT2FontCatalog->mFontCatalog) { - LoadNodeTable(gFT2FontCatalog->mFontCatalog); - } - //setup the weighting table + LoadNodeTable(); WeightTableInitCorrection(nsFreeTypeFont::sLinearWeightTable, nsFreeType::gAATTDarkTextMinValue, nsFreeType::gAATTDarkTextGain); @@ -108,14 +114,14 @@ nsFT2FontNode::InitGlobals() void nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) { - int i, j; + int j; PRBool rslt; + PRUint32 count, i; char *pattern, *foundry, *family, *charset, *encoding; const char *charSetName; nsFontNode *node; - nsFontCatalog * aFC; - - if (!gFT2FontCatalog) return; + nsISupportsArray* arrayFC; + nsCAutoString familyTmp, languageTmp; FONT_CATALOG_PRINTF(("looking for FreeType font matching %s", aPattern)); nsCAutoString patt(aPattern); @@ -125,8 +131,7 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) if (!pattern) goto cleanup_and_return; - rslt = gFT2FontCatalog->ParseXLFD(pattern, &foundry, &family, - &charset, &encoding); + rslt = ParseXLFD(pattern, &foundry, &family, &charset, &encoding); if (!rslt) goto cleanup_and_return; @@ -134,32 +139,46 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) if (charset && !encoding) { goto cleanup_and_return; } - - aFC = gFT2FontCatalog->NewFontCatalog(); - nsFT2FontCatalog::GetFontNames(aPattern, aFC); - - for (i=0; inumFonts; i++) { - nsFontCatalogEntry *fce = aFC->fonts[i]; + + if (family) + familyTmp.Assign(family); + + sFcs->GetFontCatalogEntries(familyTmp, languageTmp, 0, 0, 0, 0, &arrayFC); + arrayFC->Count(&count); + for (i = 0; i < count; i++) { + nsISupports* item = (nsISupports*)arrayFC->ElementAt(i); + nsCOMPtr fce = do_QueryInterface(item); + if (!fce) + continue; + nsCAutoString foundryName, familyName; + PRUint32 flags, codePageRange1, codePageRange2; + PRUint16 weight, width; + fce->GetFamilyName(familyName); + fce->GetFlags(&flags); + fce->GetWidth(&width); + fce->GetWeight(&weight); + fce->GetCodePageRange1(&codePageRange1); + fce->GetCodePageRange2(&codePageRange2); if (!charset) { // get all encoding - FONT_CATALOG_PRINTF(("found FreeType %s-%s-*-*", fce->mFoundryName, - fce->mFamilyName)); + FONT_CATALOG_PRINTF(("found FreeType %s-%s-*-*", foundryName.get(), + familyName.get())); for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (bit & fce->mCodePageRange1) { - charSetName = gFT2FontCatalog->GetRange1CharSetName(bit); + if (bit & codePageRange1) { + charSetName = nsFreeType::GetRange1CharSetName(bit); NS_ASSERTION(charSetName, "failed to get charset name"); if (!charSetName) continue; node = LoadNode(fce, charSetName, aNodes); } - if (bit & fce->mCodePageRange2) { - charSetName = gFT2FontCatalog->GetRange2CharSetName(bit); + if (bit & codePageRange2) { + charSetName = nsFreeType::GetRange2CharSetName(bit); if (!charSetName) continue; LoadNode(fce, charSetName, aNodes); } } - if (!foundry && family && fce->mFlags&FCE_FLAGS_SYMBOL) { + if (!(foundryName.get()) && familyName.get() && flags&FCE_FLAGS_SYMBOL) { // the "registry-encoding" is not used but LoadNode will fail without // some value for this LoadNode(fce, "symbol-fontspecific", aNodes); @@ -172,11 +191,11 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) charsetName.Append('-'); charsetName.Append(encoding); CharSetNameToCodeRangeBits(charsetName.get(), &cpr1_bits, &cpr2_bits); - if (!(cpr1_bits & fce->mCodePageRange1) - && !(cpr2_bits & fce->mCodePageRange2)) + if (!(cpr1_bits & codePageRange1) + && !(cpr2_bits & codePageRange2)) continue; FONT_CATALOG_PRINTF(("found FreeType -%s-%s-%s", - fce->mFamilyName,charset,encoding)); + familyName.get(),charset,encoding)); LoadNode(fce, charsetName.get(), aNodes); } } @@ -191,21 +210,20 @@ cleanup_and_return: } nsFontNode* -nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, +nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, + const char *aCharSetName, nsFontNodeArray* aNodes) { - if (!gFT2FontCatalog) - return nsnull; - nsFontCharSetMap *charSetMap = GetCharSetMap(aCharSetName); if (!charSetMap->mInfo) { return nsnull; } - const char *foundry; - foundry = gFT2FontCatalog->GetFoundry(aFce); - nsCAutoString nodeName(foundry); + nsCAutoString nodeName, familyName; + aFce->GetVendorID(nodeName); + aFce->GetFamilyName(familyName); + nodeName.Append('-'); - nodeName.Append(aFce->mFamilyName); + nodeName.Append(familyName); nodeName.Append('-'); nodeName.Append(aCharSetName); nsCStringKey key(nodeName); @@ -221,8 +239,14 @@ nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, node->mCharSetInfo = charSetMap->mInfo; } + PRInt64 styleFlags; + PRUint16 fceWeight, fceWidth; + aFce->GetStyleFlags(&styleFlags); + aFce->GetWidth(&fceWidth); + aFce->GetWeight(&fceWeight); + int styleIndex; - if (aFce->mStyleFlags & FT_STYLE_FLAG_ITALIC) + if (styleFlags & FT_STYLE_FLAG_ITALIC) styleIndex = NS_FONT_STYLE_ITALIC; else styleIndex = NS_FONT_STYLE_NORMAL; @@ -235,7 +259,7 @@ nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, node->mStyles[styleIndex] = style; } - int weightIndex = WEIGHT_INDEX(aFce->mWeight); + int weightIndex = WEIGHT_INDEX(fceWeight); nsFontWeight* weight = style->mWeights[weightIndex]; if (!weight) { weight = new nsFontWeight; @@ -245,16 +269,16 @@ nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, style->mWeights[weightIndex] = weight; } - nsFontStretch* stretch = weight->mStretches[aFce->mWidth]; + nsFontStretch* stretch = weight->mStretches[fceWidth]; if (!stretch) { stretch = new nsFontStretch; if (!stretch) { return nsnull; } - weight->mStretches[aFce->mWidth] = stretch; + weight->mStretches[fceWidth] = stretch; } if (!stretch->mFreeTypeFaceID) { - stretch->mFreeTypeFaceID = nsFreeTypeGetFaceID(aFce); + stretch->mFreeTypeFaceID = aFce; } if (aNodes) { int i, n, found = 0; @@ -272,24 +296,35 @@ nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, } PRBool -nsFT2FontNode::LoadNodeTable(nsFontCatalog *aFontCatalog) +nsFT2FontNode::LoadNodeTable() { - if (!gFT2FontCatalog) - return PR_FALSE; - - int i, j; - - for (i=0; inumFonts; i++) { + int j; + nsISupportsArray* arrayFC; + nsCAutoString family, language; + sFcs->GetFontCatalogEntries(family, language, 0, 0, 0, 0, &arrayFC); + PRUint32 count, i; + arrayFC->Count(&count); + for (i = 0; i < count; i++) { + nsISupports* item = (nsISupports*)arrayFC->ElementAt(i); const char *charsetName; - nsFontCatalogEntry *fce = aFontCatalog->fonts[i]; - if ((!fce->mFlags&FCE_FLAGS_ISVALID) - || (fce->mWeight < 100) || (fce->mWeight > 900) || (fce->mWidth > 8)) + nsCOMPtr fce = do_QueryInterface(item); + if (!fce) + continue; + PRUint32 flags, codePageRange1, codePageRange2; + PRUint16 weight, width; + fce->GetFlags(&flags); + fce->GetWidth(&width); + fce->GetWeight(&weight); + fce->GetCodePageRange1(&codePageRange1); + fce->GetCodePageRange2(&codePageRange2); + if ((!flags&FCE_FLAGS_ISVALID) + || (weight < 100) || (weight > 900) || (width > 8)) continue; for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (!(bit & fce->mCodePageRange1)) + if (!(bit & codePageRange1)) continue; - charsetName = gFT2FontCatalog->GetRange1CharSetName(bit); + charsetName = nsFreeType::GetRange1CharSetName(bit); NS_ASSERTION(charsetName, "failed to get charset name"); if (!charsetName) continue; @@ -297,17 +332,116 @@ nsFT2FontNode::LoadNodeTable(nsFontCatalog *aFontCatalog) } for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (!(bit & fce->mCodePageRange2)) + if (!(bit & codePageRange2)) continue; - charsetName = gFT2FontCatalog->GetRange2CharSetName(bit); + charsetName = nsFreeType::GetRange2CharSetName(bit); if (!charsetName) continue; LoadNode(fce, charsetName, nsnull); } } - return 0; } +// +// Parse XLFD +// The input is a typical XLFD string. +// +// the XLFD entries look like this: +// -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1 +// -adobe-courier-medium-r-*-*-12-*-*-*-*-*-*-* +// +// the fields are: +// -foundry-family-weight-slant-width-style-pixelsize-pointsize- +// resolution_x-resolution_y-spacing-avg_width-registry-encoding +// +// see ftp://ftp.x.org/pub/R6.4/xc/doc/hardcopy/XLFD +// +PRBool +nsFT2FontNode::ParseXLFD(char *aPattern, char** aFoundry, char** aFamily, + char** aCharset, char** aEncoding) +{ + char *p; + int i; + + *aFoundry = nsnull; + *aFamily = nsnull; + *aCharset = nsnull; + *aEncoding = nsnull; + + // start of pattern + p = aPattern; + NS_ASSERTION(*p == '-',"garbled pattern: does not start with a '-'"); + if (*p++ != '-') + return PR_FALSE; + + // foundry + NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); + if (!*p) + return PR_FALSE; + if (*p == '*') + *aFoundry = nsnull; + else + *aFoundry = p; + while (*p && (*p!='-')) + p++; + if (!*p) + return PR_TRUE; // short XLFD + NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of foundry"); + *p++ = '\0'; + + // family + if (!*p) + return PR_TRUE; // short XLFD + if (*p == '*') + *aFamily = nsnull; + else + *aFamily = p; + while (*p && (*p!='-')) + p++; + if (!*p) + return PR_TRUE; // short XLFD + NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of family"); + *p++ = '\0'; + + // skip forward to charset + for (i=0; i<10; i++) { + while (*p && (*p!='-')) + p++; + if (!*p) + return PR_TRUE; // short XLFD + *p++ = '\0'; + } + + // charset + NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); + if (!*p) + return PR_FALSE; + if (*p == '*') + *aCharset = nsnull; + else + *aCharset = p; + while (*p && (*p!='-')) + p++; + if (!*p) + return PR_TRUE; // short XLFD + NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of charset"); + *p++ = '\0'; + + // encoding + NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern"); + if (!*p) + return PR_FALSE; + if (*p == '*') + *aEncoding = nsnull; + else + *aEncoding = p; + while (*p && (*p!='-')) + p++; + if (*p) + return PR_TRUE; // short XLFD + return PR_TRUE; +} + #endif diff --git a/mozilla/gfx/src/x11shared/nsFT2FontNode.h b/mozilla/gfx/src/x11shared/nsFT2FontNode.h index 12dccd2e6e6..d4ca46f5d5f 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontNode.h +++ b/mozilla/gfx/src/x11shared/nsFT2FontNode.h @@ -41,7 +41,6 @@ #define NS_FT2_FONT_NODE_H #include "nsFontMetricsGTK.h" -#include "nsFT2FontCatalog.h" class nsFT2FontNode { public: @@ -51,10 +50,14 @@ public: #if (defined(MOZ_ENABLE_FREETYPE2)) protected: - static nsFontNode* LoadNode(nsFontCatalogEntry*,const char*,nsFontNodeArray*); - static PRBool LoadNodeTable(nsFontCatalog *); + static PRBool ParseXLFD(char *, char**, char**, char**, char**); + static nsFontNode* LoadNode(nsITrueTypeFontCatalogEntry*, + const char*, + nsFontNodeArray*); + static PRBool LoadNodeTable(); static nsHashtable *mFreeTypeNodes; static PRBool sInited; + static nsIFontCatalogService* sFcs; #endif //MOZ_ENABLE_FREETYPE2 }; diff --git a/mozilla/gfx/src/x11shared/nsFontFreeType.cpp b/mozilla/gfx/src/x11shared/nsFontFreeType.cpp index c1fb8e3c4a6..40ba17b1a32 100644 --- a/mozilla/gfx/src/x11shared/nsFontFreeType.cpp +++ b/mozilla/gfx/src/x11shared/nsFontFreeType.cpp @@ -44,20 +44,21 @@ #endif #include "nsFontFreeType.h" -#include "nsX11AlphaBlend.h" -#include "nsAntiAliasedGlyph.h" -#include "nsFontDebug.h" #if (!defined(MOZ_ENABLE_FREETYPE2)) nsFreeTypeFont * -nsFreeTypeFont::NewFont(nsFreeTypeFace *, PRUint16, const char *) +nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *) { return nsnull; } #else +#include "nsX11AlphaBlend.h" +#include "nsAntiAliasedGlyph.h" +#include "nsFontDebug.h" + // macros to handle FreeType2 26.6 numbers (26 bit number with 6 bit fraction) #define FT_CEIL(x) (((x) + 63) & -64) #define FT_FLOOR(x) ((x) & -64) @@ -78,7 +79,7 @@ PRUint8 nsFreeTypeFont::sLinearWeightTable[256]; // class nsFreeTypeXImage : public nsFreeTypeFont { public: - nsFreeTypeXImage(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, + nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID, PRUint16 aPixelSize, const char *aName); gint DrawString(nsRenderingContextGTK* aContext, nsDrawingSurfaceGTK* aSurface, nscoord aX, @@ -93,8 +94,8 @@ protected: // class nsFreeTypeXImageSBC : public nsFreeTypeXImage { public: - nsFreeTypeXImageSBC(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, - const char *aName); + nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID, + PRUint16 aPixelSize, const char *aName); #ifdef MOZ_MATHML virtual nsresult GetBoundingMetrics(const PRUnichar* aString, PRUint32 aLength, @@ -133,8 +134,8 @@ nsFreeTypeFont::nsFreeTypeFont() } nsFreeTypeFont * -nsFreeTypeFont::NewFont(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, - const char *aName) +nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID, + PRUint16 aPixelSize, const char *aName) { // for now we only support ximage (XGetImage/alpha-blend/XPutImage) display // when we support XRender then we will need to test if it is @@ -142,8 +143,10 @@ nsFreeTypeFont::NewFont(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, PRBool ximage = PR_TRUE; PRBool render = PR_FALSE; nsFreeTypeFont *ftfont; - nsFontCatalogEntry* fce = aFaceID->GetFce(); - nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); + nsCAutoString familyName; + aFaceID->GetFamilyName(familyName); + nsTTFontFamilyEncoderInfo *ffei = + nsFreeType::GetCustomEncoderInfo(familyName.get()); if (ximage) { if (ffei) { ftfont = new nsFreeTypeXImageSBC(aFaceID, aPixelSize, aName); @@ -174,7 +177,7 @@ nsFreeTypeFont::getFTFace() return face; } -nsFreeTypeFont::nsFreeTypeFont(nsFreeTypeFace *aFaceID, +nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID, PRUint16 aPixelSize, const char *aName) { PRBool anti_alias = PR_TRUE; @@ -197,12 +200,14 @@ nsFreeTypeFont::nsFreeTypeFont(nsFreeTypeFace *aFaceID, if (nsFreeType::gFreeType2Unhinted) mImageDesc.image_type |= ftc_image_flag_unhinted; + PRUint32 num_embedded_bitmaps, i; + PRInt32* embedded_bitmapheights; + mFaceID->GetEmbeddedBitmapHeights(&num_embedded_bitmaps, + &embedded_bitmapheights); // check if we have an embedded bitmap if (aPixelSize <= nsFreeType::gEmbeddedBitmapMaximumHeight) { - int num_embedded_bitmaps = mFaceID->GetNumEmbeddedBitmaps(); if (num_embedded_bitmaps) { - int *embedded_bitmapheights = mFaceID->GetEmbeddedBitmapHeights(); - for (int i=0; iGetCCMap(); + PRUint32 size; + mFaceID->GetCCMap(&size, &mCCMap); #ifdef NS_FONT_DEBUG_LOAD_FONT + nsCAutoString fileName; + mFaceID->GetFileName(fileName); if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) { printf("loaded \"%s\", size=%d, filename=%s\n", - mName, mSize, mFaceID->GetFilename()); + mName, mSize, fileName.get()); } #endif } @@ -568,8 +576,8 @@ nsFreeTypeXImage::nsFreeTypeXImage() NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage"); } -nsFreeTypeXImage::nsFreeTypeXImage(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, - const char *aName) +nsFreeTypeXImage::nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID, + PRUint16 aPixelSize, const char *aName) : nsFreeTypeFont(aFaceID, aPixelSize, aName) { //NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage"); @@ -779,7 +787,7 @@ nsFreeTypeXImageSBC::nsFreeTypeXImageSBC() NS_ERROR("should never call nsFreeTypeXImageSBC::nsFreeTypeXImageSBC"); } -nsFreeTypeXImageSBC::nsFreeTypeXImageSBC(nsFreeTypeFace *aFaceID, +nsFreeTypeXImageSBC::nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID, PRUint16 aPixelSize, const char *aName) : nsFreeTypeXImage(aFaceID, aPixelSize, aName) @@ -796,8 +804,10 @@ nsFreeTypeXImageSBC::GetBoundingMetrics(const PRUnichar* aString, char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsFontCatalogEntry* fce = mFaceID->GetFce(); - nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); + nsCAutoString familyName; + mFaceID->GetFamilyName(familyName); + nsTTFontFamilyEncoderInfo *ffei = + nsFreeType::GetCustomEncoderInfo(familyName.get()); NS_ASSERTION(ffei,"failed to find font encoder info"); if (!ffei) return NS_ERROR_FAILURE; @@ -826,8 +836,10 @@ nsFreeTypeXImageSBC::GetWidth(const PRUnichar* aString, PRUint32 aLength) char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsFontCatalogEntry* fce = mFaceID->GetFce(); - nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); + nsCAutoString familyName; + mFaceID->GetFamilyName(familyName); + nsTTFontFamilyEncoderInfo *ffei = + nsFreeType::GetCustomEncoderInfo(familyName.get()); NS_ASSERTION(ffei,"failed to find font encoder info"); if (!ffei) return NS_ERROR_FAILURE; @@ -859,8 +871,10 @@ nsFreeTypeXImageSBC::DrawString(nsRenderingContextGTK* aContext, char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsFontCatalogEntry* fce = mFaceID->GetFce(); - nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); + nsCAutoString familyName; + mFaceID->GetFamilyName(familyName); + nsTTFontFamilyEncoderInfo *ffei = + nsFreeType::GetCustomEncoderInfo(familyName.get()); NS_ASSERTION(ffei,"failed to find font encoder info"); if (!ffei) return NS_ERROR_FAILURE; diff --git a/mozilla/gfx/src/x11shared/nsFontFreeType.h b/mozilla/gfx/src/x11shared/nsFontFreeType.h index e25b02daa83..4bffe4ceb91 100644 --- a/mozilla/gfx/src/x11shared/nsFontFreeType.h +++ b/mozilla/gfx/src/x11shared/nsFontFreeType.h @@ -41,32 +41,32 @@ #define nsFontFreeType_h__ #include "nsFontMetricsGTK.h" -#include "nsFreeType.h" +/* + * since this patch won't delete "gfx/src/x11shared/nsFreeType.h", + * using "freetype/nsFreeType.h" will prevent this file from + * including the one under "x11shared". This can be changed to + * "#include nsFreeType.h" safely after deleting + * unused "x11shared/nsFreeType.h". + */ +#include "freetype/nsFreeType.h" #if (!defined(MOZ_ENABLE_FREETYPE2)) -class nsFreeTypeFace; class nsFreeTypeFont : public nsFontGTK { public: - static nsFreeTypeFont *NewFont(nsFreeTypeFace *, PRUint16, const char *); + static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*, + PRUint16, const char *); }; #else -#include -#include FT_FREETYPE_H -#include FT_CACHE_H -#include FT_CACHE_IMAGE_H -#include FT_TRUETYPE_TABLES_H - -class nsFreeTypeFace; - class nsFreeTypeFont : public nsFontGTK { public: nsFreeTypeFont(); - nsFreeTypeFont(nsFreeTypeFace *, PRUint16, const char *); + nsFreeTypeFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *); virtual ~nsFreeTypeFont(void); - static nsFreeTypeFont *NewFont(nsFreeTypeFace *, PRUint16, const char *); + static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*, + PRUint16, const char *); void LoadFont(void); @@ -114,7 +114,7 @@ public: protected: XImage *GetXImage(PRUint32 width, PRUint32 height); - nsFreeTypeFace *mFaceID; + nsITrueTypeFontCatalogEntry *mFaceID; PRUint16 mPixelSize; FTC_Image_Desc mImageDesc; };