Bug 1163488 - use the preprocessor to keep font lang arrays in sync. r=m_kato

This commit is contained in:
John Daggett 2015-07-10 23:49:26 +09:00
parent dfc652acca
commit 8742a89b16
4 changed files with 49 additions and 96 deletions

View File

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// this needs to match the list of pref font.default.xx entries listed in all.js!
FONT_PREF_LANG(Western, "x-western", x_western),
FONT_PREF_LANG(Japanese, "ja", Japanese),
FONT_PREF_LANG(ChineseTW, "zh-TW", Taiwanese),
FONT_PREF_LANG(ChineseCN, "zh-CN", Chinese),
FONT_PREF_LANG(ChineseHK, "zh-HK", HongKongChinese),
FONT_PREF_LANG(Korean, "ko", ko),
FONT_PREF_LANG(Cyrillic, "x-cyrillic", x_cyrillic),
FONT_PREF_LANG(Greek, "el", el),
FONT_PREF_LANG(Thai, "th", th),
FONT_PREF_LANG(Hebrew, "he", he),
FONT_PREF_LANG(Arabic, "ar", ar),
FONT_PREF_LANG(Devanagari, "x-devanagari", x_devanagari),
FONT_PREF_LANG(Tamil, "x-tamil", x_tamil),
FONT_PREF_LANG(Armenian, "x-armn", x_armn),
FONT_PREF_LANG(Bengali, "x-beng", x_beng),
FONT_PREF_LANG(Canadian, "x-cans", x_cans),
FONT_PREF_LANG(Ethiopic, "x-ethi", x_ethi),
FONT_PREF_LANG(Georgian, "x-geor", x_geor),
FONT_PREF_LANG(Gujarati, "x-gujr", x_gujr),
FONT_PREF_LANG(Gurmukhi, "x-guru", x_guru),
FONT_PREF_LANG(Khmer, "x-khmr", x_khmr),
FONT_PREF_LANG(Malayalam, "x-mlym", x_mlym),
FONT_PREF_LANG(Oriya, "x-orya", x_orya),
FONT_PREF_LANG(Telugu, "x-telu", x_telu),
FONT_PREF_LANG(Kannada, "x-knda", x_knda),
FONT_PREF_LANG(Sinhala, "x-sinh", x_sinh),
FONT_PREF_LANG(Tibetan, "x-tibt", x_tibt),
FONT_PREF_LANG(Others, "x-unicode", Unicode)

View File

@ -352,76 +352,22 @@ MemoryPressureObserver::Observe(nsISupports *aSubject,
return NS_OK;
}
// this needs to match the list of pref font.default.xx entries listed in all.js!
// the order *must* match the order in eFontPrefLang
// xxx - this can probably be eliminated by reworking pref font handling code
static const char *gPrefLangNames[] = {
"x-western",
"ja",
"zh-TW",
"zh-CN",
"zh-HK",
"ko",
"x-cyrillic",
"el",
"th",
"he",
"ar",
"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",
"x-tibt",
"x-unicode",
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) str_
#include "gfxFontPrefLangList.h"
#undef FONT_PREF_LANG
};
static nsIAtom* PrefLangToLangGroups(uint32_t aIndex)
{
// This needs to match the list of pref font.default.xx entries listed in
// all.js! The order *must* match the order in eFontPrefLang.
//
// Having this array within a static function rather than at the top-level
// avoids a static constructor.
// static array here avoids static constructor
static nsIAtom* gPrefLangToLangGroups[] = {
nsGkAtoms::x_western,
nsGkAtoms::Japanese,
nsGkAtoms::Taiwanese,
nsGkAtoms::Chinese,
nsGkAtoms::HongKongChinese,
nsGkAtoms::ko,
nsGkAtoms::x_cyrillic,
nsGkAtoms::el,
nsGkAtoms::th,
nsGkAtoms::he,
nsGkAtoms::ar,
nsGkAtoms::x_devanagari,
nsGkAtoms::x_tamil,
nsGkAtoms::x_armn,
nsGkAtoms::x_beng,
nsGkAtoms::x_cans,
nsGkAtoms::x_ethi,
nsGkAtoms::x_geor,
nsGkAtoms::x_gujr,
nsGkAtoms::x_guru,
nsGkAtoms::x_khmr,
nsGkAtoms::x_mlym,
nsGkAtoms::x_orya,
nsGkAtoms::x_telu,
nsGkAtoms::x_knda,
nsGkAtoms::x_sinh,
nsGkAtoms::x_tibt,
nsGkAtoms::Unicode
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) nsGkAtoms::atom_id_
#include "gfxFontPrefLangList.h"
#undef FONT_PREF_LANG
};
return aIndex < ArrayLength(gPrefLangToLangGroups)
? gPrefLangToLangGroups[aIndex]
: nsGkAtoms::Unicode;

View File

@ -69,41 +69,12 @@ BackendTypeBit(BackendType b)
extern cairo_user_data_key_t kDrawTarget;
// pref lang id's for font prefs
// !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
// !!! don't use as bit mask, this may grow larger !!!
enum eFontPrefLang {
eFontPrefLang_Western = 0,
eFontPrefLang_Japanese = 1,
eFontPrefLang_ChineseTW = 2,
eFontPrefLang_ChineseCN = 3,
eFontPrefLang_ChineseHK = 4,
eFontPrefLang_Korean = 5,
eFontPrefLang_Cyrillic = 6,
eFontPrefLang_Greek = 7,
eFontPrefLang_Thai = 8,
eFontPrefLang_Hebrew = 9,
eFontPrefLang_Arabic = 10,
eFontPrefLang_Devanagari = 11,
eFontPrefLang_Tamil = 12,
eFontPrefLang_Armenian = 13,
eFontPrefLang_Bengali = 14,
eFontPrefLang_Canadian = 15,
eFontPrefLang_Ethiopic = 16,
eFontPrefLang_Georgian = 17,
eFontPrefLang_Gujarati = 18,
eFontPrefLang_Gurmukhi = 19,
eFontPrefLang_Khmer = 20,
eFontPrefLang_Malayalam = 21,
eFontPrefLang_Oriya = 22,
eFontPrefLang_Telugu = 23,
eFontPrefLang_Kannada = 24,
eFontPrefLang_Sinhala = 25,
eFontPrefLang_Tibetan = 26,
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) eFontPrefLang_ ## enum_id_
#include "gfxFontPrefLangList.h"
#undef FONT_PREF_LANG
eFontPrefLang_Others = 27, // x-unicode
eFontPrefLang_CJKSet = 28 // special code for CJK set
, eFontPrefLang_CJKSet // special code for CJK set
};
enum eCMSMode {

View File

@ -23,6 +23,7 @@ EXPORTS += [
'gfxFontFamilyList.h',
'gfxFontFeatures.h',
'gfxFontInfoLoader.h',
'gfxFontPrefLangList.h',
'gfxFontTest.h',
'gfxFontUtils.h',
'gfxGradientCache.h',