Changeset 252952 in webkit


Ignore:
Timestamp:
Nov 29, 2019 4:03:08 PM (4 years ago)
Author:
Alan Bujtas
Message:

[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.

Source/WebCore:

  • layout/inlineformatting/InlineLineBreaker.cpp:

(WebCore::Layout::LineBreaker::tryBreakingTextRun const):

Tools:

  • LayoutReloaded/misc/LFC-passing-tests.txt:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252951 r252952  
     12019-11-29  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add support for hyphenate-limit-before and hyphenate-limit-after
     4        https://bugs.webkit.org/show_bug.cgi?id=204710
     5        <rdar://problem/57535210>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * layout/inlineformatting/InlineLineBreaker.cpp:
     10        (WebCore::Layout::LineBreaker::tryBreakingTextRun const):
     11
    1122019-11-29  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp

    r252947 r252952  
    148148        return { };
    149149
     150    auto runLength = inlineTextItem.length();
     151    unsigned limitBefore = style.hyphenationLimitBefore() == RenderStyle::initialHyphenationLimitBefore() ? 0 : style.hyphenationLimitBefore();
     152    unsigned limitAfter = style.hyphenationLimitAfter() == RenderStyle::initialHyphenationLimitAfter() ? 0 : style.hyphenationLimitAfter();
     153    // Check if this run can accommodate the before/after limits at all before start measuring text.
     154    if (limitBefore >= runLength || limitAfter >= runLength || limitBefore + limitAfter > runLength)
     155        return { };
     156
    150157    auto& fontCascade = style.fontCascade();
    151158    // FIXME: We might want to cache the hyphen width.
    152159    auto hyphenWidth = LayoutUnit { fontCascade.width(TextRun { StringView { style.hyphenString() } }) };
    153160    auto availableWidthExcludingHyphen = availableWidth - hyphenWidth;
    154     if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen, fontCascade.pixelSize()))
    155         return { };
    156 
    157     auto splitData = TextUtil::split(inlineTextItem.layoutBox(), inlineTextItem.start(), inlineTextItem.length(), overflowRun.logicalWidth, availableWidthExcludingHyphen, { });
     161
     162    // For spaceWidth() see webkit.org/b/169613
     163    if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen + fontCascade.spaceWidth(), fontCascade.pixelSize()))
     164        return { };
     165
     166    auto splitData = TextUtil::split(inlineTextItem.layoutBox(), inlineTextItem.start(), runLength, overflowRun.logicalWidth, availableWidthExcludingHyphen, { });
     167    if (splitData.length < limitBefore)
     168        return { };
     169
    158170    auto textContent = inlineTextItem.layoutBox().textContext()->content;
    159     auto hyphenBefore = inlineTextItem.start() + splitData.length;
     171    // Adjust before index to accommodate the limit-after value (it's the last potential hyphen location in this run).
     172    auto hyphenBefore = std::min(splitData.length, runLength - limitAfter) + 1;
    160173    unsigned hyphenLocation = lastHyphenLocation(StringView(textContent).substring(inlineTextItem.start(), inlineTextItem.length()), hyphenBefore, style.locale());
    161     if (!hyphenLocation)
     174    if (!hyphenLocation || hyphenLocation < limitBefore)
    162175        return { };
    163176    return SplitLengthAndWidth { hyphenLocation, TextUtil::width(inlineTextItem.layoutBox(), inlineTextItem.start(), hyphenLocation) };
  • trunk/Tools/ChangeLog

    r252948 r252952  
     12019-11-29  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add support for hyphenate-limit-before and hyphenate-limit-after
     4        https://bugs.webkit.org/show_bug.cgi?id=204710
     5        <rdar://problem/57535210>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * LayoutReloaded/misc/LFC-passing-tests.txt:
     10
    1112019-11-29  Antti Koivisto  <antti@apple.com>
    212
  • trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt

    r252916 r252952  
    841841fast/text/system-font-zero-size.html
    842842fast/text/system-ui-chinese-bold-fallback.html
     843fast/text/simple-line-layout-hyphen-limit-after.html
     844fast/text/simple-line-layout-hyphen-limit-before.html
    843845fast/text/tab-with-kerning.html
    844846fast/text/text-combine-first-line-crash.html
Note: See TracChangeset for help on using the changeset viewer.