diff --git a/mozilla/gfx/idl/Makefile.in b/mozilla/gfx/idl/Makefile.in index 7bb87147934..48d9ce861b3 100644 --- a/mozilla/gfx/idl/Makefile.in +++ b/mozilla/gfx/idl/Makefile.in @@ -39,7 +39,6 @@ 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 deleted file mode 100644 index 3b2171b0cc4..00000000000 --- a/mozilla/gfx/idl/nsIFontCatalogService.idl +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- 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 a53bf13124a..e2e6f4499f5 100644 --- a/mozilla/gfx/public/nsGfxCIID.h +++ b/mozilla/gfx/public/nsGfxCIID.h @@ -111,9 +111,4 @@ { 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 14fcdf15c42..ed5146db89e 100644 --- a/mozilla/gfx/src/Makefile.in +++ b/mozilla/gfx/src/Makefile.in @@ -45,10 +45,6 @@ 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 deleted file mode 100644 index 6ef21d152d3..00000000000 --- a/mozilla/gfx/src/freetype/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -# -# 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 9eb74b677b8..09c23797cc4 100644 --- a/mozilla/gfx/src/freetype/nsFreeType.cpp +++ b/mozilla/gfx/src/freetype/nsFreeType.cpp @@ -38,18 +38,18 @@ * ***** 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; }; @@ -74,14 +74,7 @@ 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; @@ -148,44 +141,6 @@ 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 @@ -270,24 +225,7 @@ nsFreeType::FreeGlobals() (*nsFreeType::nsFT_Done_FreeType)(sFreeTypeLibrary); sFreeTypeLibrary = nsnull; } - - 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); - } - + nsFT2FontCatalog::FreeGlobals(); UnloadSharedLib(); ClearFunctions(); ClearGlobals(); @@ -299,9 +237,7 @@ 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) { @@ -392,49 +328,10 @@ nsFreeType::InitGlobals(void) } gFreeTypeFaces = new nsHashtable(); if (!gFreeTypeFaces) { - FreeGlobals(); return NS_ERROR_OUT_OF_MEMORY; } - - 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++; + if (!nsFT2FontCatalog::InitGlobals(nsFreeType::GetLibrary())) { + return NS_ERROR_FAILURE; } return NS_OK; @@ -526,109 +423,16 @@ 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() +nsFreeTypeFace::nsFreeTypeFace(nsFontCatalogEntry *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; - } + mFce = aFce; mCCMap = nsnull; - return NS_OK; } nsFreeTypeFace::~nsFreeTypeFace() @@ -637,156 +441,6 @@ 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) { @@ -800,11 +454,12 @@ PRUint16 * nsFreeTypeFace::GetCCMap() { if (!mCCMap) { - mCCMap = nsFreeType::GetCCMap(mFce); + mCCMap = nsFT2FontCatalog::GetCCMap(mFce); } return mCCMap; } + /////////////////////////////////////////////////////////////////////// // // miscellaneous routines in alphabetic order @@ -823,7 +478,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; @@ -832,8 +487,7 @@ 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 = - nsFreeType::GetCustomEncoderInfo(fce->mFamilyName); + nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); if (ffei) { platform_id = ffei->mEncodingInfo->mCmapPlatformID; encoding_id = ffei->mEncodingInfo->mCmapEncoding; @@ -859,99 +513,19 @@ 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(aFce->mFontFileName); + nsCAutoString key_str(nsFT2FontCatalog::GetFileName(aFce)); key_str.Append('/'); - key_str.AppendInt(aFce->mFaceIndex); + key_str.AppendInt(nsFT2FontCatalog::GetFaceIndex(aFce)); nsCStringKey key(key_str); nsFreeTypeFace *face = (nsFreeTypeFace *)gFreeTypeFaces->Get(&key); if (!face) { - face = new nsFreeTypeFace; - nsresult rv = face->Init(aFce); - if (NS_FAILED(rv)) + face = new nsFreeTypeFace(aFce); + NS_ASSERTION(face, "memory error while creating nsFreeTypeFace"); + if (!face) return nsnull; gFreeTypeFaces->Put(&key, face); } return face; } -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 }, -}; - - #endif /* (!defined(MOZ_ENABLE_FREETYPE2)) */ - diff --git a/mozilla/gfx/src/freetype/nsFreeType.h b/mozilla/gfx/src/freetype/nsFreeType.h index a0789f5736d..e949d65be7f 100644 --- a/mozilla/gfx/src/freetype/nsFreeType.h +++ b/mozilla/gfx/src/freetype/nsFreeType.h @@ -27,67 +27,20 @@ void nsFreeTypeFreeGlobals(void); nsresult nsFreeTypeInitGlobals(void); -#include "nsIFontCatalogService.h" - #if (defined(MOZ_ENABLE_FREETYPE2)) -#include "nspr.h" -#include "nsHashtable.h" -#include "nsICharsetConverterManager2.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; -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; +class nsFreeTypeFace; -#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; +nsFreeTypeFace * nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce); // // the FreeType2 function type declarations @@ -112,9 +65,6 @@ 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: @@ -125,11 +75,6 @@ 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; @@ -163,7 +108,6 @@ protected: static PRBool InitLibrary(); static PRBool LoadSharedLib(); static void UnloadSharedLib(); - static nsICharsetConverterManager2* GetCharSetManager(); static PRLibrary *sSharedLib; static PRBool sInited; @@ -172,35 +116,21 @@ 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 : public nsITrueTypeFontCatalogEntry { +class nsFreeTypeFace { public: - NS_DECL_ISUPPORTS - NS_DECL_NSITRUETYPEFONTCATALOGENTRY - - nsFreeTypeFace(); - virtual ~nsFreeTypeFace(); - virtual nsresult Init(nsFontCatalogEntry *aFce); - /* additional members */ - NS_IMETHODIMP GetFontCatalogType(PRUint16 *aFontCatalogType); - + nsFreeTypeFace(nsFontCatalogEntry *aFce); + ~nsFreeTypeFace(); static PRBool FreeFace(nsHashKey* aKey, void* aData, void* aClosure); - const char *GetFilename() - { return mFce->mFontFileName; } - int *GetEmbeddedBitmapHeights() - { return mFce->mEmbeddedBitmapHeights; } ; - int GetFaceIndex() - { return mFce->mFaceIndex; } - int GetNumEmbeddedBitmaps() - { return mFce->mNumEmbeddedBitmaps; } ; + 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); } ; PRUint16 *GetCCMap(); nsFontCatalogEntry* GetFce() { return mFce; }; diff --git a/mozilla/gfx/src/gtk/Makefile.in b/mozilla/gfx/src/gtk/Makefile.in index d2132df9148..1bc1d9ab54f 100644 --- a/mozilla/gfx/src/gtk/Makefile.in +++ b/mozilla/gfx/src/gtk/Makefile.in @@ -60,6 +60,7 @@ CSRCS = nsPrintdGTK.c X11SHARED_LCPPSRCS = \ nsAntiAliasedGlyph.cpp \ nsFontFreeType.cpp \ + nsFreeType.cpp \ nsFT2FontNode.cpp \ nsFT2FontCatalog.cpp \ nsX11AlphaBlend.cpp \ @@ -88,9 +89,6 @@ CPPSRCS += \ $(X11SHARED_LCPPSRCS) \ nsFontMetricsGTK.cpp \ nsGdkUtils.cpp -ifdef MOZ_ENABLE_FREETYPE2 -EXTRA_DSO_LDOPTS += $(LIBS_DIR) -lgfxft2 -endif endif ifdef MOZ_ENABLE_XFT @@ -189,7 +187,6 @@ LOCAL_INCLUDES = \ -I$(srcdir)/. \ -I$(srcdir)/.. \ -I$(srcdir)/../shared \ - -I$(srcdir)/../freetype \ -I$(srcdir)/../x11shared \ $(NULL) diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h index cd90a491d5e..b6bafa5c4fe 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h @@ -52,7 +52,6 @@ #include "nsICharRepresentable.h" #include "nsCompressedCharMap.h" #include "nsIFontMetricsGTK.h" -#include "nsIFontCatalogService.h" #include #include @@ -92,7 +91,7 @@ struct nsFontStretch char* mScalable; PRBool mOutlineScaled; nsVoidArray mScaledFonts; - nsITrueTypeFontCatalogEntry* mFreeTypeFaceID; + nsFreeTypeFace * mFreeTypeFaceID; }; struct nsFontStyle diff --git a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp index 1b1bf118cab..fac7990dc21 100644 --- a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp +++ b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp @@ -70,7 +70,6 @@ #include "nsFontMetricsUtils.h" #include "nsPrintSession.h" #include "gfxImageFrame.h" -#include "x11shared/nsFT2FontCatalog.h" // objects that just require generic constructors @@ -90,7 +89,6 @@ 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 @@ -286,10 +284,6 @@ 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 b6b93ca7326..a891d0e9d2f 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp @@ -50,17 +50,7 @@ #include "nsLocalFileUnix.h" #include "nsIEnumerator.h" #include "nsITimelineService.h" -#include "nsFontDebug.h" -/* - * 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" - -PRUint32 gFontDebug = 0 | NS_FONT_DEBUG_FONT_SCAN; +#include "nsFT2FontCatalog.h" #if (defined(MOZ_ENABLE_FREETYPE2)) // @@ -105,104 +95,133 @@ 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 nsulCodePageRangeLanguage ulCodePageRange1Language[]; -extern nsulCodePageRangeLanguage ulCodePageRange2Language[]; +extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[]; +extern nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[]; +nsFT2FontCatalog* gFT2FontCatalog = nsnull; static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kCharSetManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); +nsICharsetConverterManager2* nsFT2FontCatalog::sCharSetManager = nsnull; -nsHashtable* nsFT2FontCatalog::sVendorNames = nsnull; -nsIPref* nsFT2FontCatalog::sPref = 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 +}; -#endif +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 }, +}; -// -// Implementation of Interfaces nsIFontCatalogService -// -NS_IMPL_ISUPPORTS1(nsFT2FontCatalog, nsIFontCatalogService) - -nsFT2FontCatalog::nsFT2FontCatalog() +nsTTFontFamilyEncoderInfo* +nsFT2FontCatalog::GetCustomEncoderInfo(nsFontCatalogEntry *aFce) { - 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; - } - if (!InitGlobals(nsFreeType::GetLibrary())) { - // Font Catalog Service is not available - return; - } - mAvailableFontCatalogService = PR_TRUE; -#endif + return GetCustomEncoderInfo(GetFamilyName(aFce)); } -nsFT2FontCatalog::~nsFT2FontCatalog() +nsTTFontFamilyEncoderInfo* +nsFT2FontCatalog::GetCustomEncoderInfo(const char * aFamilyName) { -#if (defined(MOZ_ENABLE_FREETYPE2)) - /* destructor code */ - FreeGlobals(); - // assumption: no one else use nsFreeType - nsFreeType::FreeGlobals(); -#endif -} + if (!gFT2FontCatalog) + return nsnull; -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; + 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; + } + } } - - 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; + return ffei; } -//-------------------------------------------------- - -#if (defined(MOZ_ENABLE_FREETYPE2)) - void nsFT2FontCatalog::AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir) { @@ -501,7 +520,7 @@ nsFT2FontCatalog::FixUpFontCatalog(nsFontCatalog *fc) ToLowerCase(vendorID); vendorID.StripChars(" "); nsCStringKey key(vendorID); - const char *vendorStr = (const char *)sVendorNames->Get(&key); + const char *vendorStr = (const char *)mVendorNames->Get(&key); if (!vendorStr) { if (fce->mVendorID[0]) vendorStr = fce->mVendorID; @@ -532,7 +551,8 @@ PRBool nsFT2FontCatalog::FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure) { nsFontCatalogEntry *fce = (nsFontCatalogEntry *)aData; - FreeFontCatalogEntry(fce); + gFT2FontCatalog->FreeFontCatalogEntry(fce); + return PR_TRUE; } @@ -569,23 +589,69 @@ nsFT2FontCatalog::FreeFontCatalogEntry(nsFontCatalogEntry *fce) void nsFT2FontCatalog::FreeGlobals() +{ + if (gFT2FontCatalog) { + gFT2FontCatalog->doFreeGlobals(); + gFT2FontCatalog = nsnull; + } +} + +void +nsFT2FontCatalog::doFreeGlobals() { if (mFontCatalog) { - FreeFontCatalog(mFontCatalog); + gFT2FontCatalog->FreeFontCatalog(mFontCatalog); mFontCatalog = nsnull; } - // sVendorNames elements are not alloc'd so no need call Reset - delete sVendorNames; - - delete mRange1Language; - delete mRange2Language; + // 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; - NS_IF_RELEASE(sPref); + // + // 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; } 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; @@ -593,7 +659,7 @@ nsFT2FontCatalog::GetDirsPrefEnumCallback(const char* aName, void* aClosure) if (!dce) return; // native charset?! - sPref->CopyCharPref(aName, (char **)&dce->mDirName); + mPref->CopyCharPref(aName, (char **)&dce->mDirName); if (!dce->mDirName) return; AddDir(dirCatalog, dce); @@ -708,105 +774,52 @@ cleanup_and_return: } void -nsFT2FontCatalog::GetFontNames(const nsACString & aFamilyName, - const nsACString & aLanguage, - PRUint16 aWeight, - PRUint16 aWidth, - PRUint16 aSlant, - PRUint16 aSpacing, - nsFontCatalog* aFC) +nsFT2FontCatalog::GetFontNames(const char* aPattern, nsFontCatalog* aFC) +{ + gFT2FontCatalog->doGetFontNames(aPattern, aFC); +} + +void +nsFT2FontCatalog::doGetFontNames(const char* aPattern, nsFontCatalog* aFC) { int i; - nsCAutoString familyName, language; - FONT_CATALOG_PRINTF(("looking for FreeType font matching")); + PRBool rslt; + char *pattern, *foundry, *family, *charset, *encoding; - 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)); + 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; - unsigned long bit1 = GetRangeLanguage(language, CPR1); - unsigned long bit2 = GetRangeLanguage(language, CPR2); + rslt = ParseXLFD(pattern, &foundry, &family, &charset, &encoding); + if (!rslt) + 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; + // unable to handle "name-charset-*" + if (charset && !encoding) { + goto cleanup_and_return; } - - 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]; - 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) + if (!(fce->mFlags&FCE_FLAGS_ISVALID)) continue; - // family - if (!familyName.IsEmpty() && !familyName.Equals(fce->mFamilyName)) + if (foundry && !STRMATCH(foundry,fce->mFoundryName)) continue; - // language - if (!language.IsEmpty() && - !((fce->mCodePageRange1 & bit1) || (fce->mCodePageRange2 & bit2))) + if (family && !STRMATCH(family,fce->mFamilyName)) 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); } - FONT_CATALOG_PRINTF(("\n")); + + FREE_IF(pattern); + return; + +cleanup_and_return: + FONT_CATALOG_PRINTF(("nsFT2FontCatalog::GetFontNames failed")); + FREE_IF(pattern); return; } @@ -937,7 +950,7 @@ nsFT2FontCatalog::GetFoundry(nsFontCatalogEntry *aFce) ToLowerCase(foundry); foundry.StripChars(" "); nsCStringKey key(foundry); - const char *vendorName = (const char *)sVendorNames->Get(&key); + const char *vendorName = (const char *)mVendorNames->Get(&key); if (!vendorName) { if (aFce->mVendorID[0]) vendorName = aFce->mVendorID; @@ -953,6 +966,25 @@ 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, @@ -1173,6 +1205,15 @@ 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."); @@ -1182,55 +1223,68 @@ nsFT2FontCatalog::InitGlobals(FT_Library lib) int i; #endif nsFontVendorName *vn = sVendorNamesList; + nsTTFontFamilyEncoderInfo *ff = gFontFamilyEncoderInfo; + nsulCodePageRangeCharSetName *crn = nsnull; - nsulCodePageRangeLanguage *crl = nsnull; - - nsServiceManager::GetService(NS_PREF_CONTRACTID, - NS_GET_IID(nsIPref), - (nsISupports**) &sPref); - if (!sPref) + mPref = do_GetService(NS_PREF_CONTRACTID); + if (!mPref) goto cleanup_and_return; mFontCatalog = NewFontCatalog(); if (!mFontCatalog) goto cleanup_and_return; - sVendorNames = new nsHashtable(); - if (!sVendorNames) + mVendorNames = new nsHashtable(); + if (!mVendorNames) goto cleanup_and_return; while (vn->vendorID) { nsCAutoString name(vn->vendorID); ToLowerCase(name); nsCStringKey key(name); - sVendorNames->Put(&key, (void*)vn->vendorName); + mVendorNames->Put(&key, (void*)vn->vendorName); vn++; } - mRange1Language = new nsHashtable(); - if (!mRange1Language) + mFontFamilies = new nsHashtable(); + if (!mFontFamilies) goto cleanup_and_return; - crl = ulCodePageRange1Language; - while (crl->language) { - nsCStringKey key(crl->language); - mRange1Language->Put(&key, &(crl->bit)); - crl++; + while (ff->mFamilyName) { + nsCAutoString name(ff->mFamilyName); + ToLowerCase(name); + nsCStringKey key(name); + mFontFamilies->Put(&key, (void*)ff); + ff++; } - mRange2Language = new nsHashtable(); - if (!mRange2Language) + mRange1CharSetNames = new nsHashtable(); + if (!mRange1CharSetNames) goto cleanup_and_return; - crl = ulCodePageRange2Language; - while (crl->language) { - nsCStringKey key(crl->language); - mRange2Language->Put(&key, &(crl->bit)); - crl++; + 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++; } // get dirs list from prefs dirCatalog = NewDirCatalog(); if (!dirCatalog) goto cleanup_and_return; - sPref->EnumerateChildren(prefix.get(), GetDirsPrefEnumCallback, + mPref->EnumerateChildren(prefix.get(), GetDirsPrefEnumCallback, dirCatalog); NS_TIMELINE_START_TIMER("nsFT2FontCatalog::GetFontCatalog"); @@ -1358,7 +1412,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary, if (!face->family_name) goto cleanup_and_return; nsTTFontFamilyEncoderInfo *ffei; - ffei = nsFreeType::GetCustomEncoderInfo(face->family_name); + ffei = nsFT2FontCatalog::GetCustomEncoderInfo(face->family_name); if (ffei) { fce->mFlags = FCE_FLAGS_ISVALID | FCE_FLAGS_SYMBOL; } @@ -1940,6 +1994,105 @@ 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) @@ -2146,23 +2299,6 @@ 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" }, @@ -2352,42 +2488,46 @@ nsFontVendorName sVendorNamesList[] = { { nsnull, 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 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 }, }; -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 }, +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 }, }; + #endif /* #if (!defined(MOZ_ENABLE_FREETYPE2)) */ diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h index 8c4f3fd3c11..29c5b346f27 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h @@ -40,14 +40,10 @@ #ifndef NS_FT2_FONT_CATALOG_H #define NS_FT2_FONT_CATALOG_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" + +#include "nspr.h" +#include "nsHashtable.h" +#include "nsIServiceManager.h" #include "nsCompressedCharMap.h" #include "nsICharRepresentable.h" @@ -55,6 +51,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 @@ -83,12 +80,52 @@ 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 CPR1 1 // designate CodePageRange1 to use for "GetRangeLanguage" -#define CPR2 2 // designate CodePageRange2 to use for "GetRangeLanguage" + +#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; typedef struct { nsFontCatalogEntry **fonts; @@ -109,39 +146,28 @@ typedef struct { typedef struct { unsigned long bit; - const char *language; -} nsulCodePageRangeLanguage; + const char *charsetName; +} nsulCodePageRangeCharSetName; -#endif - -class nsFT2FontCatalog : public nsIFontCatalogService { +class nsFT2FontCatalog { +friend class nsFT2FontNode; public: - NS_DECL_ISUPPORTS - NS_DECL_NSIFONTCATALOGSERVICE + static void FreeGlobals(); + static PRBool InitGlobals(FT_LibraryRec_ *); + static void GetFontNames(const char* aPattern, nsFontCatalog* aFC); - 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 PRUint16* GetCCMap(nsFontCatalogEntry *aFce); + static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(const char *); + static nsTTFontFamilyEncoderInfo* GetCustomEncoderInfo(nsFontCatalogEntry *); 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: - static void AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir); + void AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir); PRBool AddFceIfCurrent(const char*, nsHashtable*, PRInt64, nsFontCatalog*); void AddFont(nsFontCatalog *fc, nsFontCatalogEntry *fce); int CheckFontSummaryVersion(nsNameValuePairDB *aDB); @@ -152,15 +178,22 @@ protected: void FixUpFontCatalog(nsFontCatalog *fc); static PRBool FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure); void FreeFontCatalog(nsFontCatalog *fc); - static void FreeFontCatalogEntry(nsFontCatalogEntry *); + void FreeFontCatalogEntry(nsFontCatalogEntry *); + void doFreeGlobals(); + static nsICharsetConverterManager2* GetCharSetManager(); 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 &); - unsigned long GetRangeLanguage(const nsACString &, PRInt16 aRange); + const char* GetFoundry(nsFontCatalogEntry *aFce); + const char* GetRange1CharSetName(unsigned long aBit); + const char* GetRange2CharSetName(unsigned long aBit); 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*); @@ -168,22 +201,26 @@ 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 *); - static nsIPref* sPref; + nsCOMPtr mPref; nsFontCatalog *mFontCatalog; - + nsHashtable *mFontFamilies; PRPackedBool mIsNewCatalog; - static nsHashtable *sVendorNames; - nsHashtable *mRange1Language; - nsHashtable *mRange2Language; - PRBool mAvailableFontCatalogService; -#endif + nsHashtable *mVendorNames; + nsHashtable *mRange1CharSetNames; + nsHashtable *mRange2CharSetNames; + static nsICharsetConverterManager2* sCharSetManager; }; +extern nsFT2FontCatalog* gFT2FontCatalog; + +#endif + #endif /* NS_FT2_FONT_CATALOG_H */ diff --git a/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp b/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp index 73b37ba927f..5fefab3c1f7 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontNode.cpp @@ -39,17 +39,9 @@ * ***** END LICENSE BLOCK ***** */ #include "nsFT2FontNode.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" +#include "nsFreeType.h" #include "nsFontDebug.h" #include "nsFontFreeType.h" -#include "nsIServiceManager.h" #if (!defined(MOZ_ENABLE_FREETYPE2)) @@ -69,7 +61,6 @@ void nsFT2FontNode::GetFontNames(const char* aPattern, nsHashtable* nsFT2FontNode::mFreeTypeNodes = nsnull; PRBool nsFT2FontNode::sInited = PR_FALSE; -nsIFontCatalogService* nsFT2FontNode::sFcs = nsnull; void nsFT2FontNode::FreeGlobals() @@ -79,6 +70,7 @@ nsFT2FontNode::FreeGlobals() delete mFreeTypeNodes; mFreeTypeNodes = nsnull; } + nsFreeTypeFreeGlobals(); sInited = PR_FALSE; } @@ -90,19 +82,22 @@ nsFT2FontNode::InitGlobals() sInited = PR_TRUE; - nsServiceManager::GetService("@mozilla.org/gfx/xfontcatalogservice;1", - NS_GET_IID(nsIFontCatalogService), - (nsISupports**) &sFcs); - if (!sFcs) { - NS_ERROR("Font Catalog Service init failed\n"); + nsresult rv; + rv = nsFreeTypeInitGlobals(); + if (NS_FAILED(rv)) + return rv; + + if (!gFT2FontCatalog) return NS_ERROR_FAILURE; - } mFreeTypeNodes = new nsHashtable(); if (!mFreeTypeNodes) return NS_ERROR_FAILURE; - LoadNodeTable(); + if (gFT2FontCatalog->mFontCatalog) { + LoadNodeTable(gFT2FontCatalog->mFontCatalog); + } + //setup the weighting table WeightTableInitCorrection(nsFreeTypeFont::sLinearWeightTable, nsFreeType::gAATTDarkTextMinValue, nsFreeType::gAATTDarkTextGain); @@ -113,14 +108,14 @@ nsFT2FontNode::InitGlobals() void nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) { - int j; + int i, j; PRBool rslt; - PRUint32 count, i; char *pattern, *foundry, *family, *charset, *encoding; const char *charSetName; nsFontNode *node; - nsISupportsArray* arrayFC; - nsCAutoString familyTmp, languageTmp; + nsFontCatalog * aFC; + + if (!gFT2FontCatalog) return; FONT_CATALOG_PRINTF(("looking for FreeType font matching %s", aPattern)); nsCAutoString patt(aPattern); @@ -130,7 +125,8 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) if (!pattern) goto cleanup_and_return; - rslt = ParseXLFD(pattern, &foundry, &family, &charset, &encoding); + rslt = gFT2FontCatalog->ParseXLFD(pattern, &foundry, &family, + &charset, &encoding); if (!rslt) goto cleanup_and_return; @@ -138,46 +134,32 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) if (charset && !encoding) { goto cleanup_and_return; } - - 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); + + aFC = gFT2FontCatalog->NewFontCatalog(); + nsFT2FontCatalog::GetFontNames(aPattern, aFC); + + for (i=0; inumFonts; i++) { + nsFontCatalogEntry *fce = aFC->fonts[i]; if (!charset) { // get all encoding - FONT_CATALOG_PRINTF(("found FreeType %s-%s-*-*", foundryName.get(), - familyName.get())); + FONT_CATALOG_PRINTF(("found FreeType %s-%s-*-*", fce->mFoundryName, + fce->mFamilyName)); for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (bit & codePageRange1) { - charSetName = nsFreeType::GetRange1CharSetName(bit); + if (bit & fce->mCodePageRange1) { + charSetName = gFT2FontCatalog->GetRange1CharSetName(bit); NS_ASSERTION(charSetName, "failed to get charset name"); if (!charSetName) continue; node = LoadNode(fce, charSetName, aNodes); } - if (bit & codePageRange2) { - charSetName = nsFreeType::GetRange2CharSetName(bit); + if (bit & fce->mCodePageRange2) { + charSetName = gFT2FontCatalog->GetRange2CharSetName(bit); if (!charSetName) continue; LoadNode(fce, charSetName, aNodes); } } - if (!(foundryName.get()) && familyName.get() && flags&FCE_FLAGS_SYMBOL) { + if (!foundry && family && fce->mFlags&FCE_FLAGS_SYMBOL) { // the "registry-encoding" is not used but LoadNode will fail without // some value for this LoadNode(fce, "symbol-fontspecific", aNodes); @@ -190,11 +172,11 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) charsetName.Append('-'); charsetName.Append(encoding); CharSetNameToCodeRangeBits(charsetName.get(), &cpr1_bits, &cpr2_bits); - if (!(cpr1_bits & codePageRange1) - && !(cpr2_bits & codePageRange2)) + if (!(cpr1_bits & fce->mCodePageRange1) + && !(cpr2_bits & fce->mCodePageRange2)) continue; FONT_CATALOG_PRINTF(("found FreeType -%s-%s-%s", - familyName.get(),charset,encoding)); + fce->mFamilyName,charset,encoding)); LoadNode(fce, charsetName.get(), aNodes); } } @@ -209,20 +191,21 @@ cleanup_and_return: } nsFontNode* -nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, - const char *aCharSetName, +nsFT2FontNode::LoadNode(nsFontCatalogEntry *aFce, const char *aCharSetName, nsFontNodeArray* aNodes) { + if (!gFT2FontCatalog) + return nsnull; + nsFontCharSetMap *charSetMap = GetCharSetMap(aCharSetName); if (!charSetMap->mInfo) { return nsnull; } - nsCAutoString nodeName, familyName; - aFce->GetVendorID(nodeName); - aFce->GetFamilyName(familyName); - + const char *foundry; + foundry = gFT2FontCatalog->GetFoundry(aFce); + nsCAutoString nodeName(foundry); nodeName.Append('-'); - nodeName.Append(familyName); + nodeName.Append(aFce->mFamilyName); nodeName.Append('-'); nodeName.Append(aCharSetName); nsCStringKey key(nodeName); @@ -238,14 +221,8 @@ nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, node->mCharSetInfo = charSetMap->mInfo; } - PRInt64 styleFlags; - PRUint16 fceWeight, fceWidth; - aFce->GetStyleFlags(&styleFlags); - aFce->GetWidth(&fceWidth); - aFce->GetWeight(&fceWeight); - int styleIndex; - if (styleFlags & FT_STYLE_FLAG_ITALIC) + if (aFce->mStyleFlags & FT_STYLE_FLAG_ITALIC) styleIndex = NS_FONT_STYLE_ITALIC; else styleIndex = NS_FONT_STYLE_NORMAL; @@ -258,7 +235,7 @@ nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, node->mStyles[styleIndex] = style; } - int weightIndex = WEIGHT_INDEX(fceWeight); + int weightIndex = WEIGHT_INDEX(aFce->mWeight); nsFontWeight* weight = style->mWeights[weightIndex]; if (!weight) { weight = new nsFontWeight; @@ -268,16 +245,16 @@ nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, style->mWeights[weightIndex] = weight; } - nsFontStretch* stretch = weight->mStretches[fceWidth]; + nsFontStretch* stretch = weight->mStretches[aFce->mWidth]; if (!stretch) { stretch = new nsFontStretch; if (!stretch) { return nsnull; } - weight->mStretches[fceWidth] = stretch; + weight->mStretches[aFce->mWidth] = stretch; } if (!stretch->mFreeTypeFaceID) { - stretch->mFreeTypeFaceID = aFce; + stretch->mFreeTypeFaceID = nsFreeTypeGetFaceID(aFce); } if (aNodes) { int i, n, found = 0; @@ -295,35 +272,24 @@ nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce, } PRBool -nsFT2FontNode::LoadNodeTable() +nsFT2FontNode::LoadNodeTable(nsFontCatalog *aFontCatalog) { - 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); + if (!gFT2FontCatalog) + return PR_FALSE; + + int i, j; + + for (i=0; inumFonts; i++) { const char *charsetName; - 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)) + nsFontCatalogEntry *fce = aFontCatalog->fonts[i]; + if ((!fce->mFlags&FCE_FLAGS_ISVALID) + || (fce->mWeight < 100) || (fce->mWeight > 900) || (fce->mWidth > 8)) continue; for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (!(bit & codePageRange1)) + if (!(bit & fce->mCodePageRange1)) continue; - charsetName = nsFreeType::GetRange1CharSetName(bit); + charsetName = gFT2FontCatalog->GetRange1CharSetName(bit); NS_ASSERTION(charsetName, "failed to get charset name"); if (!charsetName) continue; @@ -331,116 +297,17 @@ nsFT2FontNode::LoadNodeTable() } for (j=0; j<32; j++) { unsigned long bit = 1 << j; - if (!(bit & codePageRange2)) + if (!(bit & fce->mCodePageRange2)) continue; - charsetName = nsFreeType::GetRange2CharSetName(bit); + charsetName = gFT2FontCatalog->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 d4ca46f5d5f..12dccd2e6e6 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontNode.h +++ b/mozilla/gfx/src/x11shared/nsFT2FontNode.h @@ -41,6 +41,7 @@ #define NS_FT2_FONT_NODE_H #include "nsFontMetricsGTK.h" +#include "nsFT2FontCatalog.h" class nsFT2FontNode { public: @@ -50,14 +51,10 @@ public: #if (defined(MOZ_ENABLE_FREETYPE2)) protected: - static PRBool ParseXLFD(char *, char**, char**, char**, char**); - static nsFontNode* LoadNode(nsITrueTypeFontCatalogEntry*, - const char*, - nsFontNodeArray*); - static PRBool LoadNodeTable(); + static nsFontNode* LoadNode(nsFontCatalogEntry*,const char*,nsFontNodeArray*); + static PRBool LoadNodeTable(nsFontCatalog *); 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 d081e9bf9a3..c1fb8e3c4a6 100644 --- a/mozilla/gfx/src/x11shared/nsFontFreeType.cpp +++ b/mozilla/gfx/src/x11shared/nsFontFreeType.cpp @@ -51,7 +51,7 @@ #if (!defined(MOZ_ENABLE_FREETYPE2)) nsFreeTypeFont * -nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *) +nsFreeTypeFont::NewFont(nsFreeTypeFace *, PRUint16, const char *) { return nsnull; } @@ -78,7 +78,7 @@ PRUint8 nsFreeTypeFont::sLinearWeightTable[256]; // class nsFreeTypeXImage : public nsFreeTypeFont { public: - nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID, PRUint16 aPixelSize, + nsFreeTypeXImage(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, const char *aName); gint DrawString(nsRenderingContextGTK* aContext, nsDrawingSurfaceGTK* aSurface, nscoord aX, @@ -93,8 +93,8 @@ protected: // class nsFreeTypeXImageSBC : public nsFreeTypeXImage { public: - nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID, - PRUint16 aPixelSize, const char *aName); + nsFreeTypeXImageSBC(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, + const char *aName); #ifdef MOZ_MATHML virtual nsresult GetBoundingMetrics(const PRUnichar* aString, PRUint32 aLength, @@ -133,8 +133,8 @@ nsFreeTypeFont::nsFreeTypeFont() } nsFreeTypeFont * -nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID, - PRUint16 aPixelSize, const char *aName) +nsFreeTypeFont::NewFont(nsFreeTypeFace *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,10 +142,8 @@ nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID, PRBool ximage = PR_TRUE; PRBool render = PR_FALSE; nsFreeTypeFont *ftfont; - nsCAutoString familyName; - aFaceID->GetFamilyName(familyName); - nsTTFontFamilyEncoderInfo *ffei = - nsFreeType::GetCustomEncoderInfo(familyName.get()); + nsFontCatalogEntry* fce = aFaceID->GetFce(); + nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); if (ximage) { if (ffei) { ftfont = new nsFreeTypeXImageSBC(aFaceID, aPixelSize, aName); @@ -176,7 +174,7 @@ nsFreeTypeFont::getFTFace() return face; } -nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID, +nsFreeTypeFont::nsFreeTypeFont(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, const char *aName) { PRBool anti_alias = PR_TRUE; @@ -199,14 +197,12 @@ nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *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) { - for (i=0; iGetEmbeddedBitmapHeights(); + for (int i=0; iGetCCMap(&size, &mCCMap); + mCCMap = mFaceID->GetCCMap(); #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, fileName.get()); + mName, mSize, mFaceID->GetFilename()); } #endif } @@ -575,8 +568,8 @@ nsFreeTypeXImage::nsFreeTypeXImage() NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage"); } -nsFreeTypeXImage::nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID, - PRUint16 aPixelSize, const char *aName) +nsFreeTypeXImage::nsFreeTypeXImage(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, + const char *aName) : nsFreeTypeFont(aFaceID, aPixelSize, aName) { //NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage"); @@ -786,7 +779,7 @@ nsFreeTypeXImageSBC::nsFreeTypeXImageSBC() NS_ERROR("should never call nsFreeTypeXImageSBC::nsFreeTypeXImageSBC"); } -nsFreeTypeXImageSBC::nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID, +nsFreeTypeXImageSBC::nsFreeTypeXImageSBC(nsFreeTypeFace *aFaceID, PRUint16 aPixelSize, const char *aName) : nsFreeTypeXImage(aFaceID, aPixelSize, aName) @@ -803,10 +796,8 @@ nsFreeTypeXImageSBC::GetBoundingMetrics(const PRUnichar* aString, char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsCAutoString familyName; - mFaceID->GetFamilyName(familyName); - nsTTFontFamilyEncoderInfo *ffei = - nsFreeType::GetCustomEncoderInfo(familyName.get()); + nsFontCatalogEntry* fce = mFaceID->GetFce(); + nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); NS_ASSERTION(ffei,"failed to find font encoder info"); if (!ffei) return NS_ERROR_FAILURE; @@ -835,10 +826,8 @@ nsFreeTypeXImageSBC::GetWidth(const PRUnichar* aString, PRUint32 aLength) char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsCAutoString familyName; - mFaceID->GetFamilyName(familyName); - nsTTFontFamilyEncoderInfo *ffei = - nsFreeType::GetCustomEncoderInfo(familyName.get()); + nsFontCatalogEntry* fce = mFaceID->GetFce(); + nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); NS_ASSERTION(ffei,"failed to find font encoder info"); if (!ffei) return NS_ERROR_FAILURE; @@ -870,10 +859,8 @@ nsFreeTypeXImageSBC::DrawString(nsRenderingContextGTK* aContext, char buf[512]; PRInt32 bufLen = sizeof(buf); PRInt32 stringLen = aLength; - nsCAutoString familyName; - mFaceID->GetFamilyName(familyName); - nsTTFontFamilyEncoderInfo *ffei = - nsFreeType::GetCustomEncoderInfo(familyName.get()); + nsFontCatalogEntry* fce = mFaceID->GetFce(); + nsTTFontFamilyEncoderInfo *ffei = nsFT2FontCatalog::GetCustomEncoderInfo(fce); 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 a7f7fc63d00..e25b02daa83 100644 --- a/mozilla/gfx/src/x11shared/nsFontFreeType.h +++ b/mozilla/gfx/src/x11shared/nsFontFreeType.h @@ -41,20 +41,13 @@ #define nsFontFreeType_h__ #include "nsFontMetricsGTK.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" +#include "nsFreeType.h" #if (!defined(MOZ_ENABLE_FREETYPE2)) +class nsFreeTypeFace; class nsFreeTypeFont : public nsFontGTK { public: - static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*, - PRUint16, const char *); + static nsFreeTypeFont *NewFont(nsFreeTypeFace *, PRUint16, const char *); }; #else @@ -64,15 +57,16 @@ public: #include FT_CACHE_IMAGE_H #include FT_TRUETYPE_TABLES_H +class nsFreeTypeFace; + class nsFreeTypeFont : public nsFontGTK { public: nsFreeTypeFont(); - nsFreeTypeFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *); + nsFreeTypeFont(nsFreeTypeFace *, PRUint16, const char *); virtual ~nsFreeTypeFont(void); - static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*, - PRUint16, const char *); + static nsFreeTypeFont *NewFont(nsFreeTypeFace *, PRUint16, const char *); void LoadFont(void); @@ -120,7 +114,7 @@ public: protected: XImage *GetXImage(PRUint32 width, PRUint32 height); - nsITrueTypeFontCatalogEntry *mFaceID; + nsFreeTypeFace *mFaceID; PRUint16 mPixelSize; FTC_Image_Desc mImageDesc; };