Changeset 252947 in webkit


Ignore:
Timestamp:
Nov 29, 2019 10:34:16 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Add support for simple hyphenation
https://bugs.webkit.org/show_bug.cgi?id=204706
<rdar://problem/57533803>

Reviewed by Antti Koivisto.

This is just -webkit-hyphens: auto, no limit-before/after/lines support yet.

  • layout/Verification.cpp:

(WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree):

  • layout/inlineformatting/InlineLineBreaker.cpp:

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

  • layout/inlineformatting/text/TextUtil.cpp:

(WebCore::Layout::TextUtil::split):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252945 r252947  
     12019-11-29  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add support for simple hyphenation
     4        https://bugs.webkit.org/show_bug.cgi?id=204706
     5        <rdar://problem/57533803>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is just -webkit-hyphens: auto, no limit-before/after/lines support yet.
     10
     11        * layout/Verification.cpp:
     12        (WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree):
     13        * layout/inlineformatting/InlineLineBreaker.cpp:
     14        (WebCore::Layout::LineBreaker::tryBreakingTextRun const):
     15        * layout/inlineformatting/text/TextUtil.cpp:
     16        (WebCore::Layout::TextUtil::split):
     17
    1182019-11-27  Antoine Quint  <graouts@apple.com>
    219
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp

    r252941 r252947  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
     31#include "FontCascade.h"
    3132#include "Hyphenation.h"
    3233#include "InlineItem.h"
     
    131132{
    132133    ASSERT(overflowRun.inlineItem.isText());
    133     auto breakWords = overflowRun.inlineItem.style().wordBreak();
     134    auto& style = overflowRun.inlineItem.style();
     135    auto breakWords = style.wordBreak();
    134136    if (breakWords == WordBreak::KeepAll)
    135137        return { };
     
    140142        return SplitLengthAndWidth { splitData.length, splitData.logicalWidth };
    141143    }
    142     // FIXME: Find first soft wrap opportunity (e.g. hyphenation)
    143     return { };
     144    // Find the hyphen position as follows:
     145    // 1. Split the text by taking the hyphen width into account
     146    // 2. Find the last hyphen position before the split position
     147    if (style.hyphens() != Hyphens::Auto || !canHyphenate(style.locale()))
     148        return { };
     149
     150    auto& fontCascade = style.fontCascade();
     151    // FIXME: We might want to cache the hyphen width.
     152    auto hyphenWidth = LayoutUnit { fontCascade.width(TextRun { StringView { style.hyphenString() } }) };
     153    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, { });
     158    auto textContent = inlineTextItem.layoutBox().textContext()->content;
     159    auto hyphenBefore = inlineTextItem.start() + splitData.length;
     160    unsigned hyphenLocation = lastHyphenLocation(StringView(textContent).substring(inlineTextItem.start(), inlineTextItem.length()), hyphenBefore, style.locale());
     161    if (!hyphenLocation)
     162        return { };
     163    return SplitLengthAndWidth { hyphenLocation, TextUtil::width(inlineTextItem.layoutBox(), inlineTextItem.start(), hyphenLocation) };
    144164}
    145165
  • trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp

    r252941 r252947  
    9696TextUtil::SplitData TextUtil::split(const Box& inlineBox, unsigned startPosition, unsigned length, LayoutUnit textWidth, LayoutUnit availableWidth, LayoutUnit contentLogicalLeft)
    9797{
    98     // FIXME This should take hypens into account.
    9998    ASSERT(availableWidth >= 0);
    10099    auto left = startPosition;
Note: See TracChangeset for help on using the changeset viewer.