fix for #31380 (Unicode to GBK converter not working for some GBK chars )

this fix should go together with today's change of intl/uconv/ucvcn/nsUnicodeToGBK.cpp.:
This commit is contained in:
yueheng.xu%intel.com 2000-05-03 02:16:20 +00:00
Родитель fde0bce8ca
Коммит 02779f6615
1 изменённых файлов: 112 добавлений и 240 удалений

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

@ -58,11 +58,9 @@ nsFontMetricsGTK::nsFontMetricsGTK()
mFontHandle = nsnull; mFontHandle = nsnull;
mHeight = 0; mHeight = 0;
mAscent = 0;
mDescent = 0;
mLeading = 0; mLeading = 0;
mEmHeight = 0;
mEmAscent = 0;
mEmDescent = 0;
mMaxHeight = 0;
mMaxAscent = 0; mMaxAscent = 0;
mMaxDescent = 0; mMaxDescent = 0;
mMaxAdvance = 0; mMaxAdvance = 0;
@ -102,7 +100,6 @@ nsFontMetricsGTK::~nsFontMetricsGTK()
mSubstituteFont = nsnull; mSubstituteFont = nsnull;
} }
mWesternFont = nsnull;
mFontHandle = nsnull; mFontHandle = nsnull;
if (!--gFontMetricsGTKCount) { if (!--gFontMetricsGTKCount) {
@ -126,7 +123,7 @@ FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
nsString* newPointer = new nsString[newSize]; nsString* newPointer = new nsString[newSize];
if (newPointer) { if (newPointer) {
for (int i = metrics->mFontsCount - 1; i >= 0; i--) { for (int i = metrics->mFontsCount - 1; i >= 0; i--) {
newPointer[i] = metrics->mFonts[i].GetUnicode(); newPointer[i].SetString(metrics->mFonts[i].GetUnicode());
} }
delete [] metrics->mFonts; delete [] metrics->mFonts;
metrics->mFonts = newPointer; metrics->mFonts = newPointer;
@ -136,7 +133,7 @@ FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
return PR_FALSE; return PR_FALSE;
} }
} }
metrics->mFonts[metrics->mFontsCount] = aFamily.GetUnicode(); metrics->mFonts[metrics->mFontsCount].SetString(aFamily.GetUnicode());
metrics->mFonts[metrics->mFontsCount++].ToLowerCase(); metrics->mFonts[metrics->mFontsCount++].ToLowerCase();
return PR_TRUE; return PR_TRUE;
@ -186,15 +183,13 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
res = service->GetApplicationLocale(getter_AddRefs(locale)); res = service->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(res) && locale) { if (NS_SUCCEEDED(res) && locale) {
PRUnichar* str = nsnull; PRUnichar* str = nsnull;
res = locale->GetCategory(nsAutoString(NS_ConvertASCIItoUCS2(NSILOCALE_CTYPE)).GetUnicode(), res = locale->GetCategory(nsAutoString(NSILOCALE_CTYPE).GetUnicode(),
&str); &str);
if (NS_SUCCEEDED(res) && str) { if (NS_SUCCEEDED(res) && str) {
nsAutoString loc(str); nsAutoString loc(str);
loc.Truncate(2); loc.Truncate(2);
loc.ToLowerCase(); loc.ToLowerCase();
if ((loc.Equals(NS_ConvertASCIItoUCS2("ja"))) || if ((loc == "ja") || (loc == "ko") || (loc == "zh")) {
(loc.Equals(NS_ConvertASCIItoUCS2("ko"))) ||
(loc.Equals(NS_ConvertASCIItoUCS2("zh")))) {
// In CJK environments, we want the minimum request to be 16px, // In CJK environments, we want the minimum request to be 16px,
// since the smallest font for some of those langs is 16. // since the smallest font for some of those langs is 16.
minimum = 16; minimum = 16;
@ -204,9 +199,7 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
} }
} }
} }
float textZoom = 1.0; mPixelSize = NSToIntRound(app2dev * factor * mFont->size);
mDeviceContext->GetTextZoom(textZoom);
mPixelSize = NSToIntRound(app2dev * textZoom * factor * mFont->size);
if (mPixelSize < minimum) { if (mPixelSize < minimum) {
mPixelSize = minimum; mPixelSize = minimum;
} }
@ -215,11 +208,11 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
mFont->EnumerateFamilies(FontEnumCallback, this); mFont->EnumerateFamilies(FontEnumCallback, this);
mWesternFont = FindFont('a'); nsFontGTK* f = FindFont('a');
if (!mWesternFont) { if (!f) {
return NS_OK; // XXX return NS_OK; // XXX
} }
mFontHandle = mWesternFont->mFont; mFontHandle = f->mFont;
RealizeFont(); RealizeFont();
@ -297,19 +290,8 @@ void nsFontMetricsGTK::RealizeFont()
float f; float f;
mDeviceContext->GetDevUnitsToAppUnits(f); mDeviceContext->GetDevUnitsToAppUnits(f);
int lineSpacing = fontInfo->ascent + fontInfo->descent; mAscent = nscoord(fontInfo->ascent * f);
if (lineSpacing > mWesternFont->mSize) { mDescent = nscoord(fontInfo->descent * f);
mLeading = nscoord((lineSpacing - mWesternFont->mSize) * f);
}
else {
mLeading = 0;
}
mEmHeight = nscoord(mWesternFont->mSize * f);
mEmAscent = nscoord(fontInfo->ascent * mWesternFont->mSize * f / lineSpacing);
mEmDescent = mEmHeight - mEmAscent;
mMaxHeight = nscoord((fontInfo->max_bounds.ascent +
fontInfo->max_bounds.descent) * f);
mMaxAscent = nscoord(fontInfo->max_bounds.ascent * f) ; mMaxAscent = nscoord(fontInfo->max_bounds.ascent * f) ;
mMaxDescent = nscoord(fontInfo->max_bounds.descent * f); mMaxDescent = nscoord(fontInfo->max_bounds.descent * f);
@ -393,6 +375,8 @@ void nsFontMetricsGTK::RealizeFont()
/* need better way to calculate this */ /* need better way to calculate this */
mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0); mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0);
mStrikeoutSize = mUnderlineSize; mStrikeoutSize = mUnderlineSize;
mLeading = 0;
} }
NS_IMETHODIMP nsFontMetricsGTK::GetXHeight(nscoord& aResult) NS_IMETHODIMP nsFontMetricsGTK::GetXHeight(nscoord& aResult)
@ -439,30 +423,6 @@ NS_IMETHODIMP nsFontMetricsGTK::GetLeading(nscoord &aLeading)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsFontMetricsGTK::GetEmHeight(nscoord &aHeight)
{
aHeight = mEmHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsGTK::GetEmAscent(nscoord &aAscent)
{
aAscent = mEmAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsGTK::GetEmDescent(nscoord &aDescent)
{
aDescent = mEmDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsGTK::GetMaxHeight(nscoord &aHeight)
{
aHeight = mMaxHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsGTK::GetMaxAscent(nscoord &aAscent) NS_IMETHODIMP nsFontMetricsGTK::GetMaxAscent(nscoord &aAscent)
{ {
aAscent = mMaxAscent; aAscent = mMaxAscent;
@ -742,8 +702,6 @@ static PLHashTable* gFamilies = nsnull;
static PLHashTable* gFamilyNames = nsnull; static PLHashTable* gFamilyNames = nsnull;
static nsString* gGeneric = nsnull;
static nsFontFamilyName gFamilyNameTable[] = static nsFontFamilyName gFamilyNameTable[] =
{ {
#ifdef MOZ_MATHML #ifdef MOZ_MATHML
@ -799,9 +757,13 @@ static nsFontPropertyName gStretchNames[] =
}; };
static PLHashTable* gCharSets = nsnull; static PLHashTable* gCharSets = nsnull;
#ifdef MOZ_MATHML
static PLHashTable* gSpecialCharSets = nsnull; static PLHashTable* gSpecialCharSets = nsnull;
#endif
#ifdef MOZ_MATHML
static nsFontCharSetInfo Special = { nsnull }; static nsFontCharSetInfo Special = { nsnull };
#endif
static nsFontCharSetInfo Ignore = { nsnull }; static nsFontCharSetInfo Ignore = { nsnull };
static gint static gint
@ -888,7 +850,7 @@ SetUpFontCharSetInfo(nsFontCharSetInfo* aSelf)
NS_WITH_SERVICE(nsICharsetConverterManager, manager, NS_WITH_SERVICE(nsICharsetConverterManager, manager,
NS_CHARSETCONVERTERMANAGER_PROGID, &result); NS_CHARSETCONVERTERMANAGER_PROGID, &result);
if (manager && NS_SUCCEEDED(result)) { if (manager && NS_SUCCEEDED(result)) {
nsAutoString charset(NS_ConvertASCIItoUCS2(aSelf->mCharSet)); nsAutoString charset(aSelf->mCharSet);
nsIUnicodeEncoder* converter = nsnull; nsIUnicodeEncoder* converter = nsnull;
result = manager->GetUnicodeEncoder(&charset, &converter); result = manager->GetUnicodeEncoder(&charset, &converter);
if (converter && NS_SUCCEEDED(result)) { if (converter && NS_SUCCEEDED(result)) {
@ -908,7 +870,7 @@ SetUpFontCharSetInfo(nsFontCharSetInfo* aSelf)
*/ */
if (aSelf->Convert == DoubleByteConvert) { if (aSelf->Convert == DoubleByteConvert) {
PRUint32* map = aSelf->mMap; PRUint32* map = aSelf->mMap;
for (PRUint16 i = 0; i < (0x2200 >> 5); i++) { for (PRUint16 i = 0; i < (0x3000 >> 5); i++) {
map[i] = 0; map[i] = 0;
} }
} }
@ -946,8 +908,6 @@ static nsFontCharSetInfo JISX0201 =
{ "jis_0201", SingleByteConvert, 1 }; { "jis_0201", SingleByteConvert, 1 };
static nsFontCharSetInfo KOI8R = static nsFontCharSetInfo KOI8R =
{ "KOI8-R", SingleByteConvert, 0 }; { "KOI8-R", SingleByteConvert, 0 };
static nsFontCharSetInfo KOI8U =
{ "KOI8-U", SingleByteConvert, 0 };
static nsFontCharSetInfo TIS620 = static nsFontCharSetInfo TIS620 =
{ "TIS-620", SingleByteConvert, 0 }; { "TIS-620", SingleByteConvert, 0 };
@ -969,6 +929,8 @@ static nsFontCharSetInfo CNS116437 =
{ "x-cns-11643-7", DoubleByteConvert, 1 }; { "x-cns-11643-7", DoubleByteConvert, 1 };
static nsFontCharSetInfo GB2312 = static nsFontCharSetInfo GB2312 =
{ "gb_2312-80", DoubleByteConvert, 1 }; { "gb_2312-80", DoubleByteConvert, 1 };
static nsFontCharSetInfo GBK =
{ "x-gbk", DoubleByteConverter, 1 };
static nsFontCharSetInfo JISX0208 = static nsFontCharSetInfo JISX0208 =
{ "jis_0208-1983", DoubleByteConvert, 1 }; { "jis_0208-1983", DoubleByteConvert, 1 };
static nsFontCharSetInfo JISX0212 = static nsFontCharSetInfo JISX0212 =
@ -980,12 +942,14 @@ static nsFontCharSetInfo X11Johab =
static nsFontCharSetInfo ISO106461 = static nsFontCharSetInfo ISO106461 =
{ nsnull, ISO10646Convert, 1 }; { nsnull, ISO10646Convert, 1 };
#ifdef MOZ_MATHML
static nsFontCharSetInfo AdobeSymbol = static nsFontCharSetInfo AdobeSymbol =
{ "Adobe-Symbol-Encoding", SingleByteConvert, 0 }; { "Adobe-Symbol-Encoding", SingleByteConvert, 0 };
static nsFontCharSetInfo CMCMEX = static nsFontCharSetInfo CMCMEX =
{ "x-t1-cmex", SingleByteConvert, 0 }; { "x-cm-cmex", SingleByteConvert, 0 };
static nsFontCharSetInfo CMCMSY = static nsFontCharSetInfo CMCMSY =
{ "x-t1-cmsy", SingleByteConvert, 0 }; { "x-cm-cmsy", SingleByteConvert, 0 };
#endif
/* /*
* Normally, the charset of an X font can be determined simply by looking at * Normally, the charset of an X font can be determined simply by looking at
@ -1017,7 +981,9 @@ static nsFontCharSetMap gCharSetMap[] =
{ {
{ "-ascii", &Ignore }, { "-ascii", &Ignore },
{ "-ibm pc", &Ignore }, { "-ibm pc", &Ignore },
#ifdef MOZ_MATHML
{ "adobe-fontspecific", &Special }, { "adobe-fontspecific", &Special },
#endif
{ "big5-0", &Big5 }, { "big5-0", &Big5 },
{ "big5-1", &Big5 }, { "big5-1", &Big5 },
{ "big5.et-0", &Big5 }, { "big5.et-0", &Big5 },
@ -1050,6 +1016,7 @@ static nsFontCharSetMap gCharSetMap[] =
{ "fontspecific-0", &Ignore }, { "fontspecific-0", &Ignore },
{ "gb2312.1980-0", &GB2312 }, { "gb2312.1980-0", &GB2312 },
{ "gb2312.1980-1", &GB2312 }, { "gb2312.1980-1", &GB2312 },
{ "gb13000.1993-1", &GBK },
{ "hp-japanese15", &Ignore }, { "hp-japanese15", &Ignore },
{ "hp-japaneseeuc", &Ignore }, { "hp-japaneseeuc", &Ignore },
{ "hp-roman8", &Ignore }, { "hp-roman8", &Ignore },
@ -1090,12 +1057,10 @@ static nsFontCharSetMap gCharSetMap[] =
{ "jisx0208.1990-0", &JISX0208 }, { "jisx0208.1990-0", &JISX0208 },
{ "jisx0212.1990-0", &JISX0212 }, { "jisx0212.1990-0", &JISX0212 },
{ "koi8-r", &KOI8R }, { "koi8-r", &KOI8R },
{ "koi8-u", &KOI8U },
{ "johab-1", &X11Johab }, { "johab-1", &X11Johab },
{ "johabs-1", &X11Johab }, { "johabs-1", &X11Johab },
{ "johabsh-1", &X11Johab }, { "johabsh-1", &X11Johab },
{ "ksc5601.1987-0", &KSC5601 }, { "ksc5601.1987-0", &KSC5601 },
{ "microsoft-cp1251", &CP1251 },
{ "misc-fontspecific", &Ignore }, { "misc-fontspecific", &Ignore },
{ "sgi-fontspecific", &Ignore }, { "sgi-fontspecific", &Ignore },
{ "sun-fontspecific", &Ignore }, { "sun-fontspecific", &Ignore },
@ -1109,6 +1074,7 @@ static nsFontCharSetMap gCharSetMap[] =
{ nsnull, nsnull } { nsnull, nsnull }
}; };
#ifdef MOZ_MATHML
static nsFontCharSetMap gSpecialCharSetMap[] = static nsFontCharSetMap gSpecialCharSetMap[] =
{ {
{ "symbol-adobe-fontspecific", &AdobeSymbol }, { "symbol-adobe-fontspecific", &AdobeSymbol },
@ -1117,6 +1083,7 @@ static nsFontCharSetMap gSpecialCharSetMap[] =
{ nsnull, nsnull } { nsnull, nsnull }
}; };
#endif
#undef DEBUG_DUMP_TREE #undef DEBUG_DUMP_TREE
#ifdef DEBUG_DUMP_TREE #ifdef DEBUG_DUMP_TREE
@ -1246,7 +1213,7 @@ GetMapFor10646Font(XFontStruct* aFont)
PRInt32 offset = (((row - minByte1) * charsPerRow) - minByte2); PRInt32 offset = (((row - minByte1) * charsPerRow) - minByte2);
for (PRInt32 cell = minByte2; cell <= maxByte2; cell++) { for (PRInt32 cell = minByte2; cell <= maxByte2; cell++) {
XCharStruct* bounds = &aFont->per_char[offset + cell]; XCharStruct* bounds = &aFont->per_char[offset + cell];
if (bounds->ascent || bounds->descent) { if ((!bounds->ascent) && (!bounds->descent)) {
SET_REPRESENTABLE(map, (row << 8) | cell); SET_REPRESENTABLE(map, (row << 8) | cell);
} }
} }
@ -1670,8 +1637,7 @@ PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch,
} }
} }
// XXX remove the else part after testing this for a while -- erik #ifdef MOZ_MATHML
#if 1
// CSS font-family bug fix // CSS font-family bug fix
// CSS font-family order is not respected without the following fix. // CSS font-family order is not respected without the following fix.
// The idea is to ensure that even though the character being searched // The idea is to ensure that even though the character being searched
@ -1722,7 +1688,7 @@ PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch,
if (fontHasGlyph) { if (fontHasGlyph) {
aSearch->mFont = s; aSearch->mFont = s;
} }
#else /* 1 */ #else /* MOZ_MATHML */
if (!aCharSet->mInfo->mCharSet) { if (!aCharSet->mInfo->mCharSet) {
if (!IS_REPRESENTABLE(s->mMap, aSearch->mChar)) { if (!IS_REPRESENTABLE(s->mMap, aSearch->mChar)) {
return; return;
@ -1749,7 +1715,7 @@ PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch,
} }
m->mLoadedFonts[m->mLoadedFontsCount++] = s; m->mLoadedFonts[m->mLoadedFontsCount++] = s;
aSearch->mFont = s; aSearch->mFont = s;
#endif /* 1 */ #endif /* !MOZ_MATHML */
#ifdef REALLY_NOISY_FONTS #ifdef REALLY_NOISY_FONTS
nsFontGTK* result = s; nsFontGTK* result = s;
@ -2047,8 +2013,7 @@ SearchCharSet(PLHashEntry* he, PRIntn i, void* arg)
nsFontCharSetInfo* charSetInfo = charSet->mInfo; nsFontCharSetInfo* charSetInfo = charSet->mInfo;
PRUint32* map = charSetInfo->mMap; PRUint32* map = charSetInfo->mMap;
nsFontSearch* search = (nsFontSearch*) arg; nsFontSearch* search = (nsFontSearch*) arg;
// XXX remove the if and endif lines after testing for a while -- erik #ifdef MOZ_MATHML
#if 1
nsFontMetricsGTK* m = search->mMetrics; nsFontMetricsGTK* m = search->mMetrics;
#endif #endif
PRUnichar c = search->mChar; PRUnichar c = search->mChar;
@ -2065,8 +2030,7 @@ SearchCharSet(PLHashEntry* he, PRIntn i, void* arg)
charSetInfo->mMap = map; charSetInfo->mMap = map;
SetUpFontCharSetInfo(charSetInfo); SetUpFontCharSetInfo(charSetInfo);
} }
// XXX remove the else part after testing for a while -- erik #ifdef MOZ_MATHML
#if 1
// CSS font-family bug fix // CSS font-family bug fix
// Check if font has been requested from CSS font-family, // Check if font has been requested from CSS font-family,
// if so ignore IS_REPRESENTABLE. It gets tested again // if so ignore IS_REPRESENTABLE. It gets tested again
@ -2080,11 +2044,11 @@ SearchCharSet(PLHashEntry* he, PRIntn i, void* arg)
return HT_ENUMERATE_NEXT; return HT_ENUMERATE_NEXT;
} }
} }
#else /* 1 */ #else /* MOZ_MATHML */
if (!IS_REPRESENTABLE(map, c)) { if (!IS_REPRESENTABLE(map, c)) {
return HT_ENUMERATE_NEXT; return HT_ENUMERATE_NEXT;
} }
#endif /* 1 */ #endif /* !MOZ_MATHML */
} }
TryCharSet(search, charSet); TryCharSet(search, charSet);
@ -2205,6 +2169,7 @@ GetFontNames(char* aPattern)
} }
nsFontCharSetInfo* charSetInfo = nsFontCharSetInfo* charSetInfo =
(nsFontCharSetInfo*) PL_HashTableLookup(gCharSets, charSetName); (nsFontCharSetInfo*) PL_HashTableLookup(gCharSets, charSetName);
#ifdef MOZ_MATHML
// indirection for font specific charset encoding // indirection for font specific charset encoding
if (charSetInfo == &Special) { if (charSetInfo == &Special) {
char *familyCharSetName = PR_smprintf ("%s-%s", familyName, charSetName); char *familyCharSetName = PR_smprintf ("%s-%s", familyName, charSetName);
@ -2212,6 +2177,7 @@ GetFontNames(char* aPattern)
(gSpecialCharSets, familyCharSetName); (gSpecialCharSets, familyCharSetName);
PR_smprintf_free (familyCharSetName); PR_smprintf_free (familyCharSetName);
} }
#endif
if (!charSetInfo) { if (!charSetInfo) {
#ifdef NOISY_FONTS #ifdef NOISY_FONTS
printf("cannot find charset %s\n", charSetName); printf("cannot find charset %s\n", charSetName);
@ -2223,8 +2189,7 @@ GetFontNames(char* aPattern)
continue; continue;
} }
nsAutoString familyName2; nsAutoString familyName2(familyName);
familyName2.AssignWithConversion(familyName);
family = family =
(nsFontFamily*) PL_HashTableLookup(gFamilies, (nsString*) &familyName2); (nsFontFamily*) PL_HashTableLookup(gFamilies, (nsString*) &familyName2);
if (!family) { if (!family) {
@ -2232,7 +2197,7 @@ GetFontNames(char* aPattern)
if (!family) { if (!family) {
continue; continue;
} }
nsString* copy = new nsString(NS_ConvertASCIItoUCS2(familyName)); nsString* copy = new nsString(familyName);
if (!copy) { if (!copy) {
delete family; delete family;
continue; continue;
@ -2385,135 +2350,11 @@ GetFontNames(char* aPattern)
} }
static void static void
FreeGlobals(void) FindFamily(nsFontSearch* aSearch, nsString* aName)
{ {
// XXX finish this aSearch->mFont = nsnull;
nsFontFamily* family =
if (gGeneric) { (nsFontFamily*) PL_HashTableLookup(gFamilies, aName);
delete gGeneric;
gGeneric = nsnull;
}
}
/*
* Initialize all the font lookup hash tables and other globals
*/
static int
InitFontTables(void)
{
gFamilies = PL_NewHashTable(0, HashKey, CompareKeys, NULL, NULL, NULL);
if (!gFamilies) {
FreeGlobals();
return 0;
}
gFamilyNames = PL_NewHashTable(0, HashKey, CompareKeys, NULL, NULL, NULL);
if (!gFamilyNames) {
FreeGlobals();
return 0;
}
gGeneric = new nsAutoString();
if (!gGeneric) {
FreeGlobals();
return 0;
}
nsFontFamilyName* f = gFamilyNameTable;
while (f->mName) {
nsString* name = new nsString(NS_ConvertASCIItoUCS2(f->mName));
if (!name) {
FreeGlobals();
return 0;
}
nsString* xName;
if (f->mXName) {
xName = new nsString(NS_ConvertASCIItoUCS2(f->mXName));
if (!xName) {
FreeGlobals();
return 0;
}
}
else {
xName = gGeneric;
}
if (name && xName) {
if (!PL_HashTableAdd(gFamilyNames, name, (void*) xName)) {
FreeGlobals();
return 0;
}
}
f++;
}
gWeights = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL, NULL,
NULL);
if (!gWeights) {
FreeGlobals();
return 0;
}
nsFontPropertyName* p = gWeightNames;
while (p->mName) {
if (!PL_HashTableAdd(gWeights, p->mName, (void*) p->mValue)) {
FreeGlobals();
return 0;
}
p++;
}
gStretches = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL,
NULL, NULL);
if (!gStretches) {
FreeGlobals();
return 0;
}
p = gStretchNames;
while (p->mName) {
if (!PL_HashTableAdd(gStretches, p->mName, (void*) p->mValue)) {
FreeGlobals();
return 0;
}
p++;
}
gCharSets = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL, NULL,
NULL);
if (!gCharSets) {
FreeGlobals();
return 0;
}
nsFontCharSetMap* charSetMap = gCharSetMap;
while (charSetMap->mName) {
if (!PL_HashTableAdd(gCharSets, charSetMap->mName,
(void*) charSetMap->mInfo)) {
FreeGlobals();
return 0;
}
charSetMap++;
}
gSpecialCharSets = PL_NewHashTable
(0, PL_HashString, PL_CompareStrings, NULL, NULL, NULL);
if (!gSpecialCharSets) {
FreeGlobals();
return 0;
}
nsFontCharSetMap* specialCharSetMap = gSpecialCharSetMap;
while (specialCharSetMap->mName) {
if (!PL_HashTableAdd (gSpecialCharSets,
specialCharSetMap->mName,
(void*) specialCharSetMap->mInfo)) {
FreeGlobals();
return 0;
}
specialCharSetMap++;
}
return 1;
}
static nsFontFamily*
FindFamily(const nsString* aName)
{
nsFontFamily* family = nsnull;
if (!gFamilies) {
if (!InitFontTables()) {
return nsnull;
}
}
family = (nsFontFamily*) PL_HashTableLookup(gFamilies, aName);
if (!family) { if (!family) {
char name[128]; char name[128];
aName->ToCString(name, sizeof(name)); aName->ToCString(name, sizeof(name));
@ -2529,37 +2370,15 @@ FindFamily(const nsString* aName)
} }
else { else {
delete family; delete family;
return nsnull; return;
} }
} }
else { else {
return nsnull; return;
} }
} }
} }
return family; TryFamily(aSearch, family);
}
static void
FindFamily(nsFontSearch* aSearch, nsString* aName)
{
aSearch->mFont = nsnull;
nsFontFamily* family = FindFamily(aName);
if (family) {
TryFamily(aSearch, family);
}
}
nsresult
nsFontMetricsGTK::FamilyExists(const nsString& aName)
{
nsAutoString familyName(aName);
familyName.ToLowerCase();
nsFontFamily* family = FindFamily(&familyName);
if (family && family->mCharSets) { // need to check for dummy entry
return NS_OK;
}
return NS_ERROR_FAILURE;
} }
static void static void
@ -2571,7 +2390,7 @@ PrefEnumCallback(const char* aName, void* aClosure)
gPref->CopyCharPref(aName, &value); gPref->CopyCharPref(aName, &value);
nsAutoString name; nsAutoString name;
if (value) { if (value) {
name.AssignWithConversion(value); name = value;
nsAllocator::Free(value); nsAllocator::Free(value);
value = nsnull; value = nsnull;
FindFamily(search, &name); FindFamily(search, &name);
@ -2579,7 +2398,7 @@ PrefEnumCallback(const char* aName, void* aClosure)
if (!search->mFont) { if (!search->mFont) {
gPref->CopyDefaultCharPref(aName, &value); gPref->CopyDefaultCharPref(aName, &value);
if (value) { if (value) {
name.AssignWithConversion(value); name = value;
nsAllocator::Free(value); nsAllocator::Free(value);
value = nsnull; value = nsnull;
FindFamily(search, &name); FindFamily(search, &name);
@ -2602,7 +2421,7 @@ nsFontMetricsGTK::FindGenericFont(nsFontSearch* aSearch)
if (mTriedAllGenerics) { if (mTriedAllGenerics) {
return; return;
} }
nsAutoString prefix(NS_ConvertASCIItoUCS2("font.name.")); nsAutoString prefix("font.name.");
char* value = nsnull; char* value = nsnull;
if (mGeneric) { if (mGeneric) {
prefix.Append(*mGeneric); prefix.Append(*mGeneric);
@ -2610,12 +2429,12 @@ nsFontMetricsGTK::FindGenericFont(nsFontSearch* aSearch)
else { else {
gPref->CopyCharPref("font.default", &value); gPref->CopyCharPref("font.default", &value);
if (value) { if (value) {
prefix.AppendWithConversion(value); prefix.Append(value);
nsAllocator::Free(value); nsAllocator::Free(value);
value = nsnull; value = nsnull;
} }
else { else {
prefix.AppendWithConversion("serif"); prefix.Append("serif");
} }
} }
char name[128]; char name[128];
@ -2629,7 +2448,7 @@ nsFontMetricsGTK::FindGenericFont(nsFontSearch* aSearch)
gPref->CopyCharPref(name, &value); gPref->CopyCharPref(name, &value);
nsAutoString str; nsAutoString str;
if (value) { if (value) {
str.AssignWithConversion(value); str = value;
nsAllocator::Free(value); nsAllocator::Free(value);
value = nsnull; value = nsnull;
FindFamily(aSearch, &str); FindFamily(aSearch, &str);
@ -2640,7 +2459,7 @@ nsFontMetricsGTK::FindGenericFont(nsFontSearch* aSearch)
value = nsnull; value = nsnull;
gPref->CopyDefaultCharPref(name, &value); gPref->CopyDefaultCharPref(name, &value);
if (value) { if (value) {
str.AssignWithConversion(value); str = value;
nsAllocator::Free(value); nsAllocator::Free(value);
value = nsnull; value = nsnull;
FindFamily(aSearch, &str); FindFamily(aSearch, &str);
@ -2680,10 +2499,63 @@ nsFontMetricsGTK::FindSubstituteFont(nsFontSearch* aSearch)
nsFontGTK* nsFontGTK*
nsFontMetricsGTK::FindFont(PRUnichar aChar) nsFontMetricsGTK::FindFont(PRUnichar aChar)
{ {
if (!gFamilies) { static nsString* gGeneric = nsnull;
if (!InitFontTables()) { static int gInitialized = 0;
if (!gInitialized) {
gInitialized = 1;
gFamilies = PL_NewHashTable(0, HashKey, CompareKeys, NULL, NULL, NULL);
gFamilyNames = PL_NewHashTable(0, HashKey, CompareKeys, NULL, NULL, NULL);
gGeneric = new nsAutoString();
if (!gGeneric) {
return nsnull; return nsnull;
} }
nsFontFamilyName* f = gFamilyNameTable;
while (f->mName) {
nsString* name = new nsString(f->mName);
nsString* xName;
if (f->mXName) {
xName = new nsString(f->mXName);
}
else {
xName = gGeneric;
}
if (name && xName) {
PL_HashTableAdd(gFamilyNames, name, (void*) xName);
}
f++;
}
gWeights = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL, NULL,
NULL);
nsFontPropertyName* p = gWeightNames;
while (p->mName) {
PL_HashTableAdd(gWeights, p->mName, (void*) p->mValue);
p++;
}
gStretches = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL,
NULL, NULL);
p = gStretchNames;
while (p->mName) {
PL_HashTableAdd(gStretches, p->mName, (void*) p->mValue);
p++;
}
gCharSets = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, NULL, NULL,
NULL);
nsFontCharSetMap* charSetMap = gCharSetMap;
while (charSetMap->mName) {
PL_HashTableAdd(gCharSets, charSetMap->mName, (void*) charSetMap->mInfo);
charSetMap++;
}
#ifdef MOZ_MATHML
gSpecialCharSets = PL_NewHashTable
(0, PL_HashString, PL_CompareStrings, NULL, NULL, NULL);
nsFontCharSetMap* specialCharSetMap = gSpecialCharSetMap;
while (specialCharSetMap->mName) {
PL_HashTableAdd (gSpecialCharSets,
specialCharSetMap->mName,
(void*) specialCharSetMap->mInfo);
specialCharSetMap++;
}
#endif
} }
nsFontSearch search = { this, aChar, nsnull }; nsFontSearch search = { this, aChar, nsnull };