backing-out previous patch because tree was closed

This commit is contained in:
masayuki%d-toybox.com 2006-08-17 05:05:26 +00:00
Родитель 826bd6b231
Коммит 7301a4e138
3 изменённых файлов: 56 добавлений и 166 удалений

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

@ -198,12 +198,6 @@ protected:
nsString mFamilies; nsString mFamilies;
gfxFontStyle mStyle; gfxFontStyle mStyle;
nsTArray< nsRefPtr<gfxFont> > mFonts; nsTArray< nsRefPtr<gfxFont> > mFonts;
static PRBool ForEachFontInternal(const nsAString& aFamilies,
const nsACString& aLangGroup,
FontCreationCallback fc,
void *closure,
PRBool aAllowRecursive);
}; };

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

@ -71,17 +71,6 @@ gfxFontGroup::ForEachFont(const nsAString& aFamilies,
const nsACString& aLangGroup, const nsACString& aLangGroup,
FontCreationCallback fc, FontCreationCallback fc,
void *closure) void *closure)
{
return ForEachFontInternal(aFamilies, aLangGroup,
fc, closure, PR_TRUE);
}
PRBool
gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
const nsACString& aLangGroup,
FontCreationCallback fc,
void *closure,
PRBool aAllowRecursive)
{ {
const PRUnichar kSingleQuote = PRUnichar('\''); const PRUnichar kSingleQuote = PRUnichar('\'');
const PRUnichar kDoubleQuote = PRUnichar('\"'); const PRUnichar kDoubleQuote = PRUnichar('\"');
@ -95,7 +84,6 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
families.BeginReading(p); families.BeginReading(p);
families.EndReading(p_end); families.EndReading(p_end);
nsAutoString family; nsAutoString family;
nsCAutoString lcFamily;
nsAutoString genericFamily; nsAutoString genericFamily;
while (p < p_end) { while (p < p_end) {
@ -139,6 +127,7 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
{ {
generic = PR_TRUE; generic = PR_TRUE;
nsCAutoString lcFamily;
ToLowerCase(NS_LossyConvertUTF16toASCII(family), lcFamily); ToLowerCase(NS_LossyConvertUTF16toASCII(family), lcFamily);
nsCAutoString prefName("font.name."); nsCAutoString prefName("font.name.");
@ -165,18 +154,6 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
return PR_FALSE; return PR_FALSE;
} }
if (generic && aAllowRecursive) {
nsCAutoString prefName("font.name-list.");
prefName.Append(lcFamily);
prefName.AppendLiteral(".");
prefName.Append(aLangGroup);
nsXPIDLString value;
nsresult rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
ForEachFontInternal(value, aLangGroup, fc, closure, PR_FALSE);
}
}
++p; // may advance past p_end ++p; // may advance past p_end
} }
@ -209,17 +186,6 @@ gfxFontGroup::FindGenericFontFromStyle(FontCreationCallback fc,
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
(*fc)(familyName, NS_LossyConvertUTF16toASCII(genericName), closure); (*fc)(familyName, NS_LossyConvertUTF16toASCII(genericName), closure);
} }
prefName.AssignLiteral("font.name-list.");
prefName.Append(NS_LossyConvertUTF16toASCII(genericName));
prefName.AppendLiteral(".");
prefName.Append(mStyle.langGroup);
rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(familyName));
if (NS_SUCCEEDED(rv)) {
ForEachFontInternal(familyName, mStyle.langGroup,
fc, closure, PR_FALSE);
}
} }
} }

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

@ -48,12 +48,8 @@
#include "nsUnicodeRange.h" #include "nsUnicodeRange.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include <math.h> #include <math.h>
#include "prlog.h" #include "prlog.h"
@ -883,21 +879,6 @@ static const struct ScriptPropertyEntry gScriptToText[] =
{ "LANG_DIVEHI", "div" } { "LANG_DIVEHI", "div" }
}; };
static const char *sCJKLangGroup[] = {
"ja",
"ko",
"zh-CN",
"zh-HK",
"zh-TW"
};
#define COUNT_OF_CJK_LANG_GROUP 5
#define CJK_LANG_JA sCJKLangGroup[0]
#define CJK_LANG_KO sCJKLangGroup[1]
#define CJK_LANG_ZH_CN sCJKLangGroup[2]
#define CJK_LANG_ZH_HK sCJKLangGroup[3]
#define CJK_LANG_ZH_TW sCJKLangGroup[4]
class UniscribeItem class UniscribeItem
{ {
public: public:
@ -905,14 +886,12 @@ public:
const PRUnichar *aString, PRUint32 aLength, const PRUnichar *aString, PRUint32 aLength,
SCRIPT_ITEM *aItem, SCRIPT_ITEM *aItem,
gfxWindowsFontGroup *aGroup) : gfxWindowsFontGroup *aGroup) :
mContext(aContext), mDC(aDC), mString(aString), mContext(aContext), mDC(aDC),
mLength(aLength), mScriptItem(aItem), mGroup(aGroup), mString(aString), mLength(aLength), mScriptItem(aItem), mGroup(aGroup),
mGlyphs(nsnull), mClusters(nsnull), mAttr(nsnull), mGlyphs(nsnull), mClusters(nsnull), mAttr(nsnull),
mNumGlyphs(0), mMaxGlyphs((int)(1.5 * aLength) + 16), mNumGlyphs(0), mMaxGlyphs((int)(1.5 * aLength) + 16),
mOffsets(nsnull), mAdvances(nsnull), mSpacing(nsnull), mOffsets(nsnull), mAdvances(nsnull), mSpacing(nsnull),
mFontIndex(0), mTriedPrefFonts(PR_FALSE), mFontIndex(0), mTriedPrefFonts(0), mTriedOtherFonts(0), mFontSelected(PR_FALSE)
mTriedOtherFonts(PR_FALSE), mAppendedCJKFonts(PR_FALSE),
mFontSelected(PR_FALSE)
{ {
mGlyphs = (WORD *)malloc(mMaxGlyphs * sizeof(WORD)); mGlyphs = (WORD *)malloc(mMaxGlyphs * sizeof(WORD));
mClusters = (WORD *)malloc((mLength + 1) * sizeof(WORD)); mClusters = (WORD *)malloc((mLength + 1) * sizeof(WORD));
@ -1132,15 +1111,25 @@ TRY_AGAIN_HOPE_FOR_THE_BEST_2:
} else if (!mTriedPrefFonts) { } else if (!mTriedPrefFonts) {
mTriedPrefFonts = PR_TRUE; mTriedPrefFonts = PR_TRUE;
gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
nsString fonts;
/* first check with the script properties to see what they think */ /* first check with the script properties to see what they think */
const SCRIPT_PROPERTIES *sp = ScriptProperties(); const SCRIPT_PROPERTIES *sp = ScriptProperties();
WORD primaryId = PRIMARYLANGID(sp->langid);
WORD subId = SUBLANGID(sp->langid);
if (!sp->fAmbiguousCharSet) { if (!sp->fAmbiguousCharSet) {
WORD primaryId = PRIMARYLANGID(sp->langid);
const char *langGroup = gScriptToText[primaryId].langCode; const char *langGroup = gScriptToText[primaryId].langCode;
if (langGroup) { if (langGroup) {
if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG)) if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG))
PR_LOG(gFontLog, PR_LOG_DEBUG, ("Trying to find fonts for: %s (%s)", langGroup, gScriptToText[primaryId].value)); PR_LOG(gFontLog, PR_LOG_DEBUG, ("Trying to find fonts for: %s (%s)", langGroup, gScriptToText[primaryId].value));
AppendPrefFonts(langGroup);
platform->GetPrefFonts(langGroup, fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
} else if (primaryId != 0) { } else if (primaryId != 0) {
#ifdef DEBUG_pavlov #ifdef DEBUG_pavlov
printf("Couldn't find anything about %d\n", primaryId); printf("Couldn't find anything about %d\n", primaryId);
@ -1149,26 +1138,45 @@ TRY_AGAIN_HOPE_FOR_THE_BEST_2:
} else { } else {
for (PRUint32 i = 0; i < mLength; ++i) { for (PRUint32 i = 0; i < mLength; ++i) {
const PRUnichar ch = mString[i]; const PRUnichar ch = mString[i];
PRUint32 unicodeRange = FindCharUnicodeRange(ch); const char *langGroup = LangGroupFromUnicodeRange(FindCharUnicodeRange(ch));
if (langGroup) {
/* special case CJK */ if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG))
if (unicodeRange == kRangeSetCJK) { PR_LOG(gFontLog, PR_LOG_DEBUG, ("Trying to find fonts for: %s", langGroup));
if (!mAppendedCJKFonts) { platform->GetPrefFonts(langGroup, fonts);
mAppendedCJKFonts = PR_TRUE; if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG)) gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
PR_LOG(gFontLog, PR_LOG_DEBUG, ("Trying to find fonts for: CJK"));
AppendCJKPrefFonts();
}
} else {
const char *langGroup = LangGroupFromUnicodeRange(unicodeRange);
if (langGroup) {
if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG))
PR_LOG(gFontLog, PR_LOG_DEBUG, ("Trying to find fonts for: %s", langGroup));
AppendPrefFonts(langGroup);
} }
} }
#if 0 // the old code does this -- i think it is sort of a hack
else {
platform->GetPrefFonts("ja", fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
platform->GetPrefFonts("zh-CN", fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
platform->GetPrefFonts("zh-TW", fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
platform->GetPrefFonts("zh-HK", fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
platform->GetPrefFonts("ko", fonts);
if (!fonts.IsEmpty()) {
const nsACString& lg = (langGroup) ? nsDependentCString(langGroup) : EmptyCString();
gfxFontGroup::ForEachFont(fonts, lg, UniscribeItem::AddFontCallback, this);
}
}
#endif
} }
} }
goto TRY_AGAIN_HOPE_FOR_THE_BEST_2; goto TRY_AGAIN_HOPE_FOR_THE_BEST_2;
@ -1229,83 +1237,6 @@ TRY_AGAIN_HOPE_FOR_THE_BEST_2:
mFontSelected = PR_TRUE; mFontSelected = PR_TRUE;
} }
private:
static PRInt32 GetCJKLangGroupIndex(const char *aLangGroup) {
PRInt32 i;
for (i = 0; i < COUNT_OF_CJK_LANG_GROUP; i++) {
if (!PL_strcasecmp(aLangGroup, sCJKLangGroup[i]))
return i;
}
return -1;
}
void AppendPrefFonts(const char *aLangGroup) {
NS_ASSERTION(aLangGroup, "aLangGroup is null");
gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
nsString fonts;
platform->GetPrefFonts(aLangGroup, fonts);
if (fonts.IsEmpty())
return;
gfxFontGroup::ForEachFont(fonts, nsDependentCString(aLangGroup),
UniscribeItem::AddFontCallback, this);
return;
}
void AppendCJKPrefFonts() {
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return;
nsCOMPtr<nsIPrefBranch> prefBranch;
prefs->GetBranch(0, getter_AddRefs(prefBranch));
if (!prefBranch)
return;
// Add by the order of accept languages.
nsXPIDLCString list;
nsresult rv = prefBranch->GetCharPref("intl.accept_languages", getter_Copies(list));
if (NS_SUCCEEDED(rv) && !list.IsEmpty()) {
const char kComma = ',';
const char *p, *p_end;
list.BeginReading(p);
list.EndReading(p_end);
while (p < p_end) {
while (nsCRT::IsAsciiSpace(*p)) {
if (++p == p_end)
break;
}
if (p == p_end)
break;
const char *start = p;
while (++p != p_end && *p != kComma)
/* nothing */ ;
nsCAutoString lang(Substring(start, p));
lang.CompressWhitespace(PR_FALSE, PR_TRUE);
PRInt32 index = GetCJKLangGroupIndex(lang.get());
if (index >= 0)
AppendPrefFonts(sCJKLangGroup[index]);
p++;
}
}
// Add the system locale
switch (::GetACP()) {
case 932: AppendPrefFonts(CJK_LANG_JA); break;
case 936: AppendPrefFonts(CJK_LANG_ZH_CN); break;
case 949: AppendPrefFonts(CJK_LANG_KO); break;
// XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950?
case 950: AppendPrefFonts(CJK_LANG_ZH_TW); break;
}
// last resort...
AppendPrefFonts(CJK_LANG_JA);
AppendPrefFonts(CJK_LANG_KO);
AppendPrefFonts(CJK_LANG_ZH_CN);
AppendPrefFonts(CJK_LANG_ZH_HK);
AppendPrefFonts(CJK_LANG_ZH_TW);
}
private: private:
nsRefPtr<gfxContext> mContext; nsRefPtr<gfxContext> mContext;
HDC mDC; HDC mDC;
@ -1332,13 +1263,12 @@ private:
nsTArray< nsRefPtr<gfxWindowsFont> > mFonts; nsTArray< nsRefPtr<gfxWindowsFont> > mFonts;
nsRefPtr<gfxWindowsFont> mCurrentFont;
PRUint32 mFontIndex; PRUint32 mFontIndex;
PRPackedBool mTriedPrefFonts; PRPackedBool mTriedPrefFonts;
PRPackedBool mTriedOtherFonts; PRPackedBool mTriedOtherFonts;
PRPackedBool mAppendedCJKFonts;
PRPackedBool mFontSelected; nsRefPtr<gfxWindowsFont> mCurrentFont;
PRBool mFontSelected;
}; };
class Uniscribe class Uniscribe