Bug 1348299 - Use both, OS locale and app locale when trying to test for potentially Japanese fonts. r=m_kato
authorZibi Braniecki <gandalf@mozilla.com>
Wed, 22 Mar 2017 00:27:14 -0700
changeset 348998 258d94311e1e707d6cec608bfe13d23095cea5ec
parent 348997 cd12bd4827548b4556b2e1b40f56f6315d018060
child 348999 7c7f3615f433c9d5dd898fb3fbe95601c1e85751
push id39377
push userzbraniecki@mozilla.com
push dateThu, 23 Mar 2017 06:07:21 +0000
treeherderautoland@258d94311e1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1348299
milestone55.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 1348299 - Use both, OS locale and app locale when trying to test for potentially Japanese fonts. r=m_kato MozReview-Commit-ID: 5Dtq1WplSML
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxPlatformFontList.cpp
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 #include "gfxAndroidPlatform.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/CountingAllocatorBase.h"
 #include "mozilla/intl/LocaleService.h"
+#include "mozilla/intl/OSPreferences.h"
 #include "mozilla/Preferences.h"
 
 #include "gfx2DGlue.h"
 #include "gfxFT2FontList.h"
 #include "gfxImageSurface.h"
 #include "gfxTextRun.h"
 #include "mozilla/dom/ContentChild.h"
 #include "nsXULAppAPI.h"
@@ -30,16 +31,17 @@
 #include FT_MODULE_H
 
 #include "GeneratedJNINatives.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 using mozilla::intl::LocaleService;
+using mozilla::intl::OSPreferences;
 
 static FT_Library gPlatformFTLibrary = nullptr;
 
 class FreetypeReporter final : public nsIMemoryReporter,
                                public CountingAllocatorBase<FreetypeReporter>
 {
 private:
     ~FreetypeReporter() {}
@@ -134,16 +136,23 @@ IsJapaneseLocale()
         sInitialized = true;
 
         nsAutoCString appLocale;
         LocaleService::GetInstance()->GetAppLocaleAsLangTag(appLocale);
 
         const nsDependentCSubstring lang(appLocale, 0, 2);
         if (lang.EqualsLiteral("ja")) {
             sIsJapanese = true;
+        } else {
+            OSPreferences::GetInstance()->GetSystemLocale(appLocale);
+
+            const nsDependentCSubstring lang(appLocale, 0, 2);
+            if (lang.EqualsLiteral("ja")) {
+                sIsJapanese = true;
+            }
         }
     }
 
     return sIsJapanese;
 }
 
 void
 gfxAndroidPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -1,15 +1,16 @@
 /* -*- 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/. */
 
 #include "mozilla/Logging.h"
 #include "mozilla/intl/LocaleService.h"
+#include "mozilla/intl/OSPreferences.h"
 
 #include "gfxPlatformFontList.h"
 #include "gfxTextRun.h"
 #include "gfxUserFontSet.h"
 
 #include "nsCRT.h"
 #include "nsGkAtoms.h"
 #include "nsServiceManagerUtils.h"
@@ -24,16 +25,17 @@
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/gfx/2D.h"
 
 #include <locale.h>
 
 using namespace mozilla;
 using mozilla::intl::LocaleService;
+using mozilla::intl::OSPreferences;
 
 #define LOG_FONTLIST(args) MOZ_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), \
                                LogLevel::Debug, args)
 #define LOG_FONTLIST_ENABLED() MOZ_LOG_TEST( \
                                    gfxPlatform::GetLog(eGfxLog_fontlist), \
                                    LogLevel::Debug)
 #define LOG_FONTINIT(args) MOZ_LOG(gfxPlatform::GetLog(eGfxLog_fontinit), \
                                LogLevel::Debug, args)
@@ -1086,33 +1088,57 @@ gfxPlatformFontList::AppendCJKPrefLangs(
                         break;
                     default:
                         break;
                 }
                 p++;
             }
         }
 
+        // Try using app's locale
         nsAutoCString localeStr;
         LocaleService::GetInstance()->GetAppLocaleAsLangTag(localeStr);
 
-        const nsACString& lang = Substring(localeStr, 0, 2);
-        if (lang.EqualsLiteral("ja")) {
-            AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
-        } else if (lang.EqualsLiteral("zh")) {
-            const nsACString& region = Substring(localeStr, 3, 2);
-            if (region.EqualsLiteral("CN")) {
-                AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
-            } else if (region.EqualsLiteral("TW")) {
-                AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
-            } else if (region.EqualsLiteral("HK")) {
-                AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
-            }
-        } else if (lang.EqualsLiteral("ko")) {
-            AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
+        {
+          const nsACString& lang = Substring(localeStr, 0, 2);
+          if (lang.EqualsLiteral("ja")) {
+              AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
+          } else if (lang.EqualsLiteral("zh")) {
+              const nsACString& region = Substring(localeStr, 3, 2);
+              if (region.EqualsLiteral("CN")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
+              } else if (region.EqualsLiteral("TW")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
+              } else if (region.EqualsLiteral("HK")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
+              }
+          } else if (lang.EqualsLiteral("ko")) {
+              AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
+          }
+        }
+
+        // Then test OS locale
+        OSPreferences::GetInstance()->GetSystemLocale(localeStr);
+
+        {
+          const nsACString& lang = Substring(localeStr, 0, 2);
+          if (lang.EqualsLiteral("ja")) {
+              AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
+          } else if (lang.EqualsLiteral("zh")) {
+              const nsACString& region = Substring(localeStr, 3, 2);
+              if (region.EqualsLiteral("CN")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
+              } else if (region.EqualsLiteral("TW")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
+              } else if (region.EqualsLiteral("HK")) {
+                  AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
+              }
+          } else if (lang.EqualsLiteral("ko")) {
+              AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
+          }
         }
 
         // last resort... (the order is same as old gfx.)
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);