Title: [195266] releases/WebKitGTK/webkit-2.10
Revision
195266
Author
[email protected]
Date
2016-01-19 01:00:42 -0800 (Tue, 19 Jan 2016)

Log Message

Merge r195058 - [GTK] [EFL] Hyphenation can never work in practice due to requirements on lang tags
https://bugs.webkit.org/show_bug.cgi?id=147310

Patch by Martin Robinson <[email protected]> on 2016-01-14
Reviewed by Michael Catanzaro.

Source/WebCore:

Test: platform/gtk/fast/text/hyphenate-flexible-locales.html

* platform/text/hyphen/HyphenationLibHyphen.cpp: Make locale matching for dictionary
selection a lot looser by matching case insensitively, matching multiple dictionaries
when only the language is specified, and ignoring the difference between '_' and '-' in
the locale name.
(WebCore::scanDirectoryForDicionaries): Now produce HashMap of Vectors instead of a single
path for each locale. Also add alternate entries to handle different ways of specifying
the locale.
(WebCore::scanTestDictionariesDirectoryIfNecessary): Update to handle the difference
in HashMap type.
(WebCore::availableLocales): Ditto.
(WebCore::canHyphenate): Also look for the lowercased version of the locale.
(WebCore::AtomicStringKeyedMRUCache<RefPtr<HyphenationDictionary>>::createValueForKey):
Key on the dictionary path now so that we can load more than one dictionary per locale.
(WebCore::lastHyphenLocation): Iterate through each matched dictionary in turn.

LayoutTests:

Update some baselines and add a GTK+ specific test for locale variations.

* platform/gtk/fast/text/hyphenate-flexible-locales-expected.html: Added.
* platform/gtk/fast/text/hyphenate-flexible-locales.html: Added.
* platform/gtk/fast/text/hyphenate-locale-expected.png: We now properly hyphenate
text with the 'en' locale.
* platform/gtk/fast/text/hyphenate-locale-expected.txt:

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog (195265 => 195266)


--- releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog	2016-01-19 08:59:16 UTC (rev 195265)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog	2016-01-19 09:00:42 UTC (rev 195266)
@@ -1,3 +1,18 @@
+2016-01-14  Martin Robinson  <[email protected]>
+
+        [GTK] [EFL] Hyphenation can never work in practice due to requirements on lang tags
+        https://bugs.webkit.org/show_bug.cgi?id=147310
+
+        Reviewed by Michael Catanzaro.
+
+        Update some baselines and add a GTK+ specific test for locale variations.
+
+        * platform/gtk/fast/text/hyphenate-flexible-locales-expected.html: Added.
+        * platform/gtk/fast/text/hyphenate-flexible-locales.html: Added.
+        * platform/gtk/fast/text/hyphenate-locale-expected.png: We now properly hyphenate
+        text with the 'en' locale.
+        * platform/gtk/fast/text/hyphenate-locale-expected.txt:
+
 2016-01-14  Youenn Fablet  <[email protected]>
 
         Fix problems with cross-origin redirects

Added: releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales-expected.html (0 => 195266)


--- releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales-expected.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales-expected.html	2016-01-19 09:00:42 UTC (rev 195266)
@@ -0,0 +1,11 @@
+<div style="-webkit-hyphens: auto; font-size: 36px; width: 130px;">
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+</div>

Added: releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales.html (0 => 195266)


--- releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-flexible-locales.html	2016-01-19 09:00:42 UTC (rev 195266)
@@ -0,0 +1,11 @@
+<div style="-webkit-hyphens: auto; font-size: 36px; width: 130px;">
+    <div style="-webkit-locale: 'en';">throughout</div>
+    <div style="-webkit-locale: 'en_US';">throughout</div>
+    <div style="-webkit-locale: 'en-US';">throughout</div>
+    <div style="-webkit-locale: 'en';">throughout</div>
+    <div style="-webkit-locale: 'en_us';">throughout</div>
+    <div style="-webkit-locale: 'en-us';">throughout</div>
+    <div style="-webkit-locale: 'EN';">throughout</div>
+    <div style="-webkit-locale: 'EN_US';">throughout</div>
+    <div style="-webkit-locale: 'EN-US';">throughout</div>
+</div>

Modified: releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-locale-expected.png


(Binary files differ)

Modified: releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-locale-expected.txt (195265 => 195266)


--- releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-locale-expected.txt	2016-01-19 08:59:16 UTC (rev 195265)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/platform/gtk/fast/text/hyphenate-locale-expected.txt	2016-01-19 09:00:42 UTC (rev 195266)
@@ -1,40 +1,42 @@
-layer at (0,0) size 800x600
-  RenderView at (0,0) size 800x600
-layer at (0,0) size 800x600
-  RenderBlock {HTML} at (0,0) size 800x600
-    RenderBody {BODY} at (8,8) size 784x584
-      RenderBlock {DIV} at (0,0) size 130x240
+layer at (0,0) size 785x616
+  RenderView at (0,0) size 785x600
+layer at (0,0) size 785x616
+  RenderBlock {HTML} at (0,0) size 785x616
+    RenderBody {BODY} at (8,8) size 769x600
+      RenderBlock {DIV} at (0,0) size 130x280
         RenderBlock {DIV} at (0,0) size 130x40
           RenderText {#text} at (0,0) size 158x40
             text run at (0,0) width 158: "throughout"
-        RenderBlock {DIV} at (0,40) size 130x40
-          RenderText {#text} at (0,0) size 158x40
-            text run at (0,0) width 158: "throughout"
-        RenderBlock {DIV} at (0,80) size 130x80
+        RenderBlock {DIV} at (0,40) size 130x80
           RenderText {#text} at (0,0) size 106x80
             text run at (0,0) width 106: "throug" + hyphen string "\x{2010}"
             text run at (0,40) width 64: "hout"
-        RenderBlock {DIV} at (0,160) size 130x40
+        RenderBlock {DIV} at (0,120) size 130x80
+          RenderText {#text} at (0,0) size 106x80
+            text run at (0,0) width 106: "throug" + hyphen string "\x{2010}"
+            text run at (0,40) width 64: "hout"
+        RenderBlock {DIV} at (0,200) size 130x40
           RenderText {#text} at (0,0) size 158x40
             text run at (0,0) width 158: "throughout"
-        RenderBlock {DIV} at (0,200) size 130x40
+        RenderBlock {DIV} at (0,240) size 130x40
           RenderText {#text} at (0,0) size 158x40
             text run at (0,0) width 158: "throughout"
-      RenderBlock {DIV} at (0,240) size 135x280
+      RenderBlock {DIV} at (0,280) size 135x320
         RenderBlock {DIV} at (0,0) size 135x40
           RenderText {#text} at (0,0) size 156x40
             text run at (0,0) width 156: "reciprocity"
-        RenderBlock {DIV} at (0,40) size 135x40
-          RenderText {#text} at (0,0) size 156x40
-            text run at (0,0) width 156: "reciprocity"
-        RenderBlock {DIV} at (0,80) size 135x80
+        RenderBlock {DIV} at (0,40) size 135x80
           RenderText {#text} at (0,0) size 114x80
             text run at (0,0) width 114: "recipro" + hyphen string "\x{2010}"
             text run at (0,40) width 54: "city"
-        RenderBlock {DIV} at (0,160) size 135x80
+        RenderBlock {DIV} at (0,120) size 135x80
+          RenderText {#text} at (0,0) size 114x80
+            text run at (0,0) width 114: "recipro" + hyphen string "\x{2010}"
+            text run at (0,40) width 54: "city"
+        RenderBlock {DIV} at (0,200) size 135x80
           RenderText {#text} at (0,0) size 96x80
             text run at (0,0) width 96: "recipr" + hyphen string "\x{2010}"
             text run at (0,40) width 72: "ocity"
-        RenderBlock {DIV} at (0,240) size 135x40
+        RenderBlock {DIV} at (0,280) size 135x40
           RenderText {#text} at (0,0) size 156x40
             text run at (0,0) width 156: "reciprocity"

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog (195265 => 195266)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2016-01-19 08:59:16 UTC (rev 195265)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2016-01-19 09:00:42 UTC (rev 195266)
@@ -1,3 +1,27 @@
+2016-01-14  Martin Robinson  <[email protected]>
+
+        [GTK] [EFL] Hyphenation can never work in practice due to requirements on lang tags
+        https://bugs.webkit.org/show_bug.cgi?id=147310
+
+        Reviewed by Michael Catanzaro.
+
+        Test: platform/gtk/fast/text/hyphenate-flexible-locales.html
+
+        * platform/text/hyphen/HyphenationLibHyphen.cpp: Make locale matching for dictionary
+        selection a lot looser by matching case insensitively, matching multiple dictionaries
+        when only the language is specified, and ignoring the difference between '_' and '-' in
+        the locale name.
+        (WebCore::scanDirectoryForDicionaries): Now produce HashMap of Vectors instead of a single
+        path for each locale. Also add alternate entries to handle different ways of specifying
+        the locale.
+        (WebCore::scanTestDictionariesDirectoryIfNecessary): Update to handle the difference
+        in HashMap type.
+        (WebCore::availableLocales): Ditto.
+        (WebCore::canHyphenate): Also look for the lowercased version of the locale.
+        (WebCore::AtomicStringKeyedMRUCache<RefPtr<HyphenationDictionary>>::createValueForKey):
+        Key on the dictionary path now so that we can load more than one dictionary per locale.
+        (WebCore::lastHyphenLocation): Iterate through each matched dictionary in turn.
+
 2016-01-14  Youenn Fablet  <[email protected]>
 
         Fix problems with cross-origin redirects

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp (195265 => 195266)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2016-01-19 08:59:16 UTC (rev 195265)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2016-01-19 09:00:42 UTC (rev 195266)
@@ -60,14 +60,27 @@
     return fileName.substring(prefixLength, fileName.length() - prefixLength - suffixLength);
 }
 
-static void scanDirectoryForDicionaries(const char* directoryPath, HashMap<AtomicString, String>& availableLocales)
+static void scanDirectoryForDicionaries(const char* directoryPath, HashMap<AtomicString, Vector<String>>& availableLocales)
 {
-    for (const auto& filePath : listDirectory(directoryPath, "hyph_*.dic"))
-        availableLocales.set(AtomicString(extractLocaleFromDictionaryFilePath(filePath)), filePath);
+    for (const auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
+        String locale = extractLocaleFromDictionaryFilePath(filePath).convertToASCIILowercase();
+        availableLocales.add(locale, Vector<String>()).iterator->value.append(filePath);
+
+        String localeReplacingUnderscores = String(locale);
+        localeReplacingUnderscores.replace('_', '-');
+        if (locale != localeReplacingUnderscores)
+            availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
+
+        size_t dividerPosition = localeReplacingUnderscores.find('-');
+        if (dividerPosition != notFound) {
+            localeReplacingUnderscores.truncate(dividerPosition);
+            availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
+        }
+    }
 }
 
 #if ENABLE(DEVELOPER_MODE)
-static void scanTestDictionariesDirectoryIfNecessary(HashMap<AtomicString, String>& availableLocales)
+static void scanTestDictionariesDirectoryIfNecessary(HashMap<AtomicString, Vector<String>>& availableLocales)
 {
     // It's unfortunate that we need to look for the dictionaries this way, but
     // libhyphen doesn't have the concept of installed dictionaries. Instead,
@@ -89,10 +102,10 @@
 }
 #endif
 
-static HashMap<AtomicString, String>& availableLocales()
+static HashMap<AtomicString, Vector<String>>& availableLocales()
 {
     static bool scannedLocales = false;
-    static HashMap<AtomicString, String> availableLocales;
+    static HashMap<AtomicString, Vector<String>> availableLocales;
 
     if (!scannedLocales) {
         for (size_t i = 0; i < WTF_ARRAY_LENGTH(gDictionaryDirectories); i++)
@@ -112,7 +125,9 @@
 {
     if (localeIdentifier.isNull())
         return false;
-    return availableLocales().contains(localeIdentifier);
+    if (availableLocales().contains(localeIdentifier))
+        return true;
+    return availableLocales().contains(AtomicString(localeIdentifier.string().convertToASCIILowercase()));
 }
 
 class HyphenationDictionary : public RefCounted<HyphenationDictionary> {
@@ -158,10 +173,9 @@
 }
 
 template<>
-RefPtr<HyphenationDictionary> AtomicStringKeyedMRUCache<RefPtr<HyphenationDictionary>>::createValueForKey(const AtomicString& localeIdentifier)
+RefPtr<HyphenationDictionary> AtomicStringKeyedMRUCache<RefPtr<HyphenationDictionary>>::createValueForKey(const AtomicString& dictionaryPath)
 {
-    ASSERT(availableLocales().get(localeIdentifier));
-    return HyphenationDictionary::create(fileSystemRepresentation(availableLocales().get(localeIdentifier)));
+    return HyphenationDictionary::create(fileSystemRepresentation(dictionaryPath.string()));
 }
 
 static AtomicStringKeyedMRUCache<RefPtr<HyphenationDictionary>>& hyphenDictionaryCache()
@@ -190,9 +204,6 @@
 
 size_t lastHyphenLocation(StringView string, size_t beforeIndex, const AtomicString& localeIdentifier)
 {
-    ASSERT(availableLocales().contains(localeIdentifier));
-    RefPtr<HyphenationDictionary> dictionary = hyphenDictionaryCache().get(localeIdentifier);
-
     // libhyphen accepts strings in UTF-8 format, but WebCore can only provide StringView
     // which stores either UTF-16 or Latin1 data. This is unfortunate for performance
     // reasons and we should consider switching to a more flexible hyphenation library
@@ -211,32 +222,38 @@
     Vector<char> hyphenArray(utf8StringCopy.length() - leadingSpaceBytes + 5);
     char* hyphenArrayData = hyphenArray.data();
 
-    char** replacements = nullptr;
-    int* positions = nullptr;
-    int* removedCharacterCounts = nullptr;
-    hnj_hyphen_hyphenate2(dictionary->libhyphenDictionary(),
-        utf8StringCopy.data() + leadingSpaceBytes,
-        utf8StringCopy.length() - leadingSpaceBytes,
-        hyphenArrayData,
-        nullptr, /* output parameter for hyphenated word */
-        &replacements,
-        &positions,
-        &removedCharacterCounts);
+    String lowercaseLocaleIdentifier = AtomicString(localeIdentifier.string().convertToASCIILowercase());
+    ASSERT(availableLocales().contains(lowercaseLocaleIdentifier));
+    for (const auto& dictionaryPath : availableLocales().get(lowercaseLocaleIdentifier)) {
+        RefPtr<HyphenationDictionary> dictionary = hyphenDictionaryCache().get(AtomicString(dictionaryPath));
 
-    if (replacements) {
-        for (unsigned i = 0; i < utf8StringCopy.length() - leadingSpaceBytes - 1; i++)
-            free(replacements[i]);
-        free(replacements);
-    }
+        char** replacements = nullptr;
+        int* positions = nullptr;
+        int* removedCharacterCounts = nullptr;
+        hnj_hyphen_hyphenate2(dictionary->libhyphenDictionary(),
+            utf8StringCopy.data() + leadingSpaceBytes,
+            utf8StringCopy.length() - leadingSpaceBytes,
+            hyphenArrayData,
+            nullptr, /* output parameter for hyphenated word */
+            &replacements,
+            &positions,
+            &removedCharacterCounts);
 
-    free(positions);
-    free(removedCharacterCounts);
+        if (replacements) {
+            for (unsigned i = 0; i < utf8StringCopy.length() - leadingSpaceBytes - 1; i++)
+                free(replacements[i]);
+            free(replacements);
+        }
 
-    for (int i = beforeIndex - leadingSpaceCharacters - 1; i >= 0; i--) {
-        // libhyphen will put an odd number in hyphenArrayData at all
-        // hyphenation points. A number & 1 will be true for odd numbers.
-        if (hyphenArrayData[i] & 1)
-            return i + leadingSpaceCharacters;
+        free(positions);
+        free(removedCharacterCounts);
+
+        for (int i = beforeIndex - leadingSpaceCharacters - 1; i >= 0; i--) {
+            // libhyphen will put an odd number in hyphenArrayData at all
+            // hyphenation points. A number & 1 will be true for odd numbers.
+            if (hyphenArrayData[i] & 1)
+                return i + leadingSpaceCharacters;
+        }
     }
 
     return 0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to