platform/text/BidiContext.cpp
platform/text/Hyphenation.cpp
platform/text/LineEnding.cpp
+ platform/text/LocaleToScriptMappingDefault.cpp
platform/text/LocalizedDateNone.cpp
platform/text/LocalizedNumberNone.cpp
platform/text/QuotedPrintable.cpp
+2011-08-04 Matt Falkenhagen <falken@chromium.org>
+
+ Use -webkit-locale for font selection.
+ https://bugs.webkit.org/show_bug.cgi?id=10874
+
+ Reviewed by Dan Bernstein.
+
+ Infer a script from -webkit-locale to use to choose a font for generic
+ font families and the default unstyled font. The font is retrieved
+ from per-script font settings (see bug 20797). Since these settings
+ have not changed there should be no visible effect yet.
+
+ * CMakeLists.txt:
+ * GNUmakefile.list.am:
+ * WebCore.gyp/WebCore.gyp:
+ * WebCore.gypi:
+ * WebCore.pro:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * css/CSSFontSelector.cpp: Use script when getting font from Settings
+ (WebCore::fontDataForGenericFamily):
+ (WebCore::CSSFontSelector::getFontData):
+ * css/CSSPropertyNames.in: Increase priority of -webkit-locale since it affects font
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::styleForDocument):
+ (WebCore::CSSStyleSelector::applyDeclarations):
+ (WebCore::CSSStyleSelector::applyProperty): Set script in font based on -webkit-locale
+ * page/Settings.cpp:
+ (WebCore::getGenericFontFamilyForScript): Fallback to USCRIPT_COMMON
+ * platform/graphics/FontDescription.h: Add m_script
+ (WebCore::FontDescription::FontDescription):
+ (WebCore::FontDescription::script):
+ (WebCore::FontDescription::setScript):
+ (WebCore::FontDescription::operator==):
+ * platform/text/LocaleToScriptMapping.h: Added.
+ * platform/text/LocaleToScriptMappingDefault.cpp: Added.
+ (WebCore::localeToScriptCodeForFontSelection):
+ (WebCore::LocaleScript::if):
+ (WebCore::LocaleScript::while):
+ * platform/text/LocaleToScriptMappingICU.cpp: Added.
+ (WebCore::scriptCodeForFontSelection):
+ (WebCore::localeToScriptCodeForFontSelection):
+
2011-08-04 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Pretty print JSONP in network panel preview tab.
Source/WebCore/platform/text/LineBreakIteratorPoolICU.h \
Source/WebCore/platform/text/LineEnding.cpp \
Source/WebCore/platform/text/LineEnding.h \
+ Source/WebCore/platform/text/LocaleToScriptMapping.h \
+ Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp \
Source/WebCore/platform/text/LocalizedDate.h \
Source/WebCore/platform/text/LocalizedDateNone.cpp \
Source/WebCore/platform/text/LocalizedNumber.h \
['exclude', 'platform/image-encoders/PNGImageEncoder\\.(cpp|h)$'],
['exclude', 'platform/network/ResourceHandle\\.cpp$'],
['exclude', 'platform/sql/SQLiteFileSystem\\.cpp$'],
+ ['exclude', 'platform/text/LocaleToScriptMappingDefault\\.cpp$'],
['exclude', 'platform/text/LocalizedNumberNone\\.cpp$'],
['exclude', 'platform/text/TextEncodingDetectorNone\\.cpp$'],
],
'platform/text/Hyphenation.cpp',
'platform/text/Hyphenation.h',
'platform/text/LineEnding.cpp',
+ 'platform/text/LocaleToScriptMapping.h',
+ 'platform/text/LocaleToScriptMappingDefault.cpp',
+ 'platform/text/LocaleToScriptMappingICU.cpp',
'platform/text/LocalizedDate.h',
'platform/text/LocalizedDateNone.cpp',
'platform/text/LocalizedNumber.h',
platform/text/Base64.cpp \
platform/text/BidiContext.cpp \
platform/text/Hyphenation.cpp \
+ platform/text/LocaleToScriptMappingDefault.cpp \
platform/text/LocalizedDateNone.cpp \
platform/text/LocalizedNumberNone.cpp \
platform/text/QuotedPrintable.cpp \
platform/leveldb/LevelDBWriteBatch.h \
platform/text/BidiRunList.h \
platform/text/LineEnding.h \
+ platform/text/LocaleToScriptMapping.h \
platform/text/TextCheckerClient.h \
platform/text/TextChecking.h \
platform/text/UnicodeBidi.h \
RelativePath="..\platform\text\LineEnding.h"
>
</File>
+ <File
+ RelativePath="..\platform\text\LocaleToScriptMappingDefault.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\platform\text\LocaleToScriptMapping.h"
+ >
+ </File>
<File
RelativePath="..\platform\text\LocalizedDate.h"
>
75793ED40D0CE85B007FC0AC /* DOMMessageEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */; };
75793ED50D0CE85B007FC0AC /* DOMMessageEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */; };
758978EC127090D60076D5A9 /* SpeechInputResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 758978EA127090D60076D5A9 /* SpeechInputResult.cpp */; };
+ 7633A72613D8B33A008501B6 /* LocaleToScriptMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 7633A72413D8B33A008501B6 /* LocaleToScriptMapping.h */; };
+ 7633A72713D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7633A72513D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp */; };
7637C541112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7637C540112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp */; };
7637C543112E7B7E003D6CDC /* WebSocketHandshakeRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7637C542112E7B7E003D6CDC /* WebSocketHandshakeRequest.h */; };
767F99BE11A1194A0080C51D /* WebSocketHandshakeResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 767F99BD11A1194A0080C51D /* WebSocketHandshakeResponse.cpp */; };
75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEventInternal.h; sourceTree = "<group>"; };
758978EA127090D60076D5A9 /* SpeechInputResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpeechInputResult.cpp; sourceTree = "<group>"; };
758978EB127090D60076D5A9 /* SpeechInputResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeechInputResult.h; sourceTree = "<group>"; };
+ 7633A72413D8B33A008501B6 /* LocaleToScriptMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocaleToScriptMapping.h; sourceTree = "<group>"; };
+ 7633A72513D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocaleToScriptMappingDefault.cpp; sourceTree = "<group>"; };
7637C540112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketHandshakeRequest.cpp; sourceTree = "<group>"; };
7637C542112E7B7E003D6CDC /* WebSocketHandshakeRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketHandshakeRequest.h; sourceTree = "<group>"; };
767F99BD11A1194A0080C51D /* WebSocketHandshakeResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketHandshakeResponse.cpp; sourceTree = "<group>"; };
A5ABB78613B904BC00F197E3 /* LineBreakIteratorPoolICU.h */,
89B5EA9F11E8003D00F2367E /* LineEnding.cpp */,
89B5EAA011E8003D00F2367E /* LineEnding.h */,
+ 7633A72413D8B33A008501B6 /* LocaleToScriptMapping.h */,
+ 7633A72513D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp */,
A5732B0C136A16C4005C8D7C /* LocalizedDate.h */,
A5732B0E136A1715005C8D7C /* LocalizedDateNone.cpp */,
F5142C68123F12B000F5BD4C /* LocalizedNumber.h */,
7EE6846912D26E3800E79415 /* LoaderRunLoopCF.h in Headers */,
06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
89878568122CA064003AABDA /* LocalFileSystem.h in Headers */,
+ 7633A72613D8B33A008501B6 /* LocaleToScriptMapping.h in Headers */,
BC5CFCA911F793320099ED09 /* LocalizationStrategy.h in Headers */,
A5732B0D136A16C4005C8D7C /* LocalizedDate.h in Headers */,
F5142C69123F12B000F5BD4C /* LocalizedNumber.h in Headers */,
7EE6846812D26E3800E79415 /* LoaderRunLoopCF.cpp in Sources */,
06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */,
89878567122CA064003AABDA /* LocalFileSystem.cpp in Sources */,
+ 7633A72713D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp in Sources */,
A5732B0F136A1715005C8D7C /* LocalizedDateNone.cpp in Sources */,
F5CC42DC12F801CA00D5F7E3 /* LocalizedNumberMac.mm in Sources */,
C046E1AC1208A9FE00BA2CF7 /* LocalizedStrings.cpp in Sources */,
return 0;
AtomicString genericFamily;
+ UScriptCode script = fontDescription.script();
if (familyName == "-webkit-serif")
- genericFamily = settings->serifFontFamily();
+ genericFamily = settings->serifFontFamily(script);
else if (familyName == "-webkit-sans-serif")
- genericFamily = settings->sansSerifFontFamily();
+ genericFamily = settings->sansSerifFontFamily(script);
else if (familyName == "-webkit-cursive")
- genericFamily = settings->cursiveFontFamily();
+ genericFamily = settings->cursiveFontFamily(script);
else if (familyName == "-webkit-fantasy")
- genericFamily = settings->fantasyFontFamily();
+ genericFamily = settings->fantasyFontFamily(script);
else if (familyName == "-webkit-monospace")
- genericFamily = settings->fixedFontFamily();
+ genericFamily = settings->fixedFontFamily(script);
else if (familyName == "-webkit-pictograph")
- genericFamily = settings->pictographFontFamily();
+ genericFamily = settings->pictographFontFamily(script);
else if (familyName == "-webkit-standard")
- genericFamily = settings->standardFontFamily();
+ genericFamily = settings->standardFontFamily(script);
if (!genericFamily.isEmpty())
return fontCache()->getCachedFontData(fontDescription, genericFamily);
if (m_fontFaces.isEmpty()) {
if (familyName.startsWith("-webkit-"))
return fontDataForGenericFamily(m_document, fontDescription, familyName);
+ if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
+ return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard");
return 0;
}
if (!familyFontFaces || familyFontFaces->isEmpty()) {
// If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
// settings.
+ if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
+ return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard");
return fontDataForGenericFamily(m_document, fontDescription, familyName);
}
font-weight
text-rendering
-webkit-font-smoothing
+-webkit-locale
-webkit-text-orientation
-epub-text-orientation = -webkit-text-orientation
-webkit-text-size-adjust
-webkit-line-box-contain
-webkit-line-break
-webkit-line-clamp
--webkit-locale
-webkit-logical-width
-webkit-logical-height
-webkit-margin-after-collapse
#include "HTMLTextAreaElement.h"
#include "KeyframeList.h"
#include "LinkHash.h"
+#include "LocaleToScriptMapping.h"
#include "Matrix3DTransformOperation.h"
#include "MatrixTransformOperation.h"
#include "MediaList.h"
documentStyle->setForceBackgroundsToWhite(true);
const AtomicString& stdfont = settings->standardFontFamily();
if (!stdfont.isEmpty()) {
+ fontDescription.setGenericFamily(FontDescription::StandardFamily);
fontDescription.firstFamily().setFamily(stdfont);
fontDescription.firstFamily().appendFamily(0);
}
if (applyFirst) {
COMPILE_ASSERT(firstCSSProperty == CSSPropertyColor, CSS_color_is_first_property);
- COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 14, CSS_zoom_is_end_of_first_prop_range);
+ COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 15, CSS_zoom_is_end_of_first_prop_range);
COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyZoom + 1, CSS_line_height_is_after_zoom);
// give special priority to font-xxx, color properties, etc
m_style->setLocale(nullAtom);
else
m_style->setLocale(primitiveValue->getStringValue());
+ FontDescription fontDescription = m_style->fontDescription();
+ fontDescription.setScript(localeToScriptCodeForFontSelection(m_style->locale()));
+ if (m_style->setFontDescription(fontDescription))
+ m_fontDirty = true;
return;
}
case CSSPropertyWebkitBorderFit: {
ScriptFontFamilyMap::const_iterator it = fontMap.find(static_cast<int>(script));
if (it != fontMap.end())
return it->second;
+ if (script != USCRIPT_COMMON)
+ return getGenericFontFamilyForScript(fontMap, USCRIPT_COMMON);
return emptyAtom;
}
, m_fontSmoothing(AutoSmoothing)
, m_textRendering(AutoTextRendering)
, m_isSpecifiedFont(false)
+ , m_script(USCRIPT_COMMON)
{
}
unsigned keywordSize() const { return m_keywordSize; }
FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); }
TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
+ UScriptCode script() const { return m_script; }
FontTraitsMask traitsMask() const;
bool isSpecifiedFont() const { return m_isSpecifiedFont; }
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
void setTextOrientation(TextOrientation textOrientation) { m_textOrientation = textOrientation; }
void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; }
+ void setScript(UScriptCode s) { m_script = s; }
private:
FontFamily m_familyList; // The list of font families to be used.
unsigned m_fontSmoothing : 2; // FontSmoothingMode
unsigned m_textRendering : 2; // TextRenderingMode
bool m_isSpecifiedFont : 1; // True if a web page specifies a non-generic font family as the first font family.
+ UScriptCode m_script; // Used to help choose an appropriate font for generic font families.
};
inline bool FontDescription::operator==(const FontDescription& other) const
&& m_isSpecifiedFont == other.m_isSpecifiedFont
&& m_orientation == other.m_orientation
&& m_textOrientation == other.m_textOrientation
- && m_widthVariant == other.m_widthVariant;
+ && m_widthVariant == other.m_widthVariant
+ && m_script == other.m_script;
}
}
--- /dev/null
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LocaleToScriptMapping_h
+#define LocaleToScriptMapping_h
+
+#include <wtf/Forward.h>
+#include <wtf/unicode/Unicode.h>
+
+namespace WebCore {
+
+UScriptCode localeToScriptCodeForFontSelection(const String& locale);
+
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocaleToScriptMapping.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+UScriptCode localeToScriptCodeForFontSelection(const String& locale)
+{
+ struct LocaleScript {
+ const char* locale;
+ UScriptCode script;
+ };
+
+ // FIXME: Add all languages from ICU.
+ static const LocaleScript localeScriptList[] = {
+ { "ja", USCRIPT_KATAKANA_OR_HIRAGANA },
+ { "ko", USCRIPT_HANGUL },
+ { "ru", USCRIPT_CYRILLIC },
+ { "zh", USCRIPT_HAN },
+ { "zh_cn", USCRIPT_SIMPLIFIED_HAN },
+ { "zh_hans", USCRIPT_SIMPLIFIED_HAN },
+ { "zh_hant", USCRIPT_TRADITIONAL_HAN },
+ { "zh_hk", USCRIPT_TRADITIONAL_HAN },
+ { "zh_tw", USCRIPT_TRADITIONAL_HAN }
+ };
+
+ typedef HashMap<String, UScriptCode> LocaleScriptMap;
+ DEFINE_STATIC_LOCAL(LocaleScriptMap, localeScriptMap, ());
+ if (localeScriptMap.isEmpty()) {
+ for (size_t i = 0; i < sizeof(localeScriptList) / sizeof(localeScriptList[0]); ++i)
+ localeScriptMap.set(localeScriptList[i].locale, localeScriptList[i].script);
+ }
+
+ String canonicalLocale = locale.lower().replace('-', '_');
+ while (!canonicalLocale.isEmpty()) {
+ HashMap<String, UScriptCode>::iterator it = localeScriptMap.find(canonicalLocale);
+ if (it != localeScriptMap.end())
+ return it->second;
+ size_t pos = canonicalLocale.reverseFind('_');
+ if (pos == notFound)
+ break;
+ canonicalLocale = canonicalLocale.substring(0, pos);
+ }
+ return USCRIPT_COMMON;
+}
+
+} // namespace WebCore
--- /dev/null
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocaleToScriptMapping.h"
+
+#include <unicode/uloc.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// Treat certain families of script codes as a single script for assigning a per-script font in Settings.
+static UScriptCode scriptCodeForFontSelection(UScriptCode scriptCode)
+{
+ switch (scriptCode) {
+ case USCRIPT_HIRAGANA:
+ case USCRIPT_KATAKANA:
+ case USCRIPT_JAPANESE:
+ return USCRIPT_KATAKANA_OR_HIRAGANA;
+ case USCRIPT_KOREAN:
+ return USCRIPT_HANGUL;
+ default:
+ return scriptCode;
+ }
+}
+
+UScriptCode localeToScriptCodeForFontSelection(const String& locale)
+{
+ if (locale.isEmpty())
+ return USCRIPT_COMMON;
+
+ char maximizedLocale[ULOC_FULLNAME_CAPACITY];
+ UErrorCode status = U_ZERO_ERROR;
+ uloc_addLikelySubtags(locale.utf8().data(), maximizedLocale, sizeof(maximizedLocale), &status);
+ if (U_FAILURE(status))
+ return USCRIPT_COMMON;
+
+ char script[ULOC_SCRIPT_CAPACITY];
+ uloc_getScript(maximizedLocale, script, sizeof(script), &status);
+ if (U_FAILURE(status))
+ return USCRIPT_COMMON;
+
+ UScriptCode scriptCode;
+ uscript_getCode(script, &scriptCode, 1, &status);
+ // Ignore error that multiple scripts could be returned, since we only want one script.
+ if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
+ return USCRIPT_COMMON;
+
+ return scriptCodeForFontSelection(scriptCode);
+}
+
+} // namespace WebCore