Bug 1163488 - use the preprocessor to keep font lang arrays in sync. r=m_kato
authorJohn Daggett <jdaggett@mozilla.com>
Fri, 10 Jul 2015 23:49:26 +0900
changeset 285838 ca220c8e98832c14ac2cc69e9f0f7c81315cb3da
parent 285837 3e19c8e5c60c093787c29637c4077de5901a9e66
child 285839 52bf22e257803f2da6c849e60033153fa7bd5c7e
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1163488
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1163488 - use the preprocessor to keep font lang arrays in sync. r=m_kato
gfx/thebes/gfxFontPrefLangList.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/gfxFontPrefLangList.h
@@ -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)
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -347,86 +347,32 @@ MemoryPressureObserver::Observe(nsISuppo
     NS_ASSERTION(strcmp(aTopic, "memory-pressure") == 0, "unexpected event topic");
     Factory::PurgeAllCaches();
     gfxGradientCache::PurgeAllCaches();
 
     gfxPlatform::GetPlatform()->PurgeSkiaCache();
     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;
 }
 
 gfxPlatform::gfxPlatform()
   : mTileWidth(-1)
   , mTileHeight(-1)
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -64,51 +64,22 @@ BackendTypeBit(BackendType b)
     if (gfxPrefs::PerfWarnings()) { \
       printf_stderr("[" module "] " __VA_ARGS__); \
     } \
   } while (0)
 
 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 {
+    #define FONT_PREF_LANG(enum_id_, str_, atom_id_) eFontPrefLang_ ## enum_id_
+    #include "gfxFontPrefLangList.h"
+    #undef FONT_PREF_LANG
 
-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,
-
-    eFontPrefLang_Others      = 27, // x-unicode
-
-    eFontPrefLang_CJKSet      = 28  // special code for CJK set
+    , eFontPrefLang_CJKSet  // special code for CJK set
 };
 
 enum eCMSMode {
     eCMSMode_Off          = 0,     // No color management
     eCMSMode_All          = 1,     // Color manage everything
     eCMSMode_TaggedOnly   = 2,     // Color manage tagged Images Only
     eCMSMode_AllCount     = 3
 };
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -18,16 +18,17 @@ EXPORTS += [
     'gfxDrawable.h',
     'gfxFailure.h',
     'gfxFont.h',
     'gfxFontConstants.h',
     'gfxFontEntry.h',
     'gfxFontFamilyList.h',
     'gfxFontFeatures.h',
     'gfxFontInfoLoader.h',
+    'gfxFontPrefLangList.h',
     'gfxFontTest.h',
     'gfxFontUtils.h',
     'gfxGradientCache.h',
     'gfxImageSurface.h',
     'gfxLineSegment.h',
     'gfxMathTable.h',
     'gfxMatrix.h',
     'gfxPattern.h',