Bug 120401: Font selection in pref. does not work (Hebrew, Arabic, CE, Baltic, Cyrillic, CJK, etc). Patch by Asaf Romano bugs.mano@mailcentral.com with contributions by me. r=jhpedemonte, sr=sfraser.

This commit is contained in:
smontagu%smontagu.org 2004-08-04 21:48:39 +00:00
Родитель f6261f41b7
Коммит aee07862de
4 изменённых файлов: 41 добавлений и 139 удалений

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

@ -58,33 +58,6 @@ static UnicodeToTextInfo gConverters[32] = {
nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull
};
//------------------------------------------------------------------------
static UnicodeToTextInfo
GetConverterByScript(ScriptCode sc)
{
// because the Mac QuickDraw BIDI support are quite different from other platform
// we try not to use them and use the XP BIDI feature
// those text will be drawn by ATSUI intead one character at a time
if ((sc == smArabic) || (sc == smHebrew))
return nsnull;
NS_PRECONDITION(sc < 32, "illegal script id");
if(sc >= 32)
return nsnull;
if (gConverters[sc] != nsnull) {
return gConverters[sc];
}
OSStatus err = noErr;
//
TextEncoding scriptEncoding;
err = ::UpgradeScriptInfoToTextEncoding(sc, kTextLanguageDontCare, kTextRegionDontCare, nsnull, &scriptEncoding);
if ( noErr == err )
err = ::CreateUnicodeToTextInfoByEncoding(scriptEncoding, &gConverters[sc] );
if (noErr != err)
gConverters[sc] = nsnull;
return gConverters[sc];
}
class nsUnicodeFontMappingEntry
{
@ -123,17 +96,6 @@ public:
return PR_FALSE;
}
UnicodeToTextInfo converter = GetConverterByScript(mScript);
if(converter)
{
OSStatus err = ::ConvertFromUnicodeToText(converter, 2 * aStringLength,
(ConstUniCharArrayPtr) aString,
opts, 0, NULL, 0, NULL,
aBufferLength, &oBytesRead, &oActualLength,
(LogicalAddress) aBuffer);
return (oActualLength > 0 ? PR_TRUE : PR_FALSE);
}
return PR_FALSE;
}
@ -298,21 +260,20 @@ void nsUnicodeFontMappingMac::InitByFontFamily(nsFont* aFont, nsIDeviceContext *
void nsUnicodeFontMappingMac::processOneLangRegion(const char* aLanguage, const char* aRegion )
{
if(gUtil->ScriptEnabled(smTradChinese) &&
((! nsCRT::strcmp(aLanguage,"zh")) &&
((! nsCRT::strcmp(aRegion,"TW")) || (! nsCRT::strcmp(aRegion,"HK")))))
if ((! nsCRT::strcmp(aLanguage,"zh")) &&
((! nsCRT::strcmp(aRegion,"TW")) || (! nsCRT::strcmp(aRegion,"HK"))))
{
FillVarBlockToScript(smTradChinese, mPrivBlockToScript);
}
else if(gUtil->ScriptEnabled(smSimpChinese) && (! nsCRT::strcmp(aLanguage,"zh")))
else if(! nsCRT::strcmp(aLanguage,"zh"))
{
FillVarBlockToScript(smSimpChinese, mPrivBlockToScript);
}
else if(gUtil->ScriptEnabled(smKorean) && (! nsCRT::strcmp(aLanguage,"ko")))
else if(! nsCRT::strcmp(aLanguage,"ko"))
{
FillVarBlockToScript(smKorean, mPrivBlockToScript);
}
else if(gUtil->ScriptEnabled(smJapanese) && (! nsCRT::strcmp(aLanguage,"ja")))
else if(! nsCRT::strcmp(aLanguage,"ja"))
{
FillVarBlockToScript(smJapanese, mPrivBlockToScript);
}
@ -407,25 +368,26 @@ void nsUnicodeFontMappingMac::InitByLANG(const nsString& aLANG)
//--------------------------------------------------------------------------
void nsUnicodeFontMappingMac::InitByLangGroup(const nsString& aLangGroup)
{
// do not countinue if there are no difference to look at the document Charset
// do not continue if there are no difference to look at the document Charset
if( ScriptMapInitComplete() )
return;
if(gUtil->ScriptEnabled(smRoman) && aLangGroup.LowerCaseEqualsLiteral("x-western"))
{
if(aLangGroup.LowerCaseEqualsLiteral("x-western"))
{
FillVarBlockToScript(smRoman, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smSimpChinese) && aLangGroup.LowerCaseEqualsLiteral("zh-cn"))
{
} else if(aLangGroup.LowerCaseEqualsLiteral("zh-cn"))
{
FillVarBlockToScript(smSimpChinese, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smKorean) && aLangGroup.LowerCaseEqualsLiteral("ko"))
{
} else if(aLangGroup.LowerCaseEqualsLiteral("ko"))
{
FillVarBlockToScript(smKorean, mPrivBlockToScript);
} else if((gUtil->ScriptEnabled(smTradChinese)) && ((aLangGroup.LowerCaseEqualsLiteral("zh-tw")) || (aLangGroup.LowerCaseEqualsLiteral("zh-hk"))))
{
} else if(aLangGroup.LowerCaseEqualsLiteral("zh-tw") ||
aLangGroup.LowerCaseEqualsLiteral("zh-hk"))
{
FillVarBlockToScript(smTradChinese, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smJapanese) && aLangGroup.LowerCaseEqualsLiteral("ja"))
{
} else if(aLangGroup.LowerCaseEqualsLiteral("ja"))
{
FillVarBlockToScript(smJapanese, mPrivBlockToScript);
}
}
}
//--------------------------------------------------------------------------

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

@ -80,11 +80,10 @@ void nsUnicodeMappingUtil::Reset()
}
void nsUnicodeMappingUtil::Init()
{
InitScriptEnabled();
InitGenericFontMapping();
InitFromPref();
InitScriptFontMapping();
InitBlockToScriptMapping(); // this must be called after InitScriptEnabled()
InitBlockToScriptMapping();
}
void nsUnicodeMappingUtil::CleanUp()
{
@ -110,22 +109,6 @@ nsUnicodeMappingUtil::~nsUnicodeMappingUtil()
//--------------------------------------------------------------------------
void nsUnicodeMappingUtil::InitScriptEnabled()
{
PRUint8 numOfScripts = ::GetScriptManagerVariable(smEnabled);
ScriptCode script, gotScripts;
mScriptEnabled = 0;
PRUint32 scriptMask = 1;
for(script = gotScripts = 0;
((script < smUninterp) && ( gotScripts < numOfScripts)) ;
script++, scriptMask <<= 1)
{
if(::GetScriptVariable(script, smScriptEnabled))
mScriptEnabled |= scriptMask;
}
}
//--------------------------------------------------------------------------
void nsUnicodeMappingUtil::InitGenericFontMapping()
{
for(int i= 0 ; i < smPseudoTotalScripts; i ++)
@ -166,30 +149,14 @@ void nsUnicodeMappingUtil::InitGenericFontMapping()
mGenericFontMapping[smKorean][kMonospace] = new nsAutoString( NS_LITERAL_STRING("AppleGothic") );
// smArabic
static PRUnichar afontname1[] = {
0x062B, 0x0644, 0x062B, 0x202E, 0x0020, 0x202C, 0x0623, 0x0628, 0x064A, 0x0636, 0x0000 // ËäË ÃÈêÖ
};
static PRUnichar afontname2[] = {
0x0627, 0x0644, 0x0628, 0x064A, 0x0627, 0x0646, 0x0000 // ÇäÈêÇæ
};
static PRUnichar afontname3[] = {
0x062C, 0x064A, 0x0632, 0x0629, 0x0000 // ÌêÒÉ
};
mGenericFontMapping[smArabic][kSerif] = new nsAutoString(afontname1);
mGenericFontMapping[smArabic][kSansSerif] = new nsAutoString(afontname2);
mGenericFontMapping[smArabic][kMonospace] = new nsAutoString(afontname3);
mGenericFontMapping[smArabic][kSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
mGenericFontMapping[smArabic][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
mGenericFontMapping[smArabic][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") );
// smHebrew
static PRUnichar hfontname1[] = {
0x05E4, 0x05E0, 0x05D9, 0x05E0, 0x05D9, 0x05DD, 0x202E, 0x0020, 0x202C, 0x05D7, 0x05D3, 0x05E9, 0x0000 // ôðéðéí çãù
};
static PRUnichar hfontname2[] = {
0x05D0, 0x05E8, 0x05D9, 0x05D0, 0x05DC, 0x0000 // àøéàì
};
mGenericFontMapping[smHebrew][kSerif] = new nsAutoString(hfontname1);
mGenericFontMapping[smHebrew][kSansSerif] = new nsAutoString(hfontname2);
mGenericFontMapping[smHebrew][kMonospace] = new nsAutoString(hfontname2);
mGenericFontMapping[smHebrew][kSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
mGenericFontMapping[smHebrew][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
mGenericFontMapping[smHebrew][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") );
// smCyrillic
mGenericFontMapping[smCyrillic][kSerif] = new nsAutoString( NS_LITERAL_STRING("Latinski") );
@ -346,13 +313,6 @@ nsUnicodeMappingUtil::PrefEnumCallback(const char* aName, void* aClosure)
nsString *fontname = new nsAutoString(valueInUCS2);
if(nsnull == fontname)
return;
short fontID=0;
if( (! nsDeviceContextMac::GetMacFontNumber(*fontname, fontID)) ||
((script < smUninterp) && (::FontToScript(fontID) != script)))
{
delete fontname;
return;
}
if( Self->mGenericFontMapping[script][type] )
delete Self->mGenericFontMapping[script][type];
Self->mGenericFontMapping[script][type] = fontname;
@ -424,8 +384,11 @@ void nsUnicodeMappingUtil::InitScriptFontMapping()
}
}
}
else if(ScriptEnabled(script)) {
else {
long fondsize = ::GetScriptVariable(script, smScriptPrefFondSize);
if (!fondsize)
fondsize = ::GetScriptVariable(smUnicodeScript, smScriptPrefFondSize);
if((fondsize) && ((fondsize >> 16))) {
fontNum = (fondsize >> 16);
mScriptFontMapping[script] = fontNum;
@ -453,27 +416,8 @@ void nsUnicodeMappingUtil::InitBlockToScriptMapping()
};
for(PRUint32 i= 0; i < kUnicodeBlockSize; i++)
{
if( ScriptEnabled(prebuildMapping[i]) ) {
mBlockToScriptMapping[i] = prebuildMapping[i];
} else {
if (i == kUserDefinedEncoding)
mBlockToScriptMapping[i] = prebuildMapping[i];
else if(i < kUnicodeBlockFixedScriptMax) {
mBlockToScriptMapping[i] = (PRInt8) smRoman;
} else {
if( (kCJKMisc == i) || (kHiraganaKatakana == i) || (kCJKIdeographs == i) ) {
// fallback in the following sequence
// smTradChinese smKorean smSimpChinese
mBlockToScriptMapping[i] = (PRInt8)
( ScriptEnabled(smTradChinese) ? smTradChinese :
( ScriptEnabled(smKorean) ? smKorean :
( ScriptEnabled(smSimpChinese) ? smSimpChinese : smRoman )
)
);
}
}
}
}
mBlockToScriptMapping[i] = prebuildMapping[i];
}
}
//--------------------------------------------------------------------------

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

@ -63,8 +63,6 @@ public:
void Init();
void CleanUp();
void Reset();
inline PRBool ScriptEnabled(ScriptCode script)
{ return (0 != (mScriptEnabled & (1L << script))); };
inline ScriptCode BlockToScript(nsUnicodeBlock blockID)
{
NS_PRECONDITION(blockID < kUnicodeBlockSize, "illegal value");
@ -92,7 +90,6 @@ public:
nsString *mGenericFontMapping[smPseudoTotalScripts][kUknownGenericFontName];
protected:
void InitScriptEnabled();
void InitGenericFontMapping();
void InitBlockToScriptMapping();
void InitScriptFontMapping();
@ -102,7 +99,6 @@ protected:
static void PR_CALLBACK_DECL PrefEnumCallback(const char* aName, void* aClosure);
private:
PRUint32 mScriptEnabled;
short mScriptFontMapping[smPseudoTotalScripts];
PRInt8 mBlockToScriptMapping[kUnicodeBlockSize];
nsCOMPtr<nsIPref> mPref;

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

@ -1053,9 +1053,9 @@ pref("browser.always_reuse_window", false);
// default font name (in UTF8)
pref("font.name.serif.ar", "ثلث‮ ‬أبيض");
pref("font.name.sans-serif.ar", "البيان");
pref("font.name.monospace.ar", "جيزة");
pref("font.name.serif.ar", "Lucida Grande");
pref("font.name.sans-serif.ar", "Lucida Grande");
pref("font.name.monospace.ar", "Monaco");
pref("font.name.cursive.ar", "XXX.cursive");
pref("font.name.fantasy.ar", "XXX.fantasy");
@ -1065,9 +1065,9 @@ pref("font.name.monospace.el", "Courier GR");
pref("font.name.cursive.el", "XXX.cursive");
pref("font.name.fantasy.el", "XXX.fantasy");
pref("font.name.serif.he", "פנינים‮ ‬חדש");
pref("font.name.sans-serif.he", "אריאל");
pref("font.name.monospace.he", "אריאל");
pref("font.name.serif.he", "Lucida Grande");
pref("font.name.sans-serif.he", "Lucida Grande");
pref("font.name.monospace.he", "Monaco");
pref("font.name.cursive.he", "XXX.cursive");
pref("font.name.fantasy.he", "XXX.fantasy");
@ -1148,13 +1148,13 @@ pref("font.name.fantasy.zh-HK", "XXX.fantasy");
pref("font.default", "serif");
pref("font.default", "serif");
pref("font.size.variable.ar", 16);
pref("font.size.variable.ar", 15);
pref("font.size.fixed.ar", 13);
pref("font.size.variable.el", 16);
pref("font.size.fixed.el", 13);
pref("font.size.variable.he", 16);
pref("font.size.variable.he", 15);
pref("font.size.fixed.he", 13);
pref("font.size.variable.ja", 14);