Use -webkit-locale for font selection.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Aug 2011 15:22:05 +0000 (15:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Aug 2011 15:22:05 +0000 (15:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=10874

Patch by Matt Falkenhagen <falken@chromium.org> on 2011-08-04
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@92375 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gyp/WebCore.gyp
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/page/Settings.cpp
Source/WebCore/platform/graphics/FontDescription.h
Source/WebCore/platform/text/LocaleToScriptMapping.h [new file with mode: 0644]
Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp [new file with mode: 0644]
Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp [new file with mode: 0644]

index a16de093f753f7831b2029840290d52919269af4..d989dda0b42bf0d044d37e13eb164593411eded4 100644 (file)
@@ -1154,6 +1154,7 @@ SET(WebCore_SOURCES
     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
index 63a0247b10c0c547a62af5a1046de00c914c3c2a..86efdb23d5b41f10622f20213b122327b290d2a4 100644 (file)
@@ -1,3 +1,46 @@
+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.
index 4c835bff398c4920ad854347628ff8ce612c41dc..95c9f9af62cdb24e09d75f4af2f34d5162fa6b73 100644 (file)
@@ -2799,6 +2799,8 @@ webcore_sources += \
        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 \
index 4ee84d162dcd330cee1be28ccc50cc4260018fd6..eef41a9d12b7cb994be606843f9790dac07d89eb 100644 (file)
         ['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$'],
       ],
index 28f15451178790782325365976c5d168f3756abf..ed5cc8c89f0b4ee3be0db1c1e821faa68545f606 100644 (file)
             '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',
index 7a71fc63af8d8242a2bb0d2f0dd7583922999911..adf431f4243d0f765af5ffe8839c88b21f940fa9 100644 (file)
@@ -960,6 +960,7 @@ SOURCES += \
     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 \
@@ -2031,6 +2032,7 @@ HEADERS += \
     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 \
index 11faa33ffad958e15b80cbefd8feedd90b888b11..35dd6ef60c38d238b4e83bd947c97e6180960007 100755 (executable)
                                        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"
                                        >
index 4c37ad4dfcee6dc588b26cbf78fcea8be2779ffa..b40fd85a2c679dcc0b3e0b795431e37ef1293349 100644 (file)
                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 */,
index f2a41254f5062324de13947b7b2b24b669dbc141..0275c0cefaaf09ac694a006f15dbfaf7515876c9 100644 (file)
@@ -392,20 +392,21 @@ static FontData* fontDataForGenericFamily(Document* document, const FontDescript
         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);
@@ -500,6 +501,8 @@ FontData* CSSFontSelector::getFontData(const FontDescription& fontDescription, c
     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;
     }
 
@@ -510,6 +513,8 @@ FontData* CSSFontSelector::getFontData(const FontDescription& fontDescription, c
     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);
     }
 
index 9c20f7fcf251c12d8b075d0b1e51e583968e77d1..d2d1e008d7f0208deddd8e175990aa596c5e84fb 100644 (file)
@@ -21,6 +21,7 @@ font-variant
 font-weight
 text-rendering
 -webkit-font-smoothing
+-webkit-locale
 -webkit-text-orientation
 -epub-text-orientation = -webkit-text-orientation
 -webkit-text-size-adjust
@@ -250,7 +251,6 @@ z-index
 -webkit-line-box-contain
 -webkit-line-break
 -webkit-line-clamp
--webkit-locale
 -webkit-logical-width
 -webkit-logical-height
 -webkit-margin-after-collapse
index da066f930790536a65cabb6589f5db2d83ac64f4..4bdb42670080e100c3786b801f14cea9880e51ed 100644 (file)
@@ -69,6 +69,7 @@
 #include "HTMLTextAreaElement.h"
 #include "KeyframeList.h"
 #include "LinkHash.h"
+#include "LocaleToScriptMapping.h"
 #include "Matrix3DTransformOperation.h"
 #include "MatrixTransformOperation.h"
 #include "MediaList.h"
@@ -1283,6 +1284,7 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document)
             documentStyle->setForceBackgroundsToWhite(true);
         const AtomicString& stdfont = settings->standardFontFamily();
         if (!stdfont.isEmpty()) {
+            fontDescription.setGenericFamily(FontDescription::StandardFamily);
             fontDescription.firstFamily().setFamily(stdfont);
             fontDescription.firstFamily().appendFamily(0);
         }
@@ -3479,7 +3481,7 @@ void CSSStyleSelector::applyDeclarations(bool isImportant, int startIndex, int e
 
                 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
@@ -4779,6 +4781,10 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             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: {
index c40b7ada81be612e8b3abf782af1393e829f0ae8..e3f0359f378759192a91a944487db2478eb507ef 100644 (file)
@@ -66,6 +66,8 @@ static inline const AtomicString& getGenericFontFamilyForScript(const ScriptFont
     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;
 }
 
index 5d53388ddcb2583e1fe9642086e50e8da242ac9b..dd3cf3a9b08a0c282770e81594dc38f5095d9d45 100644 (file)
@@ -83,6 +83,7 @@ public:
         , m_fontSmoothing(AutoSmoothing)
         , m_textRendering(AutoTextRendering)
         , m_isSpecifiedFont(false)
+        , m_script(USCRIPT_COMMON)
     {
     }
 
@@ -108,6 +109,7 @@ public:
     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; }
@@ -138,6 +140,7 @@ public:
     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.
@@ -168,6 +171,7 @@ private:
     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
@@ -188,7 +192,8 @@ 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;
 }
 
 }
diff --git a/Source/WebCore/platform/text/LocaleToScriptMapping.h b/Source/WebCore/platform/text/LocaleToScriptMapping.h
new file mode 100644 (file)
index 0000000..0cedb59
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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
diff --git a/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp b/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp
new file mode 100644 (file)
index 0000000..f6c1125
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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
diff --git a/Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp b/Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp
new file mode 100644 (file)
index 0000000..9977075
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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