Simple line layout: Bail out from Simple Line Layout on surrogate pairs.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2017 14:41:10 +0000 (14:41 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2017 14:41:10 +0000 (14:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167840
<rdar://problem/30364784>

Reviewed by Myles C. Maxfield.

Source/WebCore:

Surrogate pairs require special line breaking logic.

Test: fast/text/simple-line-layout-no-surrogate-pairs.html

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForCharacter):
(WebCore::SimpleLineLayout::canUseForText): Checking against special characters is faster than
checking against glyphs. Reverse their order.
(WebCore::SimpleLineLayout::printReason):

LayoutTests:

* fast/text/simple-line-layout-no-surrogate-pairs-expected.html: Added.
* fast/text/simple-line-layout-no-surrogate-pairs.html: Added.

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

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

index 17d9ce4..453675b 100644 (file)
@@ -1,3 +1,14 @@
+2017-02-05  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Bail out from Simple Line Layout on surrogate pairs.
+        https://bugs.webkit.org/show_bug.cgi?id=167840
+        <rdar://problem/30364784>
+
+        Reviewed by Myles C. Maxfield.
+
+        * fast/text/simple-line-layout-no-surrogate-pairs-expected.html: Added.
+        * fast/text/simple-line-layout-no-surrogate-pairs.html: Added.
+
 2017-02-03  Myles C. Maxfield  <mmaxfield@apple.com>
 
         REGRESSION(r204858): Synthetic bold text in vertical writing mode is rotated away from original text
diff --git a/LayoutTests/fast/text/simple-line-layout-no-surrogate-pairs-expected.html b/LayoutTests/fast/text/simple-line-layout-no-surrogate-pairs-expected.html
new file mode 100644 (file)
index 0000000..ed03cd8
--- /dev/null
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we don't use simple line layout for surrogate pairs.</title>
+</head>
+<body></body>
+</html>
diff --git a/LayoutTests/fast/text/simple-line-layout-no-surrogate-pairs.html b/LayoutTests/fast/text/simple-line-layout-no-surrogate-pairs.html
new file mode 100644 (file)
index 0000000..38ae6aa
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>This tests that we don't use simple line layout for surrogate pairs.</title>
+<style>
+div {
+    color: white;
+    font-family: Arial;
+}
+</style>
+<script>
+if (window.internals) {
+    internals.settings.setSimpleLineLayoutDebugBordersEnabled(true);
+    internals.settings.setSimpleLineLayoutEnabled(true);
+}
+</script>
+</head>
+<body>
+<div>&#xd800;</div>
+<div>&#x1D306;</div>
+<div>&#xdb7f;</div>
+</body>
+</html>
index 5a13e7f..de0700e 100644 (file)
@@ -1,3 +1,21 @@
+2017-02-05  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Bail out from Simple Line Layout on surrogate pairs.
+        https://bugs.webkit.org/show_bug.cgi?id=167840
+        <rdar://problem/30364784>
+
+        Reviewed by Myles C. Maxfield.
+
+        Surrogate pairs require special line breaking logic. 
+
+        Test: fast/text/simple-line-layout-no-surrogate-pairs.html
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForCharacter):
+        (WebCore::SimpleLineLayout::canUseForText): Checking against special characters is faster than
+        checking against glyphs. Reverse their order. 
+        (WebCore::SimpleLineLayout::printReason):
+
 2017-02-04  Joseph Pecoraro  <pecoraro@apple.com>
 
         Static Analyzer: WebCoreNSURLExtras.mm: Potential leak of memory pointed to by 'allBytesBuffer'
index a5ae2e3..0ca557e 100644 (file)
@@ -113,7 +113,8 @@ enum AvoidanceReason_ : uint64_t {
     FlowChildIsSelected                   = 1LLU  << 47,
     FlowHasHangingPunctuation             = 1LLU  << 48,
     FlowFontHasOverflowGlyph              = 1LLU  << 49,
-    EndOfReasons                          = 1LLU  << 50
+    FlowTextHasSurrogatePair              = 1LLU  << 50,
+    EndOfReasons                          = 1LLU  << 51
 };
 const unsigned NoReason = 0;
 
@@ -150,6 +151,9 @@ template<> AvoidanceReasonFlags canUseForCharacter(UChar character, bool textIsJ
             SET_REASON_AND_RETURN_IF_NEEDED(FlowHasJustifiedNonLatinText, reasons, includeReasons);
     }
 
+    if (U16_IS_SURROGATE(character))
+        SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasSurrogatePair, reasons, includeReasons);
+    
     UCharDirection direction = u_charDirection(character);
     if (direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC
         || direction == U_RIGHT_TO_LEFT_EMBEDDING || direction == U_RIGHT_TO_LEFT_OVERRIDE
@@ -179,16 +183,16 @@ static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned le
         if (character == softHyphen)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasSoftHyphen, reasons, includeReasons);
 
+        auto characterReasons = canUseForCharacter(character, textIsJustified, includeReasons);
+        if (characterReasons != NoReason)
+            SET_REASON_AND_RETURN_IF_NEEDED(characterReasons, reasons, includeReasons);
+
         auto glyphData = fontCascade.glyphDataForCharacter(character, false);
         if (!glyphData.isValid() || glyphData.font != &primaryFont)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowPrimaryFontIsInsufficient, reasons, includeReasons);
 
         if (lineHeightConstraint && primaryFont.boundsForGlyph(glyphData.glyph).height() > *lineHeightConstraint)
             SET_REASON_AND_RETURN_IF_NEEDED(FlowFontHasOverflowGlyph, reasons, includeReasons);
-
-        auto characterReasons = canUseForCharacter(character, textIsJustified, includeReasons);
-        if (characterReasons != NoReason)
-            SET_REASON_AND_RETURN_IF_NEEDED(characterReasons, reasons, includeReasons);
     }
     return reasons;
 }
@@ -1080,6 +1084,9 @@ static void printReason(AvoidanceReason reason, TextStream& stream)
     case FlowFontHasOverflowGlyph:
         stream << "-webkit-line-box-contain: glyphs with overflowing text.";
         break;
+    case FlowTextHasSurrogatePair:
+        stream << "surrogate pair";
+        break;
     case FlowTextIsEmpty:
     case FlowHasNoChild:
     case FlowHasNoParent: