Bug 524107 - part 2 - store language as atom instead of string in gfxFontStyle. r=roc sr=mats

This commit is contained in:
Jonathan Kew 2010-02-24 09:57:57 -08:00
parent 365fbafa0d
commit 7a3339c3b1
39 changed files with 442 additions and 212 deletions

View File

@ -1932,8 +1932,7 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font)
return NS_ERROR_FAILURE;
nsIDocument* document = presShell->GetDocument();
nsCString language;
presShell->GetPresContext()->GetLanguage()->ToUTF8String(language);
nsIAtom *language = presShell->GetPresContext()->GetLanguage();
nsCOMArray<nsIStyleRule> rules;
@ -2004,7 +2003,10 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font)
fontStyle->mFont.familyNameQuirks,
printerFont);
CurrentState().fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.name, &style, presShell->GetPresContext()->GetUserFontSet());
CurrentState().fontGroup =
gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.name,
&style,
presShell->GetPresContext()->GetUserFontSet());
NS_ASSERTION(CurrentState().fontGroup, "Could not get font group");
CurrentState().font = font;
return NS_OK;

View File

@ -42,6 +42,7 @@
#include "gfxPlatform.h"
#include "nsTArray.h"
#include "nsIAtom.h"
NS_IMPL_ISUPPORTS1(nsThebesFontEnumerator, nsIFontEnumerator)
@ -67,20 +68,14 @@ nsThebesFontEnumerator::EnumerateFonts(const char *aLangGroup,
nsTArray<nsString> fontList;
nsCAutoString langGroup;
nsCAutoString generic;
if (aLangGroup)
langGroup.Assign(aLangGroup);
else
langGroup.SetIsVoid(PR_TRUE);
if (aGeneric)
generic.Assign(aGeneric);
else
generic.SetIsVoid(PR_TRUE);
nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroup, generic, fontList);
nsCOMPtr<nsIAtom> langGroupAtom = do_GetAtom(aLangGroup);
nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
if (NS_FAILED(rv)) {
*aCount = 0;

View File

@ -78,14 +78,9 @@ nsThebesFontMetrics::Init(const nsFont& aFont, nsIAtom* aLanguage,
gfxFloat size = gfxFloat(aFont.size) / mP2A;
nsCString language;
if (aLanguage) {
mLanguage->ToUTF8String(language);
}
PRBool printerFont = mDeviceContext->IsPrinterSurface();
mFontStyle = new gfxFontStyle(aFont.style, aFont.weight, aFont.stretch,
size, language,
size, aLanguage,
aFont.sizeAdjust, aFont.systemFont,
aFont.familyNameQuirks,
printerFont);

View File

@ -58,7 +58,7 @@ public:
PRUint32 height,
gfxASurface::gfxImageFormat imageFormat);
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -203,11 +203,11 @@ protected: // new functions
void *closure);
PRBool mEnableKerning;
void GetPrefFonts(const char *aLangGroup,
void GetPrefFonts(nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
void FamilyListToArrayList(const nsString& aFamilies,
const nsCString& aLangGroup,
nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList);
already_AddRefed<gfxFT2Font> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList,
PRUint32 aCh);

View File

@ -54,6 +54,7 @@
#include "nsExpirationTracker.h"
#include "gfxFontConstants.h"
#include "gfxPlatform.h"
#include "nsIAtom.h"
#ifdef DEBUG
#include <stdio.h>
@ -61,7 +62,6 @@
class gfxContext;
class gfxTextRun;
class nsIAtom;
class gfxFont;
class gfxFontFamily;
class gfxFontGroup;
@ -84,7 +84,7 @@ class nsILanguageAtomService;
struct THEBES_API gfxFontStyle {
gfxFontStyle();
gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
gfxFloat aSize, const nsACString& aLanguage,
gfxFloat aSize, nsIAtom *aLanguage,
float aSizeAdjust, PRPackedBool aSystemFont,
PRPackedBool aFamilyNameQuirks,
PRPackedBool aPrinterFont);
@ -120,7 +120,7 @@ struct THEBES_API gfxFontStyle {
gfxFloat size;
// the language (may be an internal langGroup code rather than an actual lang)
nsCString language;
nsIAtom *language;
// The aspect-value (ie., the ratio actualsize:actualxheight) that any
// actual physical font created from this font structure must have when
@ -139,7 +139,7 @@ struct THEBES_API gfxFontStyle {
PLDHashNumber Hash() const {
return ((style + (systemFont << 7) + (familyNameQuirks << 8) +
(weight << 9)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^
HashString(language);
nsISupportsHashKey::HashKey(language);
}
void ComputeWeightAndOffset(PRInt8 *outBaseWeight,
@ -153,7 +153,7 @@ struct THEBES_API gfxFontStyle {
(familyNameQuirks == other.familyNameQuirks) &&
(weight == other.weight) &&
(stretch == other.stretch) &&
(language.Equals(other.language)) &&
(language == other.language) &&
(sizeAdjust == other.sizeAdjust);
}
};
@ -213,7 +213,7 @@ public:
virtual PRBool MatchesGenericFamily(const nsACString& aGeneric) const {
return PR_TRUE;
}
virtual PRBool SupportsLangGroup(const nsACString& aLangGroup) const {
virtual PRBool SupportsLangGroup(nsIAtom *aLangGroup) const {
return PR_TRUE;
}
@ -1792,7 +1792,7 @@ public:
const nsACString& aGenericName,
void *closure);
PRBool ForEachFont(const nsAString& aFamilies,
const nsACString& aLanguage,
nsIAtom *aLanguage,
FontCreationCallback fc,
void *closure);
PRBool ForEachFont(FontCreationCallback fc, void *closure);
@ -1879,7 +1879,7 @@ protected:
* if aResolveGeneric).
*/
PRBool ForEachFontInternal(const nsAString& aFamilies,
const nsACString& aLanguage,
nsIAtom *aLanguage,
PRBool aResolveGeneric,
PRBool aResolveFontName,
FontCreationCallback fc,

View File

@ -62,7 +62,7 @@ public:
CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);
nsresult UpdateFontList();

View File

@ -150,7 +150,7 @@ protected:
#endif
void GetFcFamilies(nsTArray<nsString> *aFcFamilyList,
const nsACString& aLanguage);
nsIAtom *aLanguage);
// @param aLang [in] language to use for pref fonts and system font
// resolution, or NULL to guess a language from the gfxFontStyle.

View File

@ -63,6 +63,7 @@ class gfxProxyFontEntry;
class gfxPlatformFontList;
class gfxTextRun;
class nsIURI;
class nsIAtom;
// pref lang id's for font prefs
// !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
@ -158,7 +159,7 @@ public:
* that correspond to the given language group or generic font family
* (or both, or neither).
*/
virtual nsresult GetFontList(const nsACString& aLangGroup,
virtual nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);
@ -232,7 +233,7 @@ public:
// check whether format is supported on a platform or not (if unclear, returns true)
virtual PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags) { return PR_FALSE; }
void GetPrefFonts(const char *aLanguage, nsString& array, PRBool aAppendUnicode = PR_TRUE);
void GetPrefFonts(nsIAtom *aLanguage, nsString& array, PRBool aAppendUnicode = PR_TRUE);
// in some situations, need to make decisions about ambiguous characters, may need to look at multiple pref langs
void GetLangPrefs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang);
@ -248,9 +249,12 @@ public:
PrefFontCallback aCallback,
void *aClosure);
// convert a lang group string to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
// convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
static eFontPrefLang GetFontPrefLangFor(const char* aLang);
// convert a lang group atom to enum constant
static eFontPrefLang GetFontPrefLangFor(nsIAtom *aLang);
// convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
static const char* GetPrefLangName(eFontPrefLang aLang);

View File

@ -73,7 +73,7 @@ public:
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -86,7 +86,7 @@ public:
PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags);
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);
nsresult UpdateFontList();

View File

@ -73,7 +73,7 @@ public:
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -155,7 +155,7 @@ public:
void GroupFamilyListToArrayList(nsTArray<nsRefPtr<gfxFontEntry> > *list,
nsTArray<PRPackedBool> *aNeedsBold);
void FamilyListToArrayList(const nsString& aFamilies,
const nsCString& aLangGroup,
nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> > *list);
virtual void UpdateFontList();
@ -184,7 +184,7 @@ protected:
already_AddRefed<gfxFont> WhichSystemFontSupportsChar(PRUint32 aCh);
already_AddRefed<gfxWindowsFont> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& fonts, PRUint32 ch);
void GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& array);
void GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& array);
void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& array);
static PRBool FindWindowsFont(const nsAString& aName,

View File

@ -100,7 +100,7 @@ public:
RenderMode GetRenderMode() { return mRenderMode; }
void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -22,6 +22,7 @@ CPPSRCS = \
gfxFontMissingGlyphs.cpp \
gfxFontTest.cpp \
gfxFontUtils.cpp \
gfxAtoms.cpp \
gfxMatrix.cpp \
gfxPath.cpp \
gfxPattern.cpp \

View File

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 20; 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 Mozilla Foundation code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
/******
This file contains the list of all gfx language nsIAtoms and their values
It is designed to be used as inline input to gfxAtoms.cpp *only*
through the magic of C preprocessing.
All entires must be enclosed in the macro GFX_ATOM which will have cruel
and unusual things done to it
It is recommended (but not strictly necessary) to keep all entries
in alphabetical order
The first argument to GFX_ATOM is the C++ identifier of the atom
The second argument is the string value of the atom
******/
// language codes specifically referenced in the gfx code
GFX_ATOM(en, "en")
GFX_ATOM(x_unicode, "x-unicode")
GFX_ATOM(x_western, "x-western")
GFX_ATOM(ja, "ja")
GFX_ATOM(ko, "ko")
GFX_ATOM(zh_cn, "zh-cn")
GFX_ATOM(zh_hk, "zh-hk")
GFX_ATOM(zh_tw, "zh-tw")
// additional codes used in nsUnicodeRange.cpp
GFX_ATOM(x_cyrillic, "x-cyrillic")
GFX_ATOM(el, "el")
GFX_ATOM(tr, "tr")
GFX_ATOM(he, "he")
GFX_ATOM(ar, "ar")
GFX_ATOM(x_baltic, "x-baltic")
GFX_ATOM(th, "th")
GFX_ATOM(x_devanagari, "x-devanagari")
GFX_ATOM(x_tamil, "x-tamil")
GFX_ATOM(x_armn, "x-armn")
GFX_ATOM(x_beng, "x-beng")
GFX_ATOM(x_cans, "x-cans")
GFX_ATOM(x_ethi, "x-ethi")
GFX_ATOM(x_geor, "x-geor")
GFX_ATOM(x_gujr, "x-gujr")
GFX_ATOM(x_guru, "x-guru")
GFX_ATOM(x_khmr, "x-khmr")
GFX_ATOM(x_mlym, "x-mlym")
GFX_ATOM(x_orya, "x-orya")
GFX_ATOM(x_telu, "x-telu")
GFX_ATOM(x_knda, "x-knda")
GFX_ATOM(x_sinh, "x-sinh")

View File

@ -0,0 +1,54 @@
/* -*- Mode: C++; tab-width: 20; 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 Mozilla Foundation code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 "gfxAtoms.h"
#include "nsStaticAtom.h"
#include "nsMemory.h"
#define GFX_ATOM(_name, _value) nsIAtom* gfxAtoms::_name = 0;
#include "gfxAtomList.h"
#undef GFX_ATOM
static const nsStaticAtom atoms[] = {
#define GFX_ATOM(_name, _value) { _value, &gfxAtoms::_name },
#include "gfxAtomList.h"
#undef GFX_ATOM
};
void gfxAtoms::RegisterAtoms()
{
NS_RegisterStaticAtoms(atoms, NS_ARRAY_LENGTH(atoms));
}

59
gfx/thebes/src/gfxAtoms.h Normal file
View File

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 20; 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 Mozilla Foundation code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#ifndef GFX_ATOMS_H
#define GFX_ATOMS_H
#include "prtypes.h"
#include "nsIAtom.h"
class gfxAtoms {
public:
static void RegisterAtoms();
/* Declare all atoms
The atom names and values are stored in gfxAtomList.h and
are brought to you by the magic of C preprocessing
Add new atoms to gfxAtomList.h and all support logic will be auto-generated
*/
#define GFX_ATOM(_name, _value) static nsIAtom* _name;
#include "gfxAtomList.h"
#undef GFX_ATOM
};
#endif /* GFX_ATOMS_H */

View File

@ -88,7 +88,7 @@ gfxBeOSPlatform::CreateOffscreenSurface (PRUint32 width,
}
nsresult
gfxBeOSPlatform::GetFontList(const nsACString& aLangGroup,
gfxBeOSPlatform::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{

View File

@ -58,6 +58,7 @@
#include FT_TRUETYPE_TAGS_H
#include FT_TRUETYPE_TABLES_H
#include "gfxFontUtils.h"
#include "gfxAtoms.h"
#include "nsTArray.h"
#include "nsUnicodeRange.h"
#include "nsIPrefService.h"
@ -72,17 +73,11 @@ static PRLogModuleInfo *gFontLog = PR_NewLogModule("ft2fonts");
static const char *sCJKLangGroup[] = {
"ja",
"ko",
"zh-CN",
"zh-HK",
"zh-TW"
"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]
// rounding and truncation functions for a Freetype floating point number
// (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
@ -325,7 +320,7 @@ gfxFT2FontGroup::FontCallback(const nsAString& fontName,
}
gfxFT2FontGroup::gfxFT2FontGroup(const nsAString& families,
const gfxFontStyle *aStyle)
const gfxFontStyle *aStyle)
: gfxFontGroup(families, aStyle)
{
#ifdef DEBUG_pavlov
@ -336,7 +331,7 @@ gfxFT2FontGroup::gfxFT2FontGroup(const nsAString& families,
if (familyArray.Length() == 0) {
nsAutoString prefFamilies;
gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language.get(), prefFamilies, nsnull);
gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language, prefFamilies, nsnull);
if (!prefFamilies.IsEmpty()) {
ForEachFont(prefFamilies, aStyle->language, FontCallback, &familyArray);
}
@ -485,7 +480,7 @@ AddFontNameToArray(const nsAString& aName,
void
gfxFT2FontGroup::FamilyListToArrayList(const nsString& aFamilies,
const nsCString& aLangGroup,
nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList)
{
nsAutoTArray<nsString, 15> fonts;
@ -499,12 +494,13 @@ gfxFT2FontGroup::FamilyListToArrayList(const nsString& aFamilies,
}
}
void gfxFT2FontGroup::GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList) {
void gfxFT2FontGroup::GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
{
NS_ASSERTION(aLangGroup, "aLangGroup is null");
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
/* this lookup has to depend on weight and style */
nsCAutoString key(aLangGroup);
nsCAutoString key;
aLangGroup->ToUTF8String(key);
key.Append("-");
key.AppendInt(GetStyle()->style);
key.Append("-");
@ -515,8 +511,7 @@ void gfxFT2FontGroup::GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<gfx
if (fontString.IsEmpty())
return;
FamilyListToArrayList(fontString, nsDependentCString(aLangGroup),
&fonts);
FamilyListToArrayList(fontString, aLangGroup, &fonts);
platform->SetPrefFontEntries(key, fonts);
}
@ -579,8 +574,10 @@ void gfxFT2FontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEn
nsCAutoString lang(Substring(start, p));
lang.CompressWhitespace(PR_FALSE, PR_TRUE);
PRInt32 index = GetCJKLangGroupIndex(lang.get());
if (index >= 0)
GetPrefFonts(sCJKLangGroup[index], aFontEntryList);
if (index >= 0) {
nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
GetPrefFonts(atom, aFontEntryList);
}
p++;
}
}
@ -588,35 +585,35 @@ void gfxFT2FontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEn
// Add the system locale
#ifdef XP_WIN
switch (::GetACP()) {
case 932: GetPrefFonts(CJK_LANG_JA, aFontEntryList); break;
case 936: GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList); break;
case 949: GetPrefFonts(CJK_LANG_KO, aFontEntryList); break;
// XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950?
case 950: GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList); break;
case 932: GetPrefFonts(gfxAtoms::ja, aFontEntryList); break;
case 936: GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList); break;
case 949: GetPrefFonts(gfxAtoms::ko, aFontEntryList); break;
// XXX Don't we need to append gfxAtoms::zh_hk if the codepage is 950?
case 950: GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList); break;
}
#else
const char *ctype = setlocale(LC_CTYPE, NULL);
if (ctype) {
if (!PL_strncasecmp(ctype, "ja", 2)) {
GetPrefFonts(CJK_LANG_JA, aFontEntryList);
GetPrefFonts(gfxAtoms::ja, aFontEntryList);
} else if (!PL_strncasecmp(ctype, "zh_cn", 5)) {
GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList);
} else if (!PL_strncasecmp(ctype, "zh_hk", 5)) {
GetPrefFonts(CJK_LANG_ZH_HK, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_hk, aFontEntryList);
} else if (!PL_strncasecmp(ctype, "zh_tw", 5)) {
GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList);
} else if (!PL_strncasecmp(ctype, "ko", 2)) {
GetPrefFonts(CJK_LANG_KO, aFontEntryList);
GetPrefFonts(gfxAtoms::ko, aFontEntryList);
}
}
#endif
// last resort...
GetPrefFonts(CJK_LANG_JA, aFontEntryList);
GetPrefFonts(CJK_LANG_KO, aFontEntryList);
GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList);
GetPrefFonts(CJK_LANG_ZH_HK, aFontEntryList);
GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList);
GetPrefFonts(gfxAtoms::ja, aFontEntryList);
GetPrefFonts(gfxAtoms::ko, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_hk, aFontEntryList);
GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList);
platform->SetPrefFontEntries(key, aFontEntryList);
}
@ -646,7 +643,7 @@ gfxFT2FontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
// check out the style's language
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
GetPrefFonts(mStyle.language.get(), fonts);
GetPrefFonts(mStyle.language, fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);
// otherwise search prefs
@ -663,10 +660,13 @@ gfxFT2FontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
GetCJKPrefFonts(fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);
} else {
const char *langGroup = LangGroupFromUnicodeRange(unicodeRange);
nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
if (langGroup) {
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroup));
#ifdef PR_LOGGING
const char *langGroupStr;
langGroup->GetUTF8String(&langGroupStr);
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroupStr));
#endif
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
GetPrefFonts(langGroup, fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);

View File

@ -46,6 +46,7 @@
#include "gfxFont.h"
#include "gfxPlatform.h"
#include "gfxAtoms.h"
#include "prtypes.h"
#include "gfxTypes.h"
@ -1418,7 +1419,7 @@ gfxFontGroup::gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyl
mUserFontSet = nsnull;
SetUserFontSet(aUserFontSet);
mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.language.get());
mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.language);
BuildFontList();
}
@ -1537,7 +1538,7 @@ gfxFontGroup::ForEachFont(FontCreationCallback fc,
PRBool
gfxFontGroup::ForEachFont(const nsAString& aFamilies,
const nsACString& aLanguage,
nsIAtom *aLanguage,
FontCreationCallback fc,
void *closure)
{
@ -1560,7 +1561,7 @@ struct ResolveData {
PRBool
gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
const nsACString& aLanguage,
nsIAtom *aLanguage,
PRBool aResolveGeneric,
PRBool aResolveFontName,
FontCreationCallback fc,
@ -1570,22 +1571,21 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
const PRUnichar kDoubleQuote = PRUnichar('\"');
const PRUnichar kComma = PRUnichar(',');
nsCAutoString langGroup;
if (!gLangService) {
CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
}
if (gLangService) {
nsresult rv;
// temp, until we pass aLanguage as an Atom
nsCOMPtr<nsIAtom> lang = do_GetAtom(mStyle.language);
nsIAtom *group = gLangService->GetLanguageGroup(lang, &rv);
if (NS_SUCCEEDED(rv) && group) {
group->ToUTF8String(langGroup);
nsIAtom *groupAtom = nsnull;
nsCAutoString groupString;
if (aLanguage) {
if (!gLangService) {
CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
}
if (gLangService) {
nsresult rv;
groupAtom = gLangService->GetLanguageGroup(aLanguage, &rv);
}
}
if (langGroup.IsEmpty()) {
langGroup.Assign("x-unicode"); // XXX or should use "x-user-def"?
if (!groupAtom) {
groupAtom = gfxAtoms::x_unicode;
}
groupAtom->ToUTF8String(groupString);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
@ -1646,7 +1646,7 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
nsCAutoString prefName("font.name.");
prefName.Append(lcFamily);
prefName.AppendLiteral(".");
prefName.Append(langGroup);
prefName.Append(groupString);
// prefs file always uses (must use) UTF-8 so that we can use
// |GetCharPref| and treat the result as a UTF-8 string.
@ -1662,7 +1662,7 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
}
if (generic) {
ForEachFontInternal(family, langGroup, PR_FALSE,
ForEachFontInternal(family, groupAtom, PR_FALSE,
aResolveFontName, fc, closure);
} else if (!family.IsEmpty()) {
NS_LossyConvertUTF16toASCII gf(genericFamily);
@ -1693,11 +1693,11 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
nsCAutoString prefName("font.name-list.");
prefName.Append(lcFamily);
prefName.AppendLiteral(".");
prefName.Append(langGroup);
prefName.Append(groupString);
nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
ForEachFontInternal(NS_ConvertUTF8toUTF16(value),
langGroup, PR_FALSE, aResolveFontName,
groupAtom, PR_FALSE, aResolveFontName,
fc, closure);
}
}
@ -2168,12 +2168,12 @@ gfxFontStyle::gfxFontStyle() :
style(FONT_STYLE_NORMAL), systemFont(PR_TRUE), printerFont(PR_FALSE),
familyNameQuirks(PR_FALSE), weight(FONT_WEIGHT_NORMAL),
stretch(NS_FONT_STRETCH_NORMAL), size(DEFAULT_PIXEL_FONT_SIZE),
language(NS_LITERAL_CSTRING("x-western")), sizeAdjust(0.0f)
language(gfxAtoms::x_western), sizeAdjust(0.0f)
{
}
gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
gfxFloat aSize, const nsACString& aLanguage,
gfxFloat aSize, nsIAtom *aLanguage,
float aSizeAdjust, PRPackedBool aSystemFont,
PRPackedBool aFamilyNameQuirks,
PRPackedBool aPrinterFont):
@ -2194,9 +2194,9 @@ gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
size = 0.0;
}
if (language.IsEmpty()) {
NS_WARNING("empty language");
language.Assign("x-western");
if (!language) {
NS_WARNING("null language");
language = gfxAtoms::x_western;
}
}
@ -3521,9 +3521,11 @@ gfxTextRun::Dump(FILE* aOutput) {
gfxFont* font = mGlyphRuns[i].mFont;
const gfxFontStyle* style = font->GetStyle();
NS_ConvertUTF16toUTF8 fontName(font->GetName());
nsCAutoString lang;
style->language->ToUTF8String(lang);
fprintf(aOutput, "%d: %s %f/%d/%d/%s", mGlyphRuns[i].mCharacterOffset,
fontName.get(), style->size,
style->weight, style->style, style->language.get());
style->weight, style->style, lang.get());
}
fputc(']', aOutput);
}

View File

@ -275,14 +275,16 @@ gfxFontconfigUtils::gfxFontconfigUtils()
}
nsresult
gfxFontconfigUtils::GetFontList(const nsACString& aLangGroup,
gfxFontconfigUtils::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{
aListOfFonts.Clear();
nsTArray<nsCString> fonts;
nsresult rv = GetFontListInternal(fonts, aLangGroup);
nsCString langGroupStr;
aLangGroup->ToUTF8String(langGroupStr);
nsresult rv = GetFontListInternal(fonts, langGroupStr);
if (NS_FAILED(rv))
return rv;

View File

@ -103,7 +103,7 @@ public:
static void Shutdown();
nsresult GetFontList(const nsACString& aLangGroup,
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -110,16 +110,16 @@ gfxOS2Platform::CreateOffscreenSurface(const gfxIntSize& aSize,
}
nsresult
gfxOS2Platform::GetFontList(const nsACString& aLangGroup,
gfxOS2Platform::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{
#ifdef DEBUG_thebes
char *langgroup = ToNewCString(aLangGroup),
*family = ToNewCString(aGenericFamily);
const char *langgroup;
aLangGroup->GetUTF8String(&langgroup);
char *family = ToNewCString(aGenericFamily);
printf("gfxOS2Platform::GetFontList(%s, %s, ..)\n",
langgroup, family);
free(langgroup);
free(family);
#endif
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,

View File

@ -60,6 +60,7 @@
#include "gfxFT2Utils.h"
#include "gfxFontconfigUtils.h"
#include "gfxUserFontSet.h"
#include "gfxAtoms.h"
#include <freetype/tttables.h>
@ -97,6 +98,7 @@ int moz_pango_units_from_double(double d) {
}
static PangoLanguage *GuessPangoLanguage(const nsACString& aLangGroup);
static PangoLanguage *GuessPangoLanguage(nsIAtom *aLangGroup);
static cairo_scaled_font_t *CreateScaledFont(FcPattern *aPattern);
@ -1905,7 +1907,7 @@ gfxPangoFontGroup::Copy(const gfxFontStyle *aStyle)
// An array of family names suitable for fontconfig
void
gfxPangoFontGroup::GetFcFamilies(nsTArray<nsString> *aFcFamilyList,
const nsACString& aLanguage)
nsIAtom *aLanguage)
{
FamilyCallbackData data(aFcFamilyList, mUserFontSet);
// Leave non-existing fonts in the list so that fontconfig can get the
@ -1962,24 +1964,19 @@ gfxPangoFontGroup::MakeFontSet(PangoLanguage *aLang, gfxFloat aSizeAdjustFactor,
{
const char *lang = pango_language_to_string(aLang);
const char *langGroup = nsnull;
nsIAtom *langGroup = nsnull;
if (aLang != mPangoLanguage) {
// Set up langGroup for Mozilla's font prefs.
if (!gLangService) {
CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
}
if (gLangService) {
nsIAtom *atom =
gLangService->LookupLanguage(NS_ConvertUTF8toUTF16(lang));
if (atom) {
atom->GetUTF8String(&langGroup);
}
langGroup = gLangService->LookupLanguage(NS_ConvertUTF8toUTF16(lang));
}
}
nsAutoTArray<nsString, 20> fcFamilyList;
GetFcFamilies(&fcFamilyList,
langGroup ? nsDependentCString(langGroup) : mStyle.language);
GetFcFamilies(&fcFamilyList, langGroup ? langGroup : mStyle.language);
// To consider: A fontset cache here could be helpful.
@ -2208,7 +2205,7 @@ gfxFcFont::GetOrMakeFont(FcPattern *aPattern)
// The LangSet in the FcPattern does not have an order so there is no
// one particular language to choose and converting the set to a
// string through FcNameUnparse() is more trouble than it's worth.
NS_NAMED_LITERAL_CSTRING(language, "en"); // TODO: get the correct language?
nsIAtom *language = gfxAtoms::en; // TODO: get the correct language?
// FIXME: Pass a real stretch based on aPattern!
gfxFontStyle fontStyle(style, weight, NS_FONT_STRETCH_NORMAL,
size, language, 0.0,
@ -3117,6 +3114,17 @@ GuessPangoLanguage(const nsACString& aLangGroup)
return pango_language_from_string(lang.get());
}
PangoLanguage *
GuessPangoLanguage(nsIAtom *aLangGroup)
{
if (!aLangGroup)
return NULL;
nsCAutoString lg;
aLangGroup->ToUTF8String(lg);
return GuessPangoLanguage(lg);
}
#ifdef MOZ_WIDGET_GTK2
/***************************************************************************
*

View File

@ -51,6 +51,7 @@
#include "gfxOS2Platform.h"
#endif
#include "gfxAtoms.h"
#include "gfxPlatformFontList.h"
#include "gfxContext.h"
#include "gfxImageSurface.h"
@ -174,6 +175,9 @@ nsresult
gfxPlatform::Init()
{
NS_ASSERTION(!gPlatform, "Already started???");
gfxAtoms::RegisterAtoms();
#if defined(XP_WIN)
gPlatform = new gfxWindowsPlatform;
#elif defined(XP_MACOSX)
@ -301,7 +305,7 @@ gfxPlatform::OptimizeImage(gfxImageSurface *aSurface,
}
nsresult
gfxPlatform::GetFontList(const nsACString& aLangGroup,
gfxPlatform::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{
@ -353,7 +357,7 @@ gfxPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
}
static void
AppendGenericFontFromPref(nsString& aFonts, const char *aLangGroup, const char *aGenericName)
AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGenericName)
{
nsresult rv;
@ -361,20 +365,22 @@ AppendGenericFontFromPref(nsString& aFonts, const char *aLangGroup, const char *
if (!prefs)
return;
nsCAutoString prefName;
nsCAutoString prefName, langGroupString;
nsXPIDLCString nameValue, nameListValue;
aLangGroup->ToUTF8String(langGroupString);
nsCAutoString genericDotLang;
if (aGenericName) {
genericDotLang.Assign(aGenericName);
} else {
prefName.AssignLiteral("font.default.");
prefName.Append(aLangGroup);
prefName.Append(langGroupString);
prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
}
genericDotLang.AppendLiteral(".");
genericDotLang.Append(aLangGroup);
genericDotLang.Append(langGroupString);
// fetch font.name.xxx value
prefName.AssignLiteral("font.name.");
@ -398,13 +404,13 @@ AppendGenericFontFromPref(nsString& aFonts, const char *aLangGroup, const char *
}
void
gfxPlatform::GetPrefFonts(const char *aLanguage, nsString& aFonts, PRBool aAppendUnicode)
gfxPlatform::GetPrefFonts(nsIAtom *aLanguage, nsString& aFonts, PRBool aAppendUnicode)
{
aFonts.Truncate();
AppendGenericFontFromPref(aFonts, aLanguage, nsnull);
if (aAppendUnicode)
AppendGenericFontFromPref(aFonts, "x-unicode", nsnull);
AppendGenericFontFromPref(aFonts, gfxAtoms::x_unicode, nsnull);
}
PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen, PrefFontCallback aCallback,
@ -486,6 +492,16 @@ gfxPlatform::GetFontPrefLangFor(const char* aLang)
return eFontPrefLang_Others;
}
eFontPrefLang
gfxPlatform::GetFontPrefLangFor(nsIAtom *aLang)
{
if (!aLang)
return eFontPrefLang_Others;
nsCAutoString lang;
aLang->ToUTF8String(lang);
return GetFontPrefLangFor(lang.get());
}
const char*
gfxPlatform::GetPrefLangName(eFontPrefLang aLang)
{

View File

@ -263,12 +263,12 @@ gfxPlatformFontList::ResolveFontName(const nsAString& aFontName, nsAString& aRes
}
struct FontListData {
FontListData(const nsACString& aLangGroup,
FontListData(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts) :
mLangGroup(aLangGroup), mGenericFamily(aGenericFamily),
mListOfFonts(aListOfFonts) {}
const nsACString& mLangGroup;
nsIAtom *mLangGroup;
const nsACString& mGenericFamily;
nsTArray<nsString>& mListOfFonts;
};
@ -306,7 +306,7 @@ gfxPlatformFontList::HashEnumFuncForFamilies(nsStringHashKey::KeyType aKey,
}
void
gfxPlatformFontList::GetFontList(const nsACString& aLangGroup,
gfxPlatformFontList::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{

View File

@ -74,7 +74,7 @@ public:
sPlatformFontList = nsnull;
}
void GetFontList (const nsACString& aLangGroup,
void GetFontList (nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts);

View File

@ -258,7 +258,7 @@ gfxPlatformGtk::CreateOffscreenSurface(const gfxIntSize& size,
#ifdef MOZ_PANGO
nsresult
gfxPlatformGtk::GetFontList(const nsACString& aLangGroup,
gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{

View File

@ -214,7 +214,7 @@ gfxPlatformMac::IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags)
// these will also move to gfxPlatform once all platforms support the fontlist
nsresult
gfxPlatformMac::GetFontList(const nsACString& aLangGroup,
gfxPlatformMac::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{

View File

@ -224,9 +224,9 @@ gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
}
nsresult
gfxQtPlatform::GetFontList(const nsACString& aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
aListOfFonts);

View File

@ -49,6 +49,7 @@
#include "gfxWindowsSurface.h"
#include "gfxWindowsPlatform.h"
#include "gfxGDIFontList.h"
#include "gfxAtoms.h"
#include "gfxFontTest.h"
@ -558,7 +559,7 @@ gfxWindowsFontGroup::GroupFamilyListToArrayList(nsTArray<nsRefPtr<gfxFontEntry>
void
gfxWindowsFontGroup::FamilyListToArrayList(const nsString& aFamilies,
const nsCString& aLangGroup,
nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> > *list)
{
nsAutoTArray<nsString, 15> fonts;
@ -1040,17 +1041,11 @@ static const struct ScriptPropertyEntry gScriptToText[] =
static const char *sCJKLangGroup[] = {
"ja",
"ko",
"zh-CN",
"zh-HK",
"zh-TW"
"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]
#define STATIC_STRING_LENGTH 100
@ -1718,13 +1713,15 @@ gfxWindowsFontGroup::WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry>
}
// this function appends to the array passed in.
void gfxWindowsFontGroup::GetPrefFonts(const char *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> >& array) {
void gfxWindowsFontGroup::GetPrefFonts(nsIAtom *aLangGroup,
nsTArray<nsRefPtr<gfxFontEntry> >& array)
{
NS_ASSERTION(aLangGroup, "aLangGroup is null");
gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
/* this lookup has to depend on weight and style */
nsCAutoString key(aLangGroup);
nsCAutoString key;
aLangGroup->ToUTF8String(key);
key.Append("-");
key.AppendInt(GetStyle()->style);
key.Append("-");
@ -1735,8 +1732,7 @@ void gfxWindowsFontGroup::GetPrefFonts(const char *aLangGroup,
if (fontString.IsEmpty())
return;
FamilyListToArrayList(fontString, nsDependentCString(aLangGroup),
&fonts);
FamilyListToArrayList(fontString, aLangGroup, &fonts);
platform->SetPrefFontEntries(key, fonts);
}
@ -1799,27 +1795,29 @@ void gfxWindowsFontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& arr
nsCAutoString lang(Substring(start, p));
lang.CompressWhitespace(PR_FALSE, PR_TRUE);
PRInt32 index = GetCJKLangGroupIndex(lang.get());
if (index >= 0)
GetPrefFonts(sCJKLangGroup[index], array);
if (index >= 0) {
nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
GetPrefFonts(atom, array);
}
p++;
}
}
// Add the system locale
switch (::GetACP()) {
case 932: GetPrefFonts(CJK_LANG_JA, array); break;
case 936: GetPrefFonts(CJK_LANG_ZH_CN, array); break;
case 949: GetPrefFonts(CJK_LANG_KO, array); break;
// XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950?
case 950: GetPrefFonts(CJK_LANG_ZH_TW, array); break;
case 932: GetPrefFonts(gfxAtoms::ja, array); break;
case 936: GetPrefFonts(gfxAtoms::zh_cn, array); break;
case 949: GetPrefFonts(gfxAtoms::ko, array); break;
// XXX Don't we need to append gfxAtoms::zh_hk if the codepage is 950?
case 950: GetPrefFonts(gfxAtoms::zh_tw, array); break;
}
// last resort...
GetPrefFonts(CJK_LANG_JA, array);
GetPrefFonts(CJK_LANG_KO, array);
GetPrefFonts(CJK_LANG_ZH_CN, array);
GetPrefFonts(CJK_LANG_ZH_HK, array);
GetPrefFonts(CJK_LANG_ZH_TW, array);
GetPrefFonts(gfxAtoms::ja, array);
GetPrefFonts(gfxAtoms::ko, array);
GetPrefFonts(gfxAtoms::zh_cn, array);
GetPrefFonts(gfxAtoms::zh_hk, array);
GetPrefFonts(gfxAtoms::zh_tw, array);
platform->SetPrefFontEntries(key, array);
}
@ -1833,7 +1831,7 @@ gfxWindowsFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
// check out the style's language group
if (!selectedFont) {
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
this->GetPrefFonts(mStyle.language.get(), fonts);
this->GetPrefFonts(mStyle.language, fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);
}
@ -1844,7 +1842,8 @@ gfxWindowsFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s ", mItemLangGroup));
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
this->GetPrefFonts(mItemLangGroup, fonts);
nsCOMPtr<nsIAtom> lgAtom = do_GetAtom(mItemLangGroup);
this->GetPrefFonts(lgAtom, fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);
} else if (aCh <= 0xFFFF) {
PRUint32 unicodeRange = FindCharUnicodeRange(aCh);
@ -1858,10 +1857,13 @@ gfxWindowsFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
this->GetCJKPrefFonts(fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);
} else {
const char *langGroup = LangGroupFromUnicodeRange(unicodeRange);
nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
if (langGroup) {
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroup));
#ifdef PR_LOGGING
const char *langGroupStr;
langGroup->GetUTF8String(&langGroupStr);
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroupStr));
#endif
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
this->GetPrefFonts(langGroup, fonts);
selectedFont = WhichFontSupportsChar(fonts, aCh);

View File

@ -167,7 +167,7 @@ gfxWindowsPlatform::CreateOffscreenSurface(const gfxIntSize& size,
}
nsresult
gfxWindowsPlatform::GetFontList(const nsACString& aLangGroup,
gfxWindowsPlatform::GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts)
{

View File

@ -36,38 +36,40 @@
* ***** END LICENSE BLOCK ***** */
#include "nsUnicodeRange.h"
#include "nsIAtom.h"
#include "gfxAtoms.h"
// This table depends on unicode range definitions.
// Each item's index must correspond unicode range value
// eg. x-cyrillic = LangGroupTable[kRangeCyrillic]
static const char *gUnicodeRangeToLangGroupTable[] =
static nsIAtom **gUnicodeRangeToLangGroupAtomTable[] =
{
"x-cyrillic",
"el",
"tr",
"he",
"ar",
"x-baltic",
"th",
"ko",
"ja",
"zh-CN",
"zh-TW",
"x-devanagari",
"x-tamil",
"x-armn",
"x-beng",
"x-cans",
"x-ethi",
"x-geor",
"x-gujr",
"x-guru",
"x-khmr",
"x-mlym",
"x-orya",
"x-telu",
"x-knda",
"x-sinh"
&gfxAtoms::x_cyrillic,
&gfxAtoms::el,
&gfxAtoms::tr,
&gfxAtoms::he,
&gfxAtoms::ar,
&gfxAtoms::x_baltic,
&gfxAtoms::th,
&gfxAtoms::ko,
&gfxAtoms::ja,
&gfxAtoms::zh_cn,
&gfxAtoms::zh_tw,
&gfxAtoms::x_devanagari,
&gfxAtoms::x_tamil,
&gfxAtoms::x_armn,
&gfxAtoms::x_beng,
&gfxAtoms::x_cans,
&gfxAtoms::x_ethi,
&gfxAtoms::x_geor,
&gfxAtoms::x_gujr,
&gfxAtoms::x_guru,
&gfxAtoms::x_khmr,
&gfxAtoms::x_mlym,
&gfxAtoms::x_orya,
&gfxAtoms::x_telu,
&gfxAtoms::x_knda,
&gfxAtoms::x_sinh
};
/**********************************************************************
@ -455,9 +457,11 @@ PRUint32 FindCharUnicodeRange(PRUnichar ch)
return gUnicodeTertiaryRangeTable[(ch - 0x0700) >> 7];
}
const char* LangGroupFromUnicodeRange(PRUint8 unicodeRange)
nsIAtom *LangGroupFromUnicodeRange(PRUint8 unicodeRange)
{
if (kRangeSpecificItemNum > unicodeRange)
return gUnicodeRangeToLangGroupTable[unicodeRange];
if (kRangeSpecificItemNum > unicodeRange) {
nsIAtom **atom = gUnicodeRangeToLangGroupAtomTable[unicodeRange];
return *atom;
}
return nsnull;
}

View File

@ -37,6 +37,8 @@
#include "nscore.h"
class nsIAtom;
// The following constants define unicode subranges
// values below kRangeNum must be continuous so that we can map to
// lang group directly.
@ -112,4 +114,4 @@ const PRUint8 kRangeTertiaryTable = 145; // leave room for 16 subtable
PRUint32 FindCharUnicodeRange(PRUnichar ch);
const char* LangGroupFromUnicodeRange(PRUint8 unicodeRange);
nsIAtom* LangGroupFromUnicodeRange(PRUint8 unicodeRange);

View File

@ -109,7 +109,7 @@ SetupTests()
NS_FONT_STRETCH_NORMAL,
400,
16.0,
nsDependentCString("en"),
NS_NewPermanentAtom("en"),
0.0,
PR_FALSE, PR_FALSE, PR_FALSE);
@ -117,7 +117,7 @@ SetupTests()
NS_FONT_STRETCH_NORMAL,
700,
16.0,
nsDependentCString("en"),
NS_NewPermanentAtom("en"),
0.0,
PR_FALSE, PR_FALSE, PR_FALSE);

View File

@ -93,7 +93,7 @@ RunTest (TestEntry *test, gfxContext *ctx) {
NS_FONT_STRETCH_NORMAL,
400,
16.0,
nsDependentCString("en"),
NS_NewPermanentAtom("en"),
0.0,
PR_FALSE, PR_FALSE, PR_FALSE);

View File

@ -159,7 +159,7 @@ main (int argc, char **argv) {
NS_FONT_STRETCH_NORMAL,
139,
10.0,
nsDependentCString("en"),
NS_NewPermanentAtom("en"),
0.0,
PR_FALSE, PR_FALSE, PR_FALSE);

View File

@ -1335,12 +1335,6 @@ nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
nsCString language;
nsIAtom *languageAtom = mStyleContext->GetStyleVisibility()->mLanguage;
if (languageAtom) {
languageAtom->ToUTF8String(language);
}
if (GetStyleSVG()->mTextRendering ==
NS_STYLE_TEXT_RENDERING_GEOMETRICPRECISION) {
textRunSize = PRECISE_SIZE;
@ -1354,7 +1348,8 @@ nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
PRBool printerFont = (presContext->Type() == nsPresContext::eContext_PrintPreview ||
presContext->Type() == nsPresContext::eContext_Print);
gfxFontStyle fontStyle(font.style, font.weight, font.stretch, textRunSize,
language, font.sizeAdjust, font.systemFont,
mStyleContext->GetStyleVisibility()->mLanguage,
font.sizeAdjust, font.systemFont,
font.familyNameQuirks,
printerFont);