[LFC][IFC] Add support for hyphenate-limit-before and hyphenate-limit-after
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Nov 2019 00:03:08 +0000 (00:03 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Nov 2019 00:03:08 +0000 (00:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204710
<rdar://problem/57535210>

Reviewed by Antti Koivisto.

Source/WebCore:

* layout/inlineformatting/InlineLineBreaker.cpp:
(WebCore::Layout::LineBreaker::tryBreakingTextRun const):

Tools:

* LayoutReloaded/misc/LFC-passing-tests.txt:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp
Tools/ChangeLog
Tools/LayoutReloaded/misc/LFC-passing-tests.txt

index 0331a75..94fecb0 100644 (file)
@@ -1,3 +1,14 @@
+2019-11-29  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Add support for hyphenate-limit-before and hyphenate-limit-after
+        https://bugs.webkit.org/show_bug.cgi?id=204710
+        <rdar://problem/57535210>
+
+        Reviewed by Antti Koivisto.
+
+        * layout/inlineformatting/InlineLineBreaker.cpp:
+        (WebCore::Layout::LineBreaker::tryBreakingTextRun const):
+
 2019-11-29  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r252944.
index 94c647f..889aa0b 100644 (file)
@@ -147,18 +147,31 @@ Optional<LineBreaker::SplitLengthAndWidth> LineBreaker::tryBreakingTextRun(const
     if (style.hyphens() != Hyphens::Auto || !canHyphenate(style.locale()))
         return { };
 
+    auto runLength = inlineTextItem.length();
+    unsigned limitBefore = style.hyphenationLimitBefore() == RenderStyle::initialHyphenationLimitBefore() ? 0 : style.hyphenationLimitBefore();
+    unsigned limitAfter = style.hyphenationLimitAfter() == RenderStyle::initialHyphenationLimitAfter() ? 0 : style.hyphenationLimitAfter();
+    // Check if this run can accommodate the before/after limits at all before start measuring text.
+    if (limitBefore >= runLength || limitAfter >= runLength || limitBefore + limitAfter > runLength)
+        return { };
+
     auto& fontCascade = style.fontCascade();
     // FIXME: We might want to cache the hyphen width.
     auto hyphenWidth = LayoutUnit { fontCascade.width(TextRun { StringView { style.hyphenString() } }) };
     auto availableWidthExcludingHyphen = availableWidth - hyphenWidth;
-    if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen, fontCascade.pixelSize()))
+
+    // For spaceWidth() see webkit.org/b/169613
+    if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen + fontCascade.spaceWidth(), fontCascade.pixelSize()))
+        return { };
+
+    auto splitData = TextUtil::split(inlineTextItem.layoutBox(), inlineTextItem.start(), runLength, overflowRun.logicalWidth, availableWidthExcludingHyphen, { });
+    if (splitData.length < limitBefore)
         return { };
 
-    auto splitData = TextUtil::split(inlineTextItem.layoutBox(), inlineTextItem.start(), inlineTextItem.length(), overflowRun.logicalWidth, availableWidthExcludingHyphen, { });
     auto textContent = inlineTextItem.layoutBox().textContext()->content;
-    auto hyphenBefore = inlineTextItem.start() + splitData.length;
+    // Adjust before index to accommodate the limit-after value (it's the last potential hyphen location in this run).
+    auto hyphenBefore = std::min(splitData.length, runLength - limitAfter) + 1;
     unsigned hyphenLocation = lastHyphenLocation(StringView(textContent).substring(inlineTextItem.start(), inlineTextItem.length()), hyphenBefore, style.locale());
-    if (!hyphenLocation)
+    if (!hyphenLocation || hyphenLocation < limitBefore)
         return { };
     return SplitLengthAndWidth { hyphenLocation, TextUtil::width(inlineTextItem.layoutBox(), inlineTextItem.start(), hyphenLocation) };
 }
index 23a7404..a26ed49 100644 (file)
@@ -1,3 +1,13 @@
+2019-11-29  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Add support for hyphenate-limit-before and hyphenate-limit-after
+        https://bugs.webkit.org/show_bug.cgi?id=204710
+        <rdar://problem/57535210>
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2019-11-29  Antti Koivisto  <antti@apple.com>
 
         Add mechanism for enabling internal and experimental features from run-webkit-test command line
index a8c11dc..9e9f3eb 100644 (file)
@@ -840,6 +840,8 @@ fast/text/system-font-japanese-synthetic-italic.html
 fast/text/system-font-legacy-name.html
 fast/text/system-font-zero-size.html
 fast/text/system-ui-chinese-bold-fallback.html
+fast/text/simple-line-layout-hyphen-limit-after.html
+fast/text/simple-line-layout-hyphen-limit-before.html
 fast/text/tab-with-kerning.html
 fast/text/text-combine-first-line-crash.html
 fast/text/text-combine-rendering.html