bug 180473 : make nsFreeType a xpcom service and move from shared lib to static lib

r=Louie.Zhao@sun.com, sr=alecf@netscape.com
This commit is contained in:
bstell%ix.netcom.com 2002-12-04 04:42:40 +00:00
Родитель 20a24684e0
Коммит 8c74e4e807
14 изменённых файлов: 614 добавлений и 330 удалений

Просмотреть файл

@ -40,6 +40,7 @@ XPIDLSRCS = \
nsIPrintSettings.idl \
nsIPrintSettingsService.idl \
nsIFontCatalogService.idl \
nsIFreeType2.idl \
nsIPrintSession.idl \
gfxIFormats.idl \
gfxIImageFrame.idl \

112
gfx/idl/nsIFreeType2.idl Normal file
Просмотреть файл

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 Golden Hills Computer Services code.
*
* The Initial Developer of the Original Code is Brian Stell.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Stell <bstell@ix.netcom.com>
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
%{C++
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_CACHE_H
#include FT_CACHE_IMAGE_H
#include FT_OUTLINE_H
#include FT_TRUETYPE_TABLES_H
#define NS_FREETYPE2_CONTRACTID "@mozilla.org/freetype2;1"
#define NS_FREETYPE2_CID NS_IFREETYPE2_IID
%}
[ptr] native constCharPtr(const char);
native FT_Int(FT_Int);
native FT_Long(FT_Long);
native FT_UInt(FT_UInt);
native FT_ULong(FT_ULong);
native FT_BBox(FT_BBox);
native FT_CharMap(FT_CharMap);
native FT_Error(FT_Error);
native FT_Face(FT_Face);
native FT_Glyph(FT_Glyph);
native FT_GlyphSlot(FT_GlyphSlot);
native FT_Library(FT_Library);
[ptr] native FT_Outline_p(FT_Outline);
[ptr] native const_FT_Outline_Funcs_p(const FT_Outline_Funcs);
native FT_Pointer(FT_Pointer);
native FT_Sfnt_Tag(FT_Sfnt_Tag);
native FT_Size(FT_Size);
[ptr] native FTC_Image_Desc_p(FTC_Image_Desc);
native FTC_Face_Requester(FTC_Face_Requester);
native FTC_Font(FTC_Font);
native FTC_Image_Cache(FTC_Image_Cache);
native FTC_Manager(FTC_Manager);
/*
* A XPCOM interface to the run-time loaded functions
*/
[uuid(606eac78-16d4-486a-9f0e-f180aebd449b)]
interface nsIFreeType2 : nsISupports
{
readonly attribute FT_Library library;
readonly attribute FTC_Manager FTCacheManager;
readonly attribute FTC_Image_Cache ImageCache;
void doneFace(in FT_Face face);
void doneFreeType(in FT_Library lib);
void doneGlyph(in FT_Glyph glyph);
FT_UInt getCharIndex(in FT_Face face, in FT_ULong charcode);
void getGlyph(in FT_GlyphSlot slot, out FT_Glyph glyph);
voidPtr getSfntTable(in FT_Face face, in FT_Sfnt_Tag tag);
void glyphGetCBox(in FT_Glyph glyph, in FT_UInt mode, out FT_BBox box);
void initFreeType(out FT_Library lib);
void loadGlyph(in FT_Face face, in FT_UInt gindex, in FT_Int flags);
void newFace(in FT_Library lib, in constCharPtr filename,
in FT_Long face_num, out FT_Face face);
void outlineDecompose(in FT_Outline_p outline,
in const_FT_Outline_Funcs_p funcs, in voidPtr p);
void setCharmap(in FT_Face face, in FT_CharMap charmap);
void imageCacheLookup(in FTC_Image_Cache cache, in FTC_Image_Desc_p desc,
in FT_UInt gindex, out FT_Glyph glyph);
void managerLookupSize(in FTC_Manager manager, in FTC_Font font,
out FT_Face face, out FT_Size size);
void managerDone(in FTC_Manager manager);
void managerNew(in FT_Library lib, in FT_UInt max_faces,
in FT_UInt max_sizes, in FT_ULong max_bytes,
in FTC_Face_Requester requester, in FT_Pointer req_data,
out FTC_Manager manager);
void imageCacheNew(in FTC_Manager manager, out FTC_Image_Cache cache);
};

Просмотреть файл

@ -0,0 +1 @@
Makefile

Просмотреть файл

@ -25,15 +25,15 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = gfx
LIBRARY_NAME = gfxft2
MODULE = gfx
LIBRARY_NAME = gfxft2_s
FORCE_STATIC_LIB= 1
EXPORT_LIBRARY = 1
MODULE_NAME = nsGfxFT2Module
REQUIRES = xpcom \
string \
pref \
uconv \
$(NULL)
REQUIRES = xpcom \
string \
pref \
uconv \
$(NULL)
CPPSRCS = \
nsFreeType.cpp \

Просмотреть файл

@ -52,9 +52,6 @@
#include FT_TRUETYPE_TABLES_H
#include FT_TRUETYPE_IDS_H
#include "freetype/ftcache.h"
#include "freetype/cache/ftcimage.h"
# define FREETYPE_PRINTF(x) \
PR_BEGIN_MACRO \
if (gFreeTypeDebug) { \
@ -65,18 +62,19 @@
PRUint32 gFreeTypeDebug = 0;
char* nsFreeType::gFreeType2SharedLibraryName = nsnull;
PRBool nsFreeType::gEnableFreeType2 = PR_FALSE;
PRBool nsFreeType::gFreeType2Autohinted = PR_FALSE;
PRBool nsFreeType::gFreeType2Unhinted = PR_TRUE;
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;
//
// these belong in nsFontFreeType
//
PRBool nsFreeType2::gFreeType2Autohinted = PR_FALSE;
PRBool nsFreeType2::gFreeType2Unhinted = PR_TRUE;
PRUint8 nsFreeType2::gAATTDarkTextMinValue = 64;
double nsFreeType2::gAATTDarkTextGain = 0.8;
PRInt32 nsFreeType2::gAntiAliasMinimum = 8;
PRInt32 nsFreeType2::gEmbeddedBitmapMaximumHeight = 1000000;
nsHashtable* nsFreeType2::sFontFamilies = nsnull;
nsHashtable* nsFreeType2::sRange1CharSetNames = nsnull;
nsHashtable* nsFreeType2::sRange2CharSetNames = nsnull;
nsICharsetConverterManager2* nsFreeType2::sCharSetManager = nsnull;
extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[];
extern nsulCodePageRangeCharSetName ulCodePageRange2CharSetNames[];
@ -86,65 +84,35 @@ typedef int Error;
/*FT_CALLBACK_DEF*/ FT_Error nsFreeTypeFaceRequester(FTC_FaceID, FT_Library,
FT_Pointer, FT_Face*);
static FT_Error nsFreeType__DummyFunc();
static FT_Error nsFreeType2__DummyFunc();
static nsHashtable* gFreeTypeFaces = nsnull;
static NS_DEFINE_CID(kCharSetManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
//
// Since the Freetype2 library may not be available on the user's
// system we cannot link directly to it otherwise we would fail
// to run on those systems. Instead we use function pointers to
// access its functions.
// Define the FreeType2 functions we resolve at run time.
// see the comment near nsFreeType2::DoneFace() for more info
//
// If we can load the Freetype2 library with PR_LoadLIbrary
// we to load these with pointers to its functions. If not, then
// they point to a dummy function which always returns an error.
//
// These are the Freetype2 the functions pointers
FT_Done_Face_t nsFreeType::nsFT_Done_Face;
FT_Done_FreeType_t nsFreeType::nsFT_Done_FreeType;
FT_Done_Glyph_t nsFreeType::nsFT_Done_Glyph;
FT_Get_Char_Index_t nsFreeType::nsFT_Get_Char_Index;
FT_Get_Glyph_t nsFreeType::nsFT_Get_Glyph;
FT_Get_Sfnt_Table_t nsFreeType::nsFT_Get_Sfnt_Table;
FT_Glyph_Get_CBox_t nsFreeType::nsFT_Glyph_Get_CBox;
FT_Init_FreeType_t nsFreeType::nsFT_Init_FreeType;
FT_Load_Glyph_t nsFreeType::nsFT_Load_Glyph;
FT_New_Face_t nsFreeType::nsFT_New_Face;
FT_Set_Charmap_t nsFreeType::nsFT_Set_Charmap;
FTC_Image_Cache_Lookup_t nsFreeType::nsFTC_Image_Cache_Lookup;
FTC_Manager_Lookup_Size_t nsFreeType::nsFTC_Manager_Lookup_Size;
FTC_Manager_Done_t nsFreeType::nsFTC_Manager_Done;
FTC_Manager_New_t nsFreeType::nsFTC_Manager_New;
FTC_Image_Cache_New_t nsFreeType::nsFTC_Image_Cache_New;
typedef struct {
const char *FuncName;
PRFuncPtr *FuncPtr;
} FtFuncList;
static FtFuncList FtFuncs [] = {
{"FT_Done_Face", (PRFuncPtr*)&nsFreeType::nsFT_Done_Face},
{"FT_Done_FreeType", (PRFuncPtr*)&nsFreeType::nsFT_Done_FreeType},
{"FT_Done_Glyph", (PRFuncPtr*)&nsFreeType::nsFT_Done_Glyph},
{"FT_Get_Char_Index", (PRFuncPtr*)&nsFreeType::nsFT_Get_Char_Index},
{"FT_Get_Glyph", (PRFuncPtr*)&nsFreeType::nsFT_Get_Glyph},
{"FT_Get_Sfnt_Table", (PRFuncPtr*)&nsFreeType::nsFT_Get_Sfnt_Table},
{"FT_Glyph_Get_CBox", (PRFuncPtr*)&nsFreeType::nsFT_Glyph_Get_CBox},
{"FT_Init_FreeType", (PRFuncPtr*)&nsFreeType::nsFT_Init_FreeType},
{"FT_Load_Glyph", (PRFuncPtr*)&nsFreeType::nsFT_Load_Glyph},
{"FT_New_Face", (PRFuncPtr*)&nsFreeType::nsFT_New_Face},
{"FT_Set_Charmap", (PRFuncPtr*)&nsFreeType::nsFT_Set_Charmap},
{"FTC_Image_Cache_Lookup", (PRFuncPtr*)&nsFreeType::nsFTC_Image_Cache_Lookup},
{"FTC_Manager_Lookup_Size", (PRFuncPtr*)&nsFreeType::nsFTC_Manager_Lookup_Size},
{"FTC_Manager_Done", (PRFuncPtr*)&nsFreeType::nsFTC_Manager_Done},
{"FTC_Manager_New", (PRFuncPtr*)&nsFreeType::nsFTC_Manager_New},
{"FTC_Image_Cache_New", (PRFuncPtr*)&nsFreeType::nsFTC_Image_Cache_New},
{nsnull, (PRFuncPtr*)nsnull},
#define NS_FT2_OFFSET(f) (int)&((nsFreeType2*)0)->f
FtFuncList nsFreeType2::FtFuncs [] = {
{"FT_Done_Face", NS_FT2_OFFSET(nsFT_Done_Face)},
{"FT_Done_FreeType", NS_FT2_OFFSET(nsFT_Done_FreeType)},
{"FT_Done_Glyph", NS_FT2_OFFSET(nsFT_Done_Glyph)},
{"FT_Get_Char_Index", NS_FT2_OFFSET(nsFT_Get_Char_Index)},
{"FT_Get_Glyph", NS_FT2_OFFSET(nsFT_Get_Glyph)},
{"FT_Get_Sfnt_Table", NS_FT2_OFFSET(nsFT_Get_Sfnt_Table)},
{"FT_Glyph_Get_CBox", NS_FT2_OFFSET(nsFT_Glyph_Get_CBox)},
{"FT_Init_FreeType", NS_FT2_OFFSET(nsFT_Init_FreeType)},
{"FT_Load_Glyph", NS_FT2_OFFSET(nsFT_Load_Glyph)},
{"FT_New_Face", NS_FT2_OFFSET(nsFT_New_Face)},
{"FT_Set_Charmap", NS_FT2_OFFSET(nsFT_Set_Charmap)},
{"FTC_Image_Cache_Lookup", NS_FT2_OFFSET(nsFTC_Image_Cache_Lookup)},
{"FTC_Manager_Lookup_Size", NS_FT2_OFFSET(nsFTC_Manager_Lookup_Size)},
{"FTC_Manager_Done", NS_FT2_OFFSET(nsFTC_Manager_Done)},
{"FTC_Manager_New", NS_FT2_OFFSET(nsFTC_Manager_New)},
{"FTC_Image_Cache_New", NS_FT2_OFFSET(nsFTC_Image_Cache_New)},
{nsnull, 0},
};
nsTTFontEncoderInfo FEI_Adobe_Symbol_Encoding = {
@ -187,88 +155,245 @@ nsTTFontEncoderInfo FEI_windows_1252 = {
///////////////////////////////////////////////////////////////////////
//
// class nsFreeType data/functions
// class nsFreeType2 data/functions
//
///////////////////////////////////////////////////////////////////////
// Public Functions
void
nsFreeTypeFreeGlobals()
NS_IMPL_ISUPPORTS1(nsFreeType2, nsIFreeType2);
//
// Since the Freetype2 library may not be available on the user's
// system we cannot link directly to it otherwise the whole app would
// fail to run on those systems. Instead we access the FreeType2
// functions via function pointers.
//
// If we can load the Freetype2 library with PR_LoadLIbrary we to load
// pointers to the Ft2 functions. If not, then the function pointers
// point to a dummy function which always returns an error.
//
NS_IMETHODIMP
nsFreeType2::DoneFace(FT_Face face)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Done_Face(face);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::DoneFreeType(FT_Library library)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Done_FreeType(library);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::DoneGlyph(FT_Glyph glyph)
{
// call the FreeType2 function via the function pointer
nsFT_Done_Glyph(glyph);
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GetCharIndex(FT_Face face, FT_ULong charcode, FT_UInt *index)
{
// call the FreeType2 function via the function pointer
*index = nsFT_Get_Char_Index(face, charcode);
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GetGlyph(FT_GlyphSlot slot, FT_Glyph *glyph)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Get_Glyph(slot, glyph);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GetSfntTable(FT_Face face, FT_Sfnt_Tag tag, void** table)
{
// call the FreeType2 function via the function pointer
*table = nsFT_Get_Sfnt_Table(face, tag);
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GlyphGetCBox(FT_Glyph glyph, FT_UInt mode, FT_BBox *bbox)
{
// call the FreeType2 function via the function pointer
nsFT_Glyph_Get_CBox(glyph, mode, bbox);
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::InitFreeType(FT_Library *library)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Init_FreeType(library);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::LoadGlyph(FT_Face face, FT_UInt glyph, FT_Int flags)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Load_Glyph(face, glyph, flags);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::NewFace(FT_Library library, const char *path,
FT_Long face_index, FT_Face *face)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_New_Face(library, path, face_index, face);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::OutlineDecompose(FT_Outline *outline,
const FT_Outline_Funcs *funcs, void *user)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Outline_Decompose(outline, funcs, user);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::SetCharmap(FT_Face face, FT_CharMap charmap)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFT_Set_Charmap(face, charmap);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::ImageCacheLookup(FTC_Image_Cache cache, FTC_Image_Desc *desc,
FT_UInt glyphID, FT_Glyph *glyph)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFTC_Image_Cache_Lookup(cache, desc, glyphID, glyph);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::ManagerLookupSize(FTC_Manager manager, FTC_Font font,
FT_Face *face, FT_Size *size)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFTC_Manager_Lookup_Size(manager, font, face, size);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::ManagerDone(FTC_Manager manager)
{
// call the FreeType2 function via the function pointer
nsFTC_Manager_Done(manager);
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::ManagerNew(FT_Library library, FT_UInt max_faces,
FT_UInt max_sizes, FT_ULong max_bytes,
FTC_Face_Requester requester, FT_Pointer req_data,
FTC_Manager *manager)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFTC_Manager_New(library, max_faces, max_sizes, max_bytes,
requester, req_data, manager);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::ImageCacheNew(FTC_Manager manager, FTC_Image_Cache *cache)
{
// call the FreeType2 function via the function pointer
FT_Error error = nsFTC_Image_Cache_New(manager, cache);
return error ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GetImageCache(FTC_Image_Cache *aCache)
{
nsFreeType::FreeGlobals();
*aCache = mImageCache;
return NS_OK;
}
nsresult
nsFreeTypeInitGlobals()
{
FREETYPE_PRINTF(("initialize freetype"));
nsresult rv = nsFreeType::InitGlobals();
return rv;
}
// FREETYPE Globals
PRLibrary *nsFreeType::sSharedLib;
PRBool nsFreeType::sInited;
PRBool nsFreeType::sAvailable;
FT_Library nsFreeType::sFreeTypeLibrary;
FT_Error nsFreeType::sInitError;
FTC_Manager nsFreeType::sFTCacheManager;
FTC_Image_Cache nsFreeType::sImageCache;
NS_IMETHODIMP
nsFreeType2::GetFTCacheManager(FTC_Manager *aManager)
{
*aManager = mFTCacheManager;
return NS_OK;
}
NS_IMETHODIMP
nsFreeType2::GetLibrary(FT_Library *aLibrary)
{
*aLibrary = mFreeTypeLibrary;
return NS_OK;
}
void
nsFreeType::ClearFunctions()
nsFreeType2::ClearFunctions()
{
FtFuncList *p;
void *ptr = this;
for (p=FtFuncs; p->FuncName; p++) {
*p->FuncPtr = (PRFuncPtr)&nsFreeType__DummyFunc;
*((PRFuncPtr*)((char*)ptr+p->FuncOffset)) =
(PRFuncPtr)&nsFreeType2__DummyFunc;
}
}
void
nsFreeType::ClearGlobals()
nsFreeType2::ClearGlobals()
{
sSharedLib = nsnull;
sInited = PR_FALSE;
sAvailable = PR_FALSE;
sFreeTypeLibrary = nsnull;
sInitError = 0;
sFTCacheManager = nsnull;
sImageCache = nsnull;
mSharedLib = nsnull;
mFreeTypeLibrary = nsnull;
mFTCacheManager = nsnull;
mImageCache = nsnull;
}
// I would like to make this a static member function but the compilier
// warning about converting a data pointer to a function pointer cannot
// distinguish static member functions from static data members
static FT_Error
nsFreeType__DummyFunc()
nsFreeType2__DummyFunc()
{
NS_ERROR("nsFreeType__DummyFunc should never be called");
NS_ERROR("nsFreeType2__DummyFunc should never be called");
return 1;
}
void
nsFreeType::FreeGlobals()
nsFreeType2::~nsFreeType2()
{
if (gFreeType2SharedLibraryName) {
free(gFreeType2SharedLibraryName);
gFreeType2SharedLibraryName = nsnull;
FreeGlobals();
}
void
nsFreeType2::FreeGlobals()
{
if (mFreeType2SharedLibraryName) {
free(mFreeType2SharedLibraryName);
mFreeType2SharedLibraryName = nsnull;
}
if (gFreeTypeFaces) {
gFreeTypeFaces->Reset(nsFreeTypeFace::FreeFace, nsnull);
delete gFreeTypeFaces;
gFreeTypeFaces = nsnull;
}
// sImageCache released by cache manager
if (sFTCacheManager) {
(*nsFreeType::nsFTC_Manager_Done)(sFTCacheManager);
sFTCacheManager = nsnull;
// mImageCache released by cache manager
if (mFTCacheManager) {
// use "this->" to make sure it is obivious we are calling the member func
this->ManagerDone(mFTCacheManager);
mFTCacheManager = nsnull;
}
if (sFreeTypeLibrary) {
(*nsFreeType::nsFT_Done_FreeType)(sFreeTypeLibrary);
sFreeTypeLibrary = nsnull;
if (mFreeTypeLibrary) {
// use "this->" to make sure it is obivious we are calling the member func
this->DoneFreeType(mFreeTypeLibrary);
mFreeTypeLibrary = nsnull;
}
if (sRange1CharSetNames)
@ -294,9 +419,8 @@ nsFreeType::FreeGlobals()
}
nsresult
nsFreeType::InitGlobals(void)
nsFreeType2::Init()
{
NS_ASSERTION(sInited==PR_FALSE, "InitGlobals called more than once");
// set all the globals to default values
ClearGlobals();
@ -313,17 +437,17 @@ nsFreeType::InitGlobals(void)
PRBool enable_freetype2 = PR_TRUE;
rv = mPref->GetBoolPref("font.FreeType2.enable", &enable_freetype2);
if (NS_SUCCEEDED(rv)) {
gEnableFreeType2 = enable_freetype2;
FREETYPE_PRINTF(("gEnableFreeType2 = %d", gEnableFreeType2));
mEnableFreeType2 = enable_freetype2;
FREETYPE_PRINTF(("mEnableFreeType2 = %d", mEnableFreeType2));
}
rv = mPref->GetCharPref("font.freetype2.shared-library",
&gFreeType2SharedLibraryName);
&mFreeType2SharedLibraryName);
if (NS_FAILED(rv)) {
enable_freetype2 = PR_FALSE;
FREETYPE_PRINTF((
"gFreeType2SharedLibraryName missing, FreeType2 disabled"));
gFreeType2SharedLibraryName = nsnull;
"mFreeType2SharedLibraryName missing, FreeType2 disabled"));
mFreeType2SharedLibraryName = nsnull;
}
PRBool freetype2_autohinted = PR_FALSE;
@ -371,10 +495,8 @@ nsFreeType::InitGlobals(void)
}
if (NS_FAILED(rv)) {
gEnableFreeType2 = PR_FALSE;
gFreeType2SharedLibraryName = nsnull;
gFreeType2SharedLibraryName = nsnull;
gEnableFreeType2 = PR_FALSE;
mEnableFreeType2 = PR_FALSE;
mFreeType2SharedLibraryName = nsnull;
gFreeType2Autohinted = PR_FALSE;
gFreeType2Unhinted = PR_TRUE;
gAATTDarkTextMinValue = 64;
@ -385,10 +507,9 @@ nsFreeType::InitGlobals(void)
mPref = nsnull;
if (!nsFreeType::InitLibrary()) {
// since the library may not be available on any given system
// failing to load is not considered a fatal error
// return NS_ERROR_OUT_OF_MEMORY;
if (!InitLibrary()) {
FreeGlobals();
return NS_ERROR_OUT_OF_MEMORY;
}
gFreeTypeFaces = new nsHashtable();
if (!gFreeTypeFaces) {
@ -441,77 +562,75 @@ nsFreeType::InitGlobals(void)
}
PRBool
nsFreeType::InitLibrary()
nsFreeType2::InitLibrary()
{
if (!sInited) {
sInited = PR_TRUE;
FT_Error error;
#ifdef MOZ_MATHML
// do not yet support MathML
// goto cleanup_and_return;
// do not yet support MathML
// goto cleanup_and_return;
#endif
if (!gEnableFreeType2)
return PR_FALSE;
if (!mEnableFreeType2)
return PR_FALSE;
// since the library may not be available on any given system
// failing to load is not considered a fatal error
if (!LoadSharedLib())
return PR_FALSE;
// since the library may not be available on any given system
// failing to load is not considered a fatal error
if (!LoadSharedLib())
return PR_FALSE;
sInitError = (*nsFreeType::nsFT_Init_FreeType)(&sFreeTypeLibrary);
if (sInitError) {
FREETYPE_PRINTF(("\n\n*********\nFreeType initialization error = %d",
sInitError));
sFreeTypeLibrary = nsnull;
goto cleanup_and_return;
}
FT_Error error = (*nsFreeType::nsFTC_Manager_New)(sFreeTypeLibrary,
0, 0, 0, nsFreeTypeFaceRequester, 0, &sFTCacheManager);
NS_ASSERTION(error==0, "failed to create FreeType Cache manager");
if (error)
goto cleanup_and_return;
error = (*nsFreeType::nsFTC_Image_Cache_New)(sFTCacheManager,
&sImageCache);
NS_ASSERTION(error==0, "failed to create FreeType image cache");
if (error)
goto cleanup_and_return;
sAvailable = PR_TRUE;
// use "this->" to make sure it is obivious we are calling the member func
nsresult rv = this->InitFreeType(&mFreeTypeLibrary);
if (NS_FAILED(rv)) {
FREETYPE_PRINTF(("\n\n*********\nFreeType initialization error = %d",
error));
mFreeTypeLibrary = nsnull;
goto cleanup_and_return;
}
return sAvailable;
// use "this->" to make sure it is obivious we are calling the member func
rv = this->ManagerNew(mFreeTypeLibrary, 0, 0, 0, nsFreeTypeFaceRequester,
this, &mFTCacheManager);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create FreeType Cache manager");
if (NS_FAILED(rv))
goto cleanup_and_return;
// use "this->" to make sure it is obivious we are calling the member func
rv = this->ImageCacheNew(mFTCacheManager, &mImageCache);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create FreeType image cache");
if (NS_FAILED(rv))
goto cleanup_and_return;
return PR_TRUE;
cleanup_and_return:
// clean everything up but note that init was called
FreeGlobals();
sInited = PR_TRUE;
return(sAvailable);
return(PR_FALSE);
}
PRBool
nsFreeType::LoadSharedLib()
nsFreeType2::LoadSharedLib()
{
NS_ASSERTION(sSharedLib==nsnull, "library already loaded");
NS_ASSERTION(mSharedLib==nsnull, "library already loaded");
if (!gFreeType2SharedLibraryName)
if (!mFreeType2SharedLibraryName)
return PR_FALSE;
sSharedLib = PR_LoadLibrary(gFreeType2SharedLibraryName);
mSharedLib = PR_LoadLibrary(mFreeType2SharedLibraryName);
// since the library may not be available on any given system
// failing to load is not considered a fatal error
if (!sSharedLib) {
if (!mSharedLib) {
NS_WARNING("freetype library not found");
return PR_FALSE;
}
FtFuncList *p;
PRFuncPtr func;
void *ptr = this;
for (p=FtFuncs; p->FuncName; p++) {
func = PR_FindFunctionSymbol(sSharedLib, p->FuncName);
func = PR_FindFunctionSymbol(mSharedLib, p->FuncName);
if (!func) {
NS_WARNING("nsFreeType::LoadSharedLib Error");
NS_WARNING("nsFreeType2::LoadSharedLib Error");
ClearFunctions();
return PR_FALSE;
}
*p->FuncPtr = func;
*((PRFuncPtr*)((char*)ptr+p->FuncOffset)) = func;
}
return PR_TRUE;
@ -519,15 +638,15 @@ nsFreeType::LoadSharedLib()
}
void
nsFreeType::UnloadSharedLib()
nsFreeType2::UnloadSharedLib()
{
if (sSharedLib)
PR_UnloadLibrary(sSharedLib);
sSharedLib = nsnull;
if (mSharedLib)
PR_UnloadLibrary(mSharedLib);
mSharedLib = nsnull;
}
const char *
nsFreeType::GetRange1CharSetName(unsigned long aBit)
nsFreeType2::GetRange1CharSetName(unsigned long aBit)
{
char buf[32];
sprintf(buf, "0x%08lx", aBit);
@ -537,7 +656,7 @@ nsFreeType::GetRange1CharSetName(unsigned long aBit)
}
const char *
nsFreeType::GetRange2CharSetName(unsigned long aBit)
nsFreeType2::GetRange2CharSetName(unsigned long aBit)
{
char buf[32];
sprintf(buf, "0x%08lx", aBit);
@ -547,7 +666,7 @@ nsFreeType::GetRange2CharSetName(unsigned long aBit)
}
nsTTFontFamilyEncoderInfo*
nsFreeType::GetCustomEncoderInfo(const char * aFamilyName)
nsFreeType2::GetCustomEncoderInfo(const char * aFamilyName)
{
if (!sFontFamilies)
return nsnull;
@ -582,7 +701,7 @@ nsFreeType::GetCustomEncoderInfo(const char * aFamilyName)
}
nsICharsetConverterManager2*
nsFreeType::GetCharSetManager()
nsFreeType2::GetCharSetManager()
{
if (!sCharSetManager) {
//
@ -597,7 +716,7 @@ nsFreeType::GetCharSetManager()
}
PRUint16*
nsFreeType::GetCCMap(nsFontCatalogEntry *aFce)
nsFreeType2::GetCCMap(nsFontCatalogEntry *aFce)
{
nsCompressedCharMap ccmapObj;
ccmapObj.SetChars(aFce->mCCMap);
@ -772,7 +891,7 @@ NS_IMETHODIMP nsFreeTypeFace::GetFileModTime(PRInt64 *aTime)
NS_IMETHODIMP nsFreeTypeFace::GetCCMap(
PRUint32 *size, PRUint16 **ccMaps)
{
*ccMaps = nsFreeType::GetCCMap(mFce);
*ccMaps = nsFreeType2::GetCCMap(mFce);
*size = CCMAP_SIZE(*ccMaps);
return NS_OK;
}
@ -800,7 +919,7 @@ PRUint16 *
nsFreeTypeFace::GetCCMap()
{
if (!mCCMap) {
mCCMap = nsFreeType::GetCCMap(mFce);
mCCMap = nsFreeType2::GetCCMap(mFce);
}
return mCCMap;
}
@ -817,15 +936,12 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib,
FT_Pointer request_data, FT_Face* aFace)
{
nsFreeTypeFace *faceID = (nsFreeTypeFace *)face_id;
FT_Error fterror;
FT_Error fterror = 0;
nsFreeType2 *ft2 = (nsFreeType2 *)request_data;
nsresult rv;
FT_UNUSED(request_data);
// 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->GetFaceIndex(), aFace);
if (fterror)
rv = ft2->NewFace(lib, faceID->GetFilename(), faceID->GetFaceIndex(), aFace);
if (NS_FAILED(rv))
return fterror;
FT_Face face = *aFace;
@ -833,7 +949,7 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib,
FT_UShort encoding_id = TT_MS_ID_UNICODE_CS;
nsFontCatalogEntry* fce = faceID->GetFce();
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType::GetCustomEncoderInfo(fce->mFamilyName);
nsFreeType2::GetCustomEncoderInfo(fce->mFamilyName);
if (ffei) {
platform_id = ffei->mEncodingInfo->mCmapPlatformID;
encoding_id = ffei->mEncodingInfo->mCmapEncoding;
@ -841,11 +957,12 @@ nsFreeTypeFaceRequester(FTC_FaceID face_id, FT_Library lib,
for (int i=0; i < face->num_charmaps; i++) {
if ( (face->charmaps[i]->platform_id == platform_id)
&& (face->charmaps[i]->encoding_id == encoding_id)) {
fterror = (*nsFreeType::nsFT_Set_Charmap)(face, face->charmaps[i]);
if (fterror) {
rv = ft2->SetCharmap(face, face->charmaps[i]);
if (NS_FAILED(rv)) {
FREETYPE_PRINTF(("failed to set cmap"));
(*nsFreeType::nsFT_Done_Face)(face);
ft2->DoneFace(face);
*aFace = nsnull;
fterror = 1;
}
}
}

Просмотреть файл

@ -26,13 +26,11 @@
#if (defined(MOZ_ENABLE_FREETYPE2))
void nsFreeTypeFreeGlobals(void);
nsresult nsFreeTypeInitGlobals(void);
#include "nspr.h"
#include "nsHashtable.h"
#include "nsICharsetConverterManager2.h"
#include "nsIFontCatalogService.h"
#include "nsIFreeType2.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_CACHE_H
@ -95,10 +93,12 @@ typedef FT_Error (*FT_Done_FreeType_t)(FT_Library);
typedef FT_Error (*FT_Done_Glyph_t)(FT_Glyph);
typedef FT_Error (*FT_Get_Char_Index_t)(FT_Face, FT_ULong);
typedef FT_Error (*FT_Get_Glyph_t)(FT_GlyphSlot, FT_Glyph*);
typedef FT_Error (*FT_Get_Sfnt_Table_t)(FT_Face, FT_Sfnt_Tag);
typedef void* (*FT_Get_Sfnt_Table_t)(FT_Face, FT_Sfnt_Tag);
typedef FT_Error (*FT_Glyph_Get_CBox_t)(FT_Glyph, FT_UInt, FT_BBox*);
typedef FT_Error (*FT_Init_FreeType_t)(FT_Library*);
typedef FT_Error (*FT_Load_Glyph_t)(FT_Face, FT_UInt, FT_Int);
typedef FT_Error (*FT_Outline_Decompose_t)
(FT_Outline*, const FT_Outline_Funcs*, void*);
typedef FT_Error (*FT_New_Face_t)(FT_Library, const char*, FT_Long, FT_Face*);
typedef FT_Error (*FT_Set_Charmap_t)(FT_Face face, FT_CharMap charmap);
typedef FT_Error (*FTC_Image_Cache_Lookup_t)
@ -114,41 +114,56 @@ class nsFreeTypeFace;
nsFreeTypeFace * nsFreeTypeGetFaceID(nsFontCatalogEntry *aFce);
// class nsFreeType class definition
class nsFreeType {
public:
inline PRBool FreeTypeAvailable() { return sAvailable; };
inline static FTC_Manager GetFTCacheManager() { return sFTCacheManager; };
inline static FT_Library GetLibrary() { return sFreeTypeLibrary; };
inline static FTC_Image_Cache GetImageCache() { return sImageCache; };
static void FreeGlobals();
static nsresult InitGlobals();
typedef struct {
const char *FuncName;
int FuncOffset;
} FtFuncList;
// class nsFreeType class definition
class nsFreeType2 : nsIFreeType2 {
NS_DECL_ISUPPORTS
public:
void FreeGlobals();
nsresult Init();
virtual ~nsFreeType2();
NS_DECL_NSIFREETYPE2
// these belong in nsFT2FontCatalog
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;
static FT_Done_Glyph_t nsFT_Done_Glyph;
static FT_Get_Char_Index_t nsFT_Get_Char_Index;
static FT_Get_Glyph_t nsFT_Get_Glyph;
static FT_Get_Sfnt_Table_t nsFT_Get_Sfnt_Table;
static FT_Glyph_Get_CBox_t nsFT_Glyph_Get_CBox;
static FT_Init_FreeType_t nsFT_Init_FreeType;
static FT_Load_Glyph_t nsFT_Load_Glyph;
static FT_New_Face_t nsFT_New_Face;
static FT_Set_Charmap_t nsFT_Set_Charmap;
static FTC_Image_Cache_Lookup_t nsFTC_Image_Cache_Lookup;
static FTC_Manager_Lookup_Size_t nsFTC_Manager_Lookup_Size;
static FTC_Manager_Done_t nsFTC_Manager_Done;
static FTC_Manager_New_t nsFTC_Manager_New;
static FTC_Image_Cache_New_t nsFTC_Image_Cache_New;
protected:
// run time loaded function pointers
FT_Done_Face_t nsFT_Done_Face;
FT_Done_FreeType_t nsFT_Done_FreeType;
FT_Done_Glyph_t nsFT_Done_Glyph;
FT_Get_Char_Index_t nsFT_Get_Char_Index;
FT_Get_Glyph_t nsFT_Get_Glyph;
FT_Get_Sfnt_Table_t nsFT_Get_Sfnt_Table;
FT_Glyph_Get_CBox_t nsFT_Glyph_Get_CBox;
FT_Init_FreeType_t nsFT_Init_FreeType;
FT_Load_Glyph_t nsFT_Load_Glyph;
FT_New_Face_t nsFT_New_Face;
FT_Outline_Decompose_t nsFT_Outline_Decompose;
FT_Set_Charmap_t nsFT_Set_Charmap;
FTC_Image_Cache_Lookup_t nsFTC_Image_Cache_Lookup;
FTC_Manager_Lookup_Size_t nsFTC_Manager_Lookup_Size;
FTC_Manager_Done_t nsFTC_Manager_Done;
FTC_Manager_New_t nsFTC_Manager_New;
FTC_Image_Cache_New_t nsFTC_Image_Cache_New;
// this array needs to be big enough to hold all the function pointers
static FtFuncList FtFuncs[17];
static PRBool gEnableFreeType2;
static char* gFreeType2SharedLibraryName;
protected:
PRBool mEnableFreeType2;
char* mFreeType2SharedLibraryName;
public:
// these belong in the nsFontFreeType code
static PRBool gFreeType2Autohinted;
static PRBool gFreeType2Unhinted;
static PRUint8 gAATTDarkTextMinValue;
@ -157,20 +172,19 @@ public:
static PRInt32 gEmbeddedBitmapMaximumHeight;
protected:
static void ClearGlobals();
static void ClearFunctions();
static PRBool InitLibrary();
static PRBool LoadSharedLib();
static void UnloadSharedLib();
void ClearGlobals();
void ClearFunctions();
PRBool InitLibrary();
PRBool LoadSharedLib();
void UnloadSharedLib();
// this belongs in nsFT2FontCatalog
static nsICharsetConverterManager2* GetCharSetManager();
static PRLibrary *sSharedLib;
static PRBool sInited;
static PRBool sAvailable;
static FT_Error sInitError;
static FT_Library sFreeTypeLibrary;
static FTC_Manager sFTCacheManager;
static FTC_Image_Cache sImageCache;
PRLibrary *mSharedLib;
FT_Library mFreeTypeLibrary;
FTC_Manager mFTCacheManager;
FTC_Image_Cache mImageCache;
static nsHashtable *sFontFamilies;
static nsHashtable *sRange1CharSetNames;
@ -178,7 +192,6 @@ protected:
static nsICharsetConverterManager2* sCharSetManager;
};
// class nsFreeTypeFace definition
/* this simple record is used to model a given `installed' face */
class nsFreeTypeFace : public nsITrueTypeFontCatalogEntry {
public:

Просмотреть файл

@ -128,6 +128,11 @@ endif
GARBAGE += $(X11SHARED_LCPPSRCS) $(XPU_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
ifdef MOZ_ENABLE_FREETYPE2
# the SHARED_LIBRARY_LIBS line must be before the rules.mk include
SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)gfxft2_s.$(LIB_SUFFIX)
endif
include $(topsrcdir)/config/rules.mk
ifdef MOZ_ENABLE_GTK
@ -193,9 +198,6 @@ LOCAL_INCLUDES = \
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
ifdef MOZ_ENABLE_XPRINT

Просмотреть файл

@ -71,6 +71,7 @@
#include "nsPrintSession.h"
#include "gfxImageFrame.h"
#include "x11shared/nsFT2FontCatalog.h"
#include "nsFreeType.h"
// objects that just require generic constructors
@ -91,6 +92,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFT2FontCatalog)
#ifdef MOZ_ENABLE_FREETYPE2
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFreeType2, Init)
#endif
// our custom constructors
@ -290,6 +294,12 @@ static const nsModuleComponentInfo components[] =
NS_FONTCATALOGSERVICE_CID,
"@mozilla.org/gfx/xfontcatalogservice;1",
nsFT2FontCatalogConstructor },
#ifdef MOZ_ENABLE_FREETYPE2
{ "FreeType2 routines",
NS_FREETYPE2_CID,
NS_FREETYPE2_CONTRACTID,
nsFreeType2Constructor },
#endif
#ifdef NATIVE_THEME_SUPPORT
{ "Native Theme Renderer",
NS_THEMERENDERER_CID,

Просмотреть файл

@ -134,12 +134,21 @@ nsFT2FontCatalog::nsFT2FontCatalog()
#if (defined(MOZ_ENABLE_FREETYPE2))
nsresult rv;
mAvailableFontCatalogService = PR_FALSE;
rv = nsFreeType::InitGlobals();
mFt2 = do_GetService(NS_FREETYPE2_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
// FreeType is not available
return;
}
if (!InitGlobals(nsFreeType::GetLibrary())) {
FT_Library lib;
mFt2->GetLibrary(&lib);
if (!lib) {
// FreeType is not available
return;
}
if (!InitGlobals(lib)) {
// Font Catalog Service is not available
return;
}
@ -149,12 +158,6 @@ nsFT2FontCatalog::nsFT2FontCatalog()
nsFT2FontCatalog::~nsFT2FontCatalog()
{
#if (defined(MOZ_ENABLE_FREETYPE2))
/* destructor code */
FreeGlobals();
// assumption: no one else use nsFreeType
nsFreeType::FreeGlobals();
#endif
}
NS_IMETHODIMP
@ -1320,6 +1323,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
int num_checked = 0;
int blank_chars;
nsCompressedCharMap ccmapObj;
nsresult rv;
fce = (nsFontCatalogEntry *)calloc(1, sizeof(nsFontCatalogEntry));
if (!fce)
@ -1344,9 +1348,8 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
fce->mFaceIndex = aFaceIndex;
// open the font
fterror = (*nsFreeType::nsFT_New_Face)(aFreeTypeLibrary, aFontFileName,
aFaceIndex, &face);
if (fterror) {
rv = mFt2->NewFace(aFreeTypeLibrary, aFontFileName, aFaceIndex, &face);
if (NS_FAILED(rv)) {
FONT_SCAN_PRINTF((" FreeType failed to open, error=%d", fterror));
goto cleanup_and_return;
}
@ -1359,7 +1362,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
if (!face->family_name)
goto cleanup_and_return;
nsTTFontFamilyEncoderInfo *ffei;
ffei = nsFreeType::GetCustomEncoderInfo(face->family_name);
ffei = nsFreeType2::GetCustomEncoderInfo(face->family_name);
if (ffei) {
fce->mFlags = FCE_FLAGS_ISVALID | FCE_FLAGS_SYMBOL;
}
@ -1368,8 +1371,8 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
if ( (face->charmaps[i]->platform_id == TT_PLATFORM_MICROSOFT)
&& (face->charmaps[i]->encoding_id == TT_MS_ID_UNICODE_CS)) {
fce->mFlags = FCE_FLAGS_ISVALID | FCE_FLAGS_UNICODE;
fterror = (*nsFreeType::nsFT_Set_Charmap)(face, face->charmaps[i]);
if (fterror) {
rv = mFt2->SetCharmap(face, face->charmaps[i]);
if (NS_FAILED(rv)) {
FONT_SCAN_PRINTF(("failed to select unicode charmap"));
goto cleanup_and_return;
}
@ -1381,7 +1384,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
goto cleanup_and_return;
}
tt_os2 = (TT_OS2 *)(*nsFreeType::nsFT_Get_Sfnt_Table)(face, ft_sfnt_os2);
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
if (!tt_os2) {
FONT_SCAN_PRINTF(("unable to get OS2 table"));
goto cleanup_and_return;
@ -1432,7 +1435,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
slot = face->glyph;
FONT_SCAN_PRINTF((" "));
for (i=0; i<len; i++) {
glyph_index = (*nsFreeType::nsFT_Get_Char_Index)(face, (FT_ULong)i);
mFt2->GetCharIndex(face, (FT_ULong)i, &glyph_index);
//FONT_CATALOG_PRINTF(("i=%d, glyph_index=%d", i, glyph_index));
if (!glyph_index)
continue;
@ -1442,12 +1445,12 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
}
}
num_checked++;
fterror = (*nsFreeType::nsFT_Load_Glyph)(face, glyph_index,
rv = mFt2->LoadGlyph(face, glyph_index,
FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING);
//FONT_CATALOG_PRINTF(("fterror = %d", fterror));
if (fterror) {
FONT_CATALOG_PRINTF(("error 0x%04x loading %d (glyph index = %d)",
fterror, i, glyph_index));
if (NS_FAILED(rv)) {
FONT_CATALOG_PRINTF(("error loading %d (glyph index = %d)",
i, glyph_index));
continue;
}
if (slot->format == ft_glyph_format_outline) {
@ -1456,10 +1459,9 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
blank_chars++;
FT_Glyph glyph;
FT_BBox bbox;
(*nsFreeType::nsFT_Get_Glyph)(slot, &glyph);
(*nsFreeType::nsFT_Glyph_Get_CBox)(glyph, ft_glyph_bbox_pixels,
&bbox);
(*nsFreeType::nsFT_Done_Glyph)(glyph);
mFt2->GetGlyph(slot, &glyph);
mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &bbox);
mFt2->DoneGlyph(glyph);
if((bbox.xMax==0) && (bbox.xMin==0)
&& (bbox.yMax==0) && (bbox.yMin==0)) {
continue;
@ -1515,7 +1517,7 @@ nsFT2FontCatalog::NewFceFromFontFile(FT_Library aFreeTypeLibrary,
goto cleanup_and_return;
}
(*nsFreeType::nsFT_Done_Face)(face);
mFt2->DoneFace(face);
FONT_SCAN_PRINTF(("\n"));
return fce;
@ -1534,7 +1536,7 @@ cleanup_and_return:
fce->mStyleName = strdup("");
FREE_IF(fce->mEmbeddedBitmapHeights);
if (face)
(*nsFreeType::nsFT_Done_Face)(face);
mFt2->DoneFace(face);
FONT_SCAN_PRINTF(("\n"));
return fce;
@ -1548,7 +1550,7 @@ no_memory_cleanup_and_return:
FreeCCMap(fce->mCCMap);
FREE_IF(fce);
if (face)
(*nsFreeType::nsFT_Done_Face)(face);
mFt2->DoneFace(face);
FONT_SCAN_PRINTF(("\n"));
return nsnull;
}

Просмотреть файл

@ -186,6 +186,7 @@ protected:
nsHashtable *mRange1Language;
nsHashtable *mRange2Language;
PRBool mAvailableFontCatalogService;
nsCOMPtr<nsIFreeType2> mFt2;
#endif
};

Просмотреть файл

@ -105,8 +105,8 @@ nsFT2FontNode::InitGlobals()
LoadNodeTable();
WeightTableInitCorrection(nsFreeTypeFont::sLinearWeightTable,
nsFreeType::gAATTDarkTextMinValue,
nsFreeType::gAATTDarkTextGain);
nsFreeType2::gAATTDarkTextMinValue,
nsFreeType2::gAATTDarkTextGain);
return NS_OK;
}
@ -144,6 +144,8 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes)
familyTmp.Assign(family);
sFcs->GetFontCatalogEntries(familyTmp, languageTmp, 0, 0, 0, 0, &arrayFC);
if (!arrayFC)
goto cleanup_and_return;
arrayFC->Count(&count);
for (i = 0; i < count; i++) {
nsISupports* item = (nsISupports*)arrayFC->ElementAt(i);
@ -165,14 +167,14 @@ nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes)
for (j=0; j<32; j++) {
unsigned long bit = 1 << j;
if (bit & codePageRange1) {
charSetName = nsFreeType::GetRange1CharSetName(bit);
charSetName = nsFreeType2::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);
charSetName = nsFreeType2::GetRange2CharSetName(bit);
if (!charSetName)
continue;
LoadNode(fce, charSetName, aNodes);
@ -302,6 +304,8 @@ nsFT2FontNode::LoadNodeTable()
nsISupportsArray* arrayFC;
nsCAutoString family, language;
sFcs->GetFontCatalogEntries(family, language, 0, 0, 0, 0, &arrayFC);
if (!arrayFC)
return PR_FALSE;
PRUint32 count, i;
arrayFC->Count(&count);
for (i = 0; i < count; i++) {
@ -324,7 +328,7 @@ nsFT2FontNode::LoadNodeTable()
unsigned long bit = 1 << j;
if (!(bit & codePageRange1))
continue;
charsetName = nsFreeType::GetRange1CharSetName(bit);
charsetName = nsFreeType2::GetRange1CharSetName(bit);
NS_ASSERTION(charsetName, "failed to get charset name");
if (!charsetName)
continue;
@ -334,13 +338,13 @@ nsFT2FontNode::LoadNodeTable()
unsigned long bit = 1 << j;
if (!(bit & codePageRange2))
continue;
charsetName = nsFreeType::GetRange2CharSetName(bit);
charsetName = nsFreeType2::GetRange2CharSetName(bit);
if (!charsetName)
continue;
LoadNode(fce, charsetName, nsnull);
}
}
return 0;
return PR_TRUE;
}
//

Просмотреть файл

@ -58,6 +58,7 @@ nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *)
#include "nsX11AlphaBlend.h"
#include "nsAntiAliasedGlyph.h"
#include "nsFontDebug.h"
#include "nsIServiceManager.h"
// macros to handle FreeType2 26.6 numbers (26 bit number with 6 bit fraction)
#define FT_CEIL(x) (((x) + 63) & -64)
@ -137,6 +138,14 @@ nsFreeTypeFont *
nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize, const char *aName)
{
// Make sure FreeType is available
nsresult rv;
nsCOMPtr<nsIFreeType2> ft2 = do_GetService(NS_FREETYPE2_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
NS_ERROR("FreeType2 routines not available");
return nsnull;
}
// for now we only support ximage (XGetImage/alpha-blend/XPutImage) display
// when we support XRender then we will need to test if it is
// available and if so use it since it is faster than ximage.
@ -146,7 +155,7 @@ nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID,
nsCAutoString familyName;
aFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType::GetCustomEncoderInfo(familyName.get());
nsFreeType2::GetCustomEncoderInfo(familyName.get());
if (ximage) {
if (ffei) {
ftfont = new nsFreeTypeXImageSBC(aFaceID, aPixelSize, aName);
@ -168,11 +177,12 @@ FT_Face
nsFreeTypeFont::getFTFace()
{
FT_Face face = nsnull;
FT_Error error = (*nsFreeType::nsFTC_Manager_Lookup_Size)(
nsFreeType::GetFTCacheManager(),
&mImageDesc.font, &face, nsnull);
NS_ASSERTION(error==0, "failed to get face/size");
if (error)
FTC_Manager mgr;
nsresult rv;
mFt2->GetFTCacheManager(&mgr);
rv = mFt2->ManagerLookupSize(mgr, &mImageDesc.font, &face, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get face/size");
if (NS_FAILED(rv))
return nsnull;
return face;
}
@ -189,15 +199,15 @@ nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID,
mImageDesc.font.pix_height = aPixelSize;
mImageDesc.image_type = 0;
if (aPixelSize < nsFreeType::gAntiAliasMinimum) {
if (aPixelSize < nsFreeType2::gAntiAliasMinimum) {
mImageDesc.image_type |= ftc_image_mono;
anti_alias = PR_FALSE;
}
if (nsFreeType::gFreeType2Autohinted)
if (nsFreeType2::gFreeType2Autohinted)
mImageDesc.image_type |= ftc_image_flag_autohinted;
if (nsFreeType::gFreeType2Unhinted)
if (nsFreeType2::gFreeType2Unhinted)
mImageDesc.image_type |= ftc_image_flag_unhinted;
PRUint32 num_embedded_bitmaps, i;
@ -205,7 +215,7 @@ nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID,
mFaceID->GetEmbeddedBitmapHeights(&num_embedded_bitmaps,
&embedded_bitmapheights);
// check if we have an embedded bitmap
if (aPixelSize <= nsFreeType::gEmbeddedBitmapMaximumHeight) {
if (aPixelSize <= nsFreeType2::gEmbeddedBitmapMaximumHeight) {
if (num_embedded_bitmaps) {
for (i=0; i<num_embedded_bitmaps; i++) {
if (embedded_bitmapheights[i] == aPixelSize) {
@ -218,12 +228,17 @@ nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID,
}
}
nsresult rv;
// we checked for this earlier so it should not fail now
mFt2 = do_GetService(NS_FREETYPE2_CONTRACTID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to find FreeType routines");
FREETYPE_FONT_PRINTF(("anti_alias=%d, embedded_bitmap=%d, "
"AutoHinted=%d, gFreeType2Unhinted = %d, "
"size=%dpx, \"%s\"",
anti_alias, embedded_bimap,
nsFreeType::gFreeType2Autohinted,
nsFreeType::gFreeType2Unhinted,
nsFreeType2::gFreeType2Autohinted,
nsFreeType2::gFreeType2Unhinted,
aPixelSize, aName));
}
@ -276,6 +291,8 @@ nsFreeTypeFont::doGetBoundingMetrics(const PRUnichar* aString, PRUint32 aLength,
PRInt32* aDescent,
PRInt32* aWidth)
{
nsresult rv;
*aLeftBearing = 0;
*aRightBearing = 0;
*aAscent = 0;
@ -298,26 +315,26 @@ nsFreeTypeFont::doGetBoundingMetrics(const PRUnichar* aString, PRUint32 aLength,
if (!face)
return NS_ERROR_FAILURE;
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return NS_ERROR_FAILURE;
// get the text size
PRUint32 i;
for (i=0; i<aLength; i++) {
FT_UInt glyph_index;
FT_Glyph glyph;
FT_Error error;
FT_BBox glyph_bbox;
FT_Pos advance;
glyph_index = (*nsFreeType::nsFT_Get_Char_Index)(face,
(FT_ULong)aString[i]);
mFt2->GetCharIndex(face, (FT_ULong)aString[i], &glyph_index);
//NS_ASSERTION(glyph_index,"failed to get glyph");
if (glyph_index) {
error = (*nsFreeType::nsFTC_Image_Cache_Lookup)(
nsFreeType::GetImageCache(),
&mImageDesc, glyph_index, &glyph);
NS_ASSERTION(error==0,"error loading glyph");
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
NS_ASSERTION(NS_SUCCEEDED(rv),"error loading glyph");
}
if ((glyph_index) && (!error)) {
(*nsFreeType::nsFT_Glyph_Get_CBox)(glyph, ft_glyph_bbox_pixels,
&glyph_bbox);
if ((glyph_index) && (NS_SUCCEEDED(rv))) {
mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
advance = FT_16_16_TO_REG(glyph->advance.x);
}
else {
@ -375,14 +392,17 @@ nsFreeTypeFont::GetWidth(const PRUnichar* aString, PRUint32 aLength)
if (!face)
return 0;
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return 0;
for (PRUint32 i=0; i<aLength; i++) {
glyph_index = (*nsFreeType::nsFT_Get_Char_Index)((FT_Face)face,
(FT_ULong)aString[i]);
FT_Error error = (*nsFreeType::nsFTC_Image_Cache_Lookup)(
nsFreeType::GetImageCache(),
&mImageDesc, glyph_index, &glyph);
NS_ASSERTION(error==0,"error loading glyph");
if (error) {
mFt2->GetCharIndex((FT_Face)face, (FT_ULong)aString[i], &glyph_index);
nsresult rv;
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
NS_ASSERTION(NS_SUCCEEDED(rv),"error loading glyph");
if (NS_FAILED(rv)) {
origin_x += face->size->metrics.x_ppem/2 + 2;
continue;
}
@ -447,8 +467,8 @@ nsFreeTypeFont::max_ascent()
if (!face)
return 0;
TT_OS2 * tt_os2 = (TT_OS2 *)(*nsFreeType::nsFT_Get_Sfnt_Table)(face,
ft_sfnt_os2);
TT_OS2 * tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (tt_os2)
max_ascent = FT_16_16_TO_REG(tt_os2->sTypoAscender
@ -469,8 +489,8 @@ nsFreeTypeFont::max_descent()
if (!face)
return 0;
TT_OS2 *tt_os2 = (TT_OS2 *)(*nsFreeType::nsFT_Get_Sfnt_Table)(face,
ft_sfnt_os2);
TT_OS2 *tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (tt_os2)
max_descent = FT_16_16_TO_REG(-tt_os2->sTypoDescender *
@ -685,6 +705,11 @@ nsFreeTypeXImage::DrawString(nsRenderingContextGTK* aContext,
if (y%4==0) (*blendPixelFunc)(sub_image, y, ascent-1, black, 255/2);
#endif
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return 0;
//
// Get aa glyphs and blend with background
//
@ -693,18 +718,14 @@ nsFreeTypeXImage::DrawString(nsRenderingContextGTK* aContext,
for (i=0; i<aLength; i++) {
FT_UInt glyph_index;
FT_Glyph glyph;
FT_Error error;
nsresult rv;
FT_BBox glyph_bbox;
glyph_index = (*nsFreeType::nsFT_Get_Char_Index)(face,
(FT_ULong)aString[i]);
mFt2->GetCharIndex(face, (FT_ULong)aString[i], &glyph_index);
if (glyph_index) {
error = (*nsFreeType::nsFTC_Image_Cache_Lookup)(
nsFreeType::GetImageCache(),
&mImageDesc, glyph_index, &glyph);
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
}
if ((glyph_index) && (!error)) {
(*nsFreeType::nsFT_Glyph_Get_CBox)(glyph, ft_glyph_bbox_pixels,
&glyph_bbox);
if ((glyph_index) && (NS_SUCCEEDED(rv))) {
mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
}
else {
// draw an empty box for the missing glyphs
@ -807,7 +828,7 @@ nsFreeTypeXImageSBC::GetBoundingMetrics(const PRUnichar* aString,
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType::GetCustomEncoderInfo(familyName.get());
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return NS_ERROR_FAILURE;
@ -839,7 +860,7 @@ nsFreeTypeXImageSBC::GetWidth(const PRUnichar* aString, PRUint32 aLength)
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType::GetCustomEncoderInfo(familyName.get());
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return NS_ERROR_FAILURE;
@ -874,7 +895,7 @@ nsFreeTypeXImageSBC::DrawString(nsRenderingContextGTK* aContext,
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType::GetCustomEncoderInfo(familyName.get());
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return NS_ERROR_FAILURE;

Просмотреть файл

@ -117,6 +117,7 @@ protected:
nsITrueTypeFontCatalogEntry *mFaceID;
PRUint16 mPixelSize;
FTC_Image_Desc mImageDesc;
nsCOMPtr<nsIFreeType2> mFt2;
};
void WeightTableInitCorrection(PRUint8*, PRUint8, double);

Просмотреть файл

@ -116,7 +116,6 @@ bin/components/libdocshell.so
bin/components/libeditor.so
bin/components/libembedcomponents.so
bin/components/libgfx_gtk.so
bin/libgfxft2.so
bin/components/libgfxps.so
bin/components/libgfxxprint.so
bin/components/libimglib2.so