[HarfBuzz] Decomposed Vietnamese characters are rendered incorrectly
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Aug 2017 16:36:35 +0000 (16:36 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Aug 2017 16:36:35 +0000 (16:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174418

Patch by Fujii Hironori <Hironori.Fujii@sony.com> on 2017-08-16
Reviewed by Michael Catanzaro.

Source/WebCore:

HarfBuzzShaper should normalize the input text before collecting
HarfBuzzRuns. Actually, HarfBuzzShaper::setNormalizedBuffer does
the task. But, this function hasn't been called from anywhere
since Bug 90951.

Test: fast/text/international/vietnamese-nfd.html
      imported/blink/fast/text/international/text-shaping-arabic-diffs.html

* platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
(WebCore::HarfBuzzShaper::HarfBuzzShaper):
Call setNormalizedBuffer instead of normalizeCharacters.
(WebCore::normalizeCharacters): Deleted.
(WebCore::normalizeSpacesAndMirrorChars) Use
FontCascade::treatAsZeroWidthSpaceInComplexScript instead of
FontCascade::treatAsZeroWidthSpace to preserve ZWJ and ZWNJ.

LayoutTests:

* fast/text/international/vietnamese-nfd-expected.html: Added.
* fast/text/international/vietnamese-nfd.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/international/vietnamese-nfd-expected.html [new file with mode: 0644]
LayoutTests/fast/text/international/vietnamese-nfd.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp

index 3ed2669..6c37180 100644 (file)
@@ -1,3 +1,13 @@
+2017-08-16  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [HarfBuzz] Decomposed Vietnamese characters are rendered incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=174418
+
+        Reviewed by Michael Catanzaro.
+
+        * fast/text/international/vietnamese-nfd-expected.html: Added.
+        * fast/text/international/vietnamese-nfd.html: Added.
+
 2017-08-16  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, rebaseline a few tests after r220779.
diff --git a/LayoutTests/fast/text/international/vietnamese-nfd-expected.html b/LayoutTests/fast/text/international/vietnamese-nfd-expected.html
new file mode 100644 (file)
index 0000000..90497d9
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<meta charset="utf-8">
+<style>
+ body {
+     font-size: 30px;
+     font-family: Helvetica, sans;
+ }
+</style>
+<body>
+    ã ẫ ẵ ẽ ễ ĩ õ ỗ ỡ ũ ữ ỹ<br>
+    ạ ậ ặ ẹ ệ ị ọ ộ ợ ụ ự ỵ<br>
+    ả ẩ ẳ ẻ ể ỉ ỏ ổ ở ủ ử ỷ<br>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/international/vietnamese-nfd.html b/LayoutTests/fast/text/international/vietnamese-nfd.html
new file mode 100644 (file)
index 0000000..9070f33
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<meta charset="utf-8">
+<style>
+ body {
+     font-size: 30px;
+     font-family: Helvetica, sans;
+ }
+</style>
+<body>
+    ã ẫ ẵ ẽ ễ ĩ õ ỗ ỡ ũ ữ ỹ<br>
+    ạ ậ ặ ẹ ệ ị ọ ộ ợ ụ ự ỵ<br>
+    ả ẩ ẳ ẻ ể ỉ ỏ ổ ở ủ ử ỷ<br>
+</body>
+</html>
index 88c7a04..797ca37 100644 (file)
@@ -1,3 +1,26 @@
+2017-08-16  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        [HarfBuzz] Decomposed Vietnamese characters are rendered incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=174418
+
+        Reviewed by Michael Catanzaro.
+
+        HarfBuzzShaper should normalize the input text before collecting
+        HarfBuzzRuns. Actually, HarfBuzzShaper::setNormalizedBuffer does
+        the task. But, this function hasn't been called from anywhere
+        since Bug 90951.
+
+        Test: fast/text/international/vietnamese-nfd.html
+              imported/blink/fast/text/international/text-shaping-arabic-diffs.html
+
+        * platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
+        (WebCore::HarfBuzzShaper::HarfBuzzShaper):
+        Call setNormalizedBuffer instead of normalizeCharacters.
+        (WebCore::normalizeCharacters): Deleted.
+        (WebCore::normalizeSpacesAndMirrorChars) Use
+        FontCascade::treatAsZeroWidthSpaceInComplexScript instead of
+        FontCascade::treatAsZeroWidthSpace to preserve ZWJ and ZWNJ.
+
 2017-08-16  Antti Koivisto  <antti@apple.com>
 
         Move first-letter renderer mutation code out of RenderBlock and into RenderTreeUpdater
index 9e6f448..bf33707 100644 (file)
@@ -160,33 +160,6 @@ float HarfBuzzShaper::HarfBuzzRun::xPositionForOffset(unsigned offset)
     return position;
 }
 
-static void normalizeCharacters(const TextRun& run, UChar* destination, unsigned length)
-{
-    unsigned position = 0;
-    bool error = false;
-    const UChar* source;
-    String stringFor8BitRun;
-    if (run.is8Bit()) {
-        stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), run.length());
-        source = stringFor8BitRun.characters16();
-    } else
-        source = run.characters16();
-
-    while (position < length) {
-        UChar32 character;
-        unsigned nextPosition = position;
-        U16_NEXT(source, nextPosition, length, character);
-        // Don't normalize tabs as they are not treated as spaces for word-end.
-        if (FontCascade::treatAsSpace(character) && character != '\t')
-            character = ' ';
-        else if (FontCascade::treatAsZeroWidthSpaceInComplexScript(character))
-            character = zeroWidthSpace;
-        U16_APPEND(destination, position, length, character, error);
-        ASSERT_UNUSED(error, !error);
-        position = nextPosition;
-    }
-}
-
 HarfBuzzShaper::HarfBuzzShaper(const FontCascade* font, const TextRun& run)
     : m_font(font)
     , m_normalizedBufferLength(0)
@@ -197,9 +170,7 @@ HarfBuzzShaper::HarfBuzzShaper(const FontCascade* font, const TextRun& run)
     , m_padError(0)
     , m_letterSpacing(font->letterSpacing())
 {
-    m_normalizedBuffer = std::make_unique<UChar[]>(m_run.length() + 1);
-    m_normalizedBufferLength = m_run.length();
-    normalizeCharacters(m_run, m_normalizedBuffer.get(), m_normalizedBufferLength);
+    setNormalizedBuffer();
     setPadding(m_run.expansion());
     setFontFeatures();
 }
@@ -220,7 +191,7 @@ static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destinatio
         // Don't normalize tabs as they are not treated as spaces for word-end
         if (FontCascade::treatAsSpace(character) && character != '\t')
             character = ' ';
-        else if (FontCascade::treatAsZeroWidthSpace(character))
+        else if (FontCascade::treatAsZeroWidthSpaceInComplexScript(character))
             character = zeroWidthSpace;
         else if (normalizeMode == HarfBuzzShaper::NormalizeMirrorChars)
             character = u_charMirror(character);