Bug 1345957 - Update the use of LocaleService API in gfxPlatformFontList. r?jfkthame draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Tue, 06 Mar 2018 18:55:22 -0800
changeset 764085 7fa2466b11d0f2bc06ffe67e749f8598d3c38242
parent 764084 c2e50fb251c9bf2bd4adc016a6795304938fa5ef
push id101659
push userbmo:gandalf@aviary.pl
push dateWed, 07 Mar 2018 05:11:28 +0000
reviewersjfkthame
bugs1345957
milestone60.0a1
Bug 1345957 - Update the use of LocaleService API in gfxPlatformFontList. r?jfkthame MozReview-Commit-ID: Lj7H2DwlS91
gfx/thebes/gfxPlatformFontList.cpp
--- 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/MozLocale.h"
 #include "mozilla/intl/OSPreferences.h"
 
 #include "gfxPlatformFontList.h"
 #include "gfxTextRun.h"
 #include "gfxUserFontSet.h"
 
 #include "nsCRT.h"
 #include "nsGkAtoms.h"
@@ -28,16 +29,17 @@
 #include "mozilla/TimeStamp.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/gfx/2D.h"
 
 #include <locale.h>
 
 using namespace mozilla;
 using mozilla::intl::LocaleService;
+using mozilla::intl::Locale;
 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), \
@@ -1238,65 +1240,64 @@ gfxPlatformFontList::AppendCJKPrefLangs(
             }
         }
 
         // Try using app's locale
         nsAutoCString localeStr;
         LocaleService::GetInstance()->GetAppLocaleAsLangTag(localeStr);
 
         {
-          const nsACString& lang = Substring(localeStr, 0, 2);
-          if (lang.EqualsLiteral("ja")) {
+          Locale locale(localeStr);
+          if (locale.GetLanguage().Equals("ja")) {
               AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
-          } else if (lang.EqualsLiteral("zh")) {
-              const nsACString& region = Substring(localeStr, 3, 2);
-              if (region.EqualsLiteral("CN")) {
+          } else if (locale.GetLanguage().Equals("zh")) {
+              if (locale.GetRegion().Equals("CN")) {
                   AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
-              } else if (region.EqualsLiteral("TW")) {
+              } else if (locale.GetRegion().Equals("TW")) {
                   AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
-              } else if (region.EqualsLiteral("HK")) {
+              } else if (locale.GetRegion().Equals("HK")) {
                   AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
               }
-          } else if (lang.EqualsLiteral("ko")) {
+          } else if (locale.GetLanguage().Equals("ko")) {
               AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
           }
         }
 
         // Then add the known CJK prefs in order of system preferred locales
         AutoTArray<nsCString,5> prefLocales;
         prefLocales.AppendElement(NS_LITERAL_CSTRING("ja"));
         prefLocales.AppendElement(NS_LITERAL_CSTRING("zh-CN"));
         prefLocales.AppendElement(NS_LITERAL_CSTRING("zh-TW"));
         prefLocales.AppendElement(NS_LITERAL_CSTRING("zh-HK"));
         prefLocales.AppendElement(NS_LITERAL_CSTRING("ko"));
 
         AutoTArray<nsCString,16> sysLocales;
         AutoTArray<nsCString,16> negLocales;
-        if (OSPreferences::GetInstance()->GetSystemLocales(sysLocales) &&
+        if (OSPreferences::GetInstance()->GetSystemLocales(sysLocales)) {
             LocaleService::GetInstance()->NegotiateLanguages(
                 sysLocales, prefLocales, NS_LITERAL_CSTRING(""),
-                LocaleService::LangNegStrategy::Filtering, negLocales)) {
+                LocaleService::LangNegStrategy::Filtering, negLocales);
             for (const auto& localeStr : negLocales) {
-                const nsACString& lang = Substring(localeStr, 0, 2);
-                if (lang.EqualsLiteral("ja")) {
+                Locale locale(localeStr);
+
+                if (locale.GetLanguage().Equals("ja")) {
                     AppendPrefLang(tempPrefLangs, tempLen,
                                    eFontPrefLang_Japanese);
-                } else if (lang.EqualsLiteral("zh")) {
-                    const nsACString& region = Substring(localeStr, 3, 2);
-                    if (region.EqualsLiteral("CN")) {
+                } else if (locale.GetLanguage().Equals("zh")) {
+                    if (locale.GetRegion().Equals("CN")) {
                         AppendPrefLang(tempPrefLangs, tempLen,
                                        eFontPrefLang_ChineseCN);
-                    } else if (region.EqualsLiteral("TW")) {
+                    } else if (locale.GetRegion().Equals("TW")) {
                         AppendPrefLang(tempPrefLangs, tempLen,
                                        eFontPrefLang_ChineseTW);
-                    } else if (region.EqualsLiteral("HK")) {
+                    } else if (locale.GetRegion().Equals("HK")) {
                         AppendPrefLang(tempPrefLangs, tempLen,
                                        eFontPrefLang_ChineseHK);
                     }
-                } else if (lang.EqualsLiteral("ko")) {
+                } else if (locale.GetLanguage().Equals("ko")) {
                     AppendPrefLang(tempPrefLangs, tempLen,
                                    eFontPrefLang_Korean);
                 }
             }
         }
 
         // last resort... (the order is same as old gfx.)
         AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);