Simple line layout: Extend coverage for justified content.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jan 2017 02:52:34 +0000 (02:52 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jan 2017 02:52:34 +0000 (02:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167219
<rdar://problem/30108391>

Reviewed by Antti Koivisto.

Source/WebCore:

Add support for general punctuation characters (0x2010, 0x2027) and latin characters including Extended-B.

Test: fast/text/simple-line-layout-with-justified-punctuation.html

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForText):
(WebCore::SimpleLineLayout::canUseForFontAndText):

LayoutTests:

* fast/text/simple-line-layout-with-justified-punctuation-expected.html: Added.
* fast/text/simple-line-layout-with-justified-punctuation.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/simple-line-layout-with-justified-punctuation-expected.html [new file with mode: 0644]
LayoutTests/fast/text/simple-line-layout-with-justified-punctuation.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayout.cpp

index 95e1318..05f76a3 100644 (file)
@@ -1,3 +1,14 @@
+2017-01-19  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Extend coverage for justified content.
+        https://bugs.webkit.org/show_bug.cgi?id=167219
+        <rdar://problem/30108391>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/simple-line-layout-with-justified-punctuation-expected.html: Added.
+        * fast/text/simple-line-layout-with-justified-punctuation.html: Added.
+
 2017-01-19  Jer Noble  <jer.noble@apple.com>
 
         CRASH at WebCore::TrackListBase::remove
diff --git a/LayoutTests/fast/text/simple-line-layout-with-justified-punctuation-expected.html b/LayoutTests/fast/text/simple-line-layout-with-justified-punctuation-expected.html
new file mode 100644 (file)
index 0000000..44f7a8c
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>This tests that we renderer justified punctuation content correctly with simple line layout</title>
+<style>
+div {
+    text-align: justify;
+    width: 200px;
+}
+</style>
+<script>
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+</head>
+<body>
+<div>foobar &#x2010; foobar &#x2011; foobar &#x2012; foobar &#x2013;</div>
+<div>foobar &#x2014; foobar &#x2015; foobar &#x2016; foobar &#x2017;</div>
+<div>foobar &#x2018; foobar &#x2019; foobar &#x201A; foobar &#x201B;</div>
+<div>foobar &#x201C; foobar &#x201D; foobar &#x201E; foobar &#x201F;</div>
+<div>foobar &#x2020; foobar &#x2021; foobar &#x2022; foobar &#x2023;</div>
+<div>foobar &#x2024; foobar &#x2025; foobar &#x2026; foobar &#x2027;</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/simple-line-layout-with-justified-punctuation.html b/LayoutTests/fast/text/simple-line-layout-with-justified-punctuation.html
new file mode 100644 (file)
index 0000000..e9c778a
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>This tests that we renderer justified punctuation content correctly with simple line layout</title>
+<style>
+div {
+    text-align: justify;
+    width: 200px;
+} 
+</style>
+</head>
+<body>
+<div>foobar &#x2010; foobar &#x2011; foobar &#x2012; foobar &#x2013;</div>
+<div>foobar &#x2014; foobar &#x2015; foobar &#x2016; foobar &#x2017;</div>
+<div>foobar &#x2018; foobar &#x2019; foobar &#x201A; foobar &#x201B;</div>
+<div>foobar &#x201C; foobar &#x201D; foobar &#x201E; foobar &#x201F;</div>
+<div>foobar &#x2020; foobar &#x2021; foobar &#x2022; foobar &#x2023;</div>
+<div>foobar &#x2024; foobar &#x2025; foobar &#x2026; foobar &#x2027;</div>
+</body>
+</html>
index b729044..94330e6 100644 (file)
@@ -1,3 +1,19 @@
+2017-01-19  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Extend coverage for justified content.
+        https://bugs.webkit.org/show_bug.cgi?id=167219
+        <rdar://problem/30108391>
+
+        Reviewed by Antti Koivisto.
+
+        Add support for general punctuation characters (0x2010, 0x2027) and latin characters including Extended-B.
+
+        Test: fast/text/simple-line-layout-with-justified-punctuation.html
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForText):
+        (WebCore::SimpleLineLayout::canUseForFontAndText):
+
 2017-01-19  Alex Christensen  <achristensen@webkit.org>
 
         Construct URLSearchParams from array or object
index eb45013..98488b1 100644 (file)
@@ -136,7 +136,7 @@ enum class IncludeReasons { First , All };
 #endif
 
 template <typename CharacterType>
-static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned length, const Font& font, IncludeReasons includeReasons)
+static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned length, const Font& font, bool textIsJustified, IncludeReasons includeReasons)
 {
     AvoidanceReasonFlags reasons = { };
     // FIXME: <textarea maxlength=0> generates empty text node.
@@ -148,6 +148,14 @@ static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned le
         if (character == ' ')
             continue;
 
+        if (textIsJustified) {
+            // Include characters up to Latin Extended-B and some punctuation range when text is justified.
+            bool isLatinIncludingExtendedB = character <= 0x01FF;
+            bool isPunctuationRange = character >= 0x2010 && character <= 0x2027;
+            if (!(isLatinIncludingExtendedB || isPunctuationRange))
+                SET_REASON_AND_RETURN_IF_NEEDED(FlowHasJustifiedNonLatinText, reasons, includeReasons);
+        }
+
         // These would be easy to support.
         if (character == noBreakSpace)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasNoBreakSpace, reasons, includeReasons);
@@ -167,11 +175,11 @@ static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned le
     return reasons;
 }
 
-static AvoidanceReasonFlags canUseForText(const RenderText& textRenderer, const Font& font, IncludeReasons includeReasons)
+static AvoidanceReasonFlags canUseForText(const RenderText& textRenderer, const Font& font, bool textIsJustified, IncludeReasons includeReasons)
 {
     if (textRenderer.is8Bit())
-        return canUseForText(textRenderer.characters8(), textRenderer.textLength(), font, includeReasons);
-    return canUseForText(textRenderer.characters16(), textRenderer.textLength(), font, includeReasons);
+        return canUseForText(textRenderer.characters8(), textRenderer.textLength(), font, false, includeReasons);
+    return canUseForText(textRenderer.characters16(), textRenderer.textLength(), font, textIsJustified, includeReasons);
 }
 
 static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& flow, IncludeReasons includeReasons)
@@ -183,9 +191,8 @@ static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& flow, In
     if (primaryFont.isLoading())
         SET_REASON_AND_RETURN_IF_NEEDED(FlowIsMissingPrimaryFont, reasons, includeReasons);
 
+    bool flowIsJustified = style.textAlign() == JUSTIFY;
     for (const auto& textRenderer : childrenOfType<RenderText>(flow)) {
-        if (style.textAlign() == JUSTIFY && !textRenderer.originalText().containsOnlyLatin1())
-            SET_REASON_AND_RETURN_IF_NEEDED(FlowHasJustifiedNonLatinText, reasons, includeReasons);
         if (textRenderer.isCombineText())
             SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsCombineText, reasons, includeReasons);
         if (textRenderer.isCounter())
@@ -199,7 +206,7 @@ static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& flow, In
         if (style.fontCascade().codePath(TextRun(textRenderer.text())) != FontCascade::Simple)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowFontIsNotSimple, reasons, includeReasons);
 
-        auto textReasons = canUseForText(textRenderer, primaryFont, includeReasons);
+        auto textReasons = canUseForText(textRenderer, primaryFont, flowIsJustified, includeReasons);
         if (textReasons != NoReason)
             SET_REASON_AND_RETURN_IF_NEEDED(textReasons, reasons, includeReasons);
     }