Title: [92375] trunk/Source/WebCore
Revision
92375
Author
[email protected]
Date
2011-08-04 08:22:05 -0700 (Thu, 04 Aug 2011)

Log Message

Use -webkit-locale for font selection.
https://bugs.webkit.org/show_bug.cgi?id=10874

Patch by Matt Falkenhagen <[email protected]> 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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (92374 => 92375)


--- trunk/Source/WebCore/CMakeLists.txt	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/CMakeLists.txt	2011-08-04 15:22:05 UTC (rev 92375)
@@ -1154,6 +1154,7 @@
     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

Modified: trunk/Source/WebCore/ChangeLog (92374 => 92375)


--- trunk/Source/WebCore/ChangeLog	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/ChangeLog	2011-08-04 15:22:05 UTC (rev 92375)
@@ -1,3 +1,46 @@
+2011-08-04  Matt Falkenhagen  <[email protected]>
+
+        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  <[email protected]>
 
         Web Inspector: Pretty print JSONP in network panel preview tab.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (92374 => 92375)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-08-04 15:22:05 UTC (rev 92375)
@@ -2799,6 +2799,8 @@
 	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 \

Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (92374 => 92375)


--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -1340,6 +1340,7 @@
         ['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$'],
       ],

Modified: trunk/Source/WebCore/WebCore.gypi (92374 => 92375)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-04 15:22:05 UTC (rev 92375)
@@ -4363,6 +4363,9 @@
             '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',

Modified: trunk/Source/WebCore/WebCore.pro (92374 => 92375)


--- trunk/Source/WebCore/WebCore.pro	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/WebCore.pro	2011-08-04 15:22:05 UTC (rev 92375)
@@ -960,6 +960,7 @@
     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 @@
     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 \

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (92374 => 92375)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-04 15:22:05 UTC (rev 92375)
@@ -31565,6 +31565,14 @@
 					>
 				</File>
 				<File
+					RelativePath="..\platform\text\LocaleToScriptMappingDefault.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\platform\text\LocaleToScriptMapping.h"
+					>
+				</File>
+				<File
 					RelativePath="..\platform\text\LocalizedDate.h"
 					>
 				</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (92374 => 92375)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-08-04 15:22:05 UTC (rev 92375)
@@ -1720,6 +1720,8 @@
 		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 */; };
@@ -8347,6 +8349,8 @@
 		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>"; };
@@ -18300,6 +18304,8 @@
 				A5ABB78613B904BC00F197E3 /* LineBreakIteratorPoolICU.h */,
 				89B5EA9F11E8003D00F2367E /* LineEnding.cpp */,
 				89B5EAA011E8003D00F2367E /* LineEnding.h */,
+				7633A72413D8B33A008501B6 /* LocaleToScriptMapping.h */,
+				7633A72513D8B33A008501B6 /* LocaleToScriptMappingDefault.cpp */,
 				A5732B0C136A16C4005C8D7C /* LocalizedDate.h */,
 				A5732B0E136A1715005C8D7C /* LocalizedDateNone.cpp */,
 				F5142C68123F12B000F5BD4C /* LocalizedNumber.h */,
@@ -22288,6 +22294,7 @@
 				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 */,
@@ -25299,6 +25306,7 @@
 				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 */,

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (92374 => 92375)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -392,20 +392,21 @@
         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 @@
     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 @@
     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);
     }
 

Modified: trunk/Source/WebCore/css/CSSPropertyNames.in (92374 => 92375)


--- trunk/Source/WebCore/css/CSSPropertyNames.in	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/css/CSSPropertyNames.in	2011-08-04 15:22:05 UTC (rev 92375)
@@ -21,6 +21,7 @@
 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 @@
 -webkit-line-box-contain
 -webkit-line-break
 -webkit-line-clamp
--webkit-locale
 -webkit-logical-width
 -webkit-logical-height
 -webkit-margin-after-collapse

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (92374 => 92375)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -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 @@
             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 @@
 
                 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 @@
             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: {

Modified: trunk/Source/WebCore/page/Settings.cpp (92374 => 92375)


--- trunk/Source/WebCore/page/Settings.cpp	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/page/Settings.cpp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -66,6 +66,8 @@
     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;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/FontDescription.h (92374 => 92375)


--- trunk/Source/WebCore/platform/graphics/FontDescription.h	2011-08-04 15:04:20 UTC (rev 92374)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.h	2011-08-04 15:22:05 UTC (rev 92375)
@@ -83,6 +83,7 @@
         , m_fontSmoothing(AutoSmoothing)
         , m_textRendering(AutoTextRendering)
         , m_isSpecifiedFont(false)
+        , m_script(USCRIPT_COMMON)
     {
     }
 
@@ -108,6 +109,7 @@
     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 @@
     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 @@
     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 @@
         && 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;
 }
 
 }

Added: trunk/Source/WebCore/platform/text/LocaleToScriptMapping.h (0 => 92375)


--- trunk/Source/WebCore/platform/text/LocaleToScriptMapping.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocaleToScriptMapping.h	2011-08-04 15:22:05 UTC (rev 92375)
@@ -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

Added: trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp (0 => 92375)


--- trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocaleToScriptMappingDefault.cpp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -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

Added: trunk/Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp (0 => 92375)


--- trunk/Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocaleToScriptMappingICU.cpp	2011-08-04 15:22:05 UTC (rev 92375)
@@ -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
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to