⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 213008 in webkit


Ignore:
Timestamp:
Feb 25, 2017, 2:18:23 PM (9 years ago)
Author:
Alan Bujtas
Message:

Text might wrap when its preferred logical width is used for sizing the containing block.
https://bugs.webkit.org/show_bug.cgi?id=168864
<rdar://problem/30690734>

Reviewed by Antti Koivisto.

Source/WebCore:

In certain cases we end up measuring a text run in 2 different ways.

  1. preferred width computation -> slow path FontCascade::width()
  2. line breaking logic -> fast path FontCascade::widthForSimpleText()

FontCascade::width() and ::widthForSimpleText() might return different results for the same run even when
the individual glyph widths are measured to be the same. It's because they run diffrent set of
arithmetics on the float values and for certain values these arithmetics produce different results due to the floating point
precision.
Since RenderText::computePreferredLogicalWidths() currently forces us to use the slow path
(to retrieve fontfallback and glyph overflow information) the only alternative solution is to turn off the fast path
for all runs that have been already measured using the slow path (which would be just wasteful).

Test: fast/text/fast-run-width-vs-slow-run-width.html

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::widthForSimpleText): Mimics WidthIterator::applyFontTransforms. Use the same set of arithmetics here.

LayoutTests:

  • fast/text/fast-run-width-vs-slow-run-width-expected.html: Added.
  • fast/text/fast-run-width-vs-slow-run-width.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r213006 r213008  
     12017-02-25  Zalan Bujtas <zalan@apple.com>
     2
     3        Text might wrap when its preferred logical width is used for sizing the containing block.
     4        https://bugs.webkit.org/show_bug.cgi?id=168864
     5        <rdar://problem/30690734>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * fast/text/fast-run-width-vs-slow-run-width-expected.html: Added.
     10        * fast/text/fast-run-width-vs-slow-run-width.html: Added.
     11
    1122017-02-25  Michael Catanzaro  <mcatanzaro@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r213007 r213008  
     12017-02-25  Zalan Bujtas  <zalan@apple.com>
     2
     3        Text might wrap when its preferred logical width is used for sizing the containing block.
     4        https://bugs.webkit.org/show_bug.cgi?id=168864
     5        <rdar://problem/30690734>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        In certain cases we end up measuring a text run in 2 different ways.
     10        1. preferred width computation -> slow path FontCascade::width()
     11        2. line breaking logic -> fast path FontCascade::widthForSimpleText()
     12 
     13        FontCascade::width() and ::widthForSimpleText() might return different results for the same run even when
     14        the individual glyph widths are measured to be the same. It's because they run diffrent set of
     15        arithmetics on the float values and for certain values these arithmetics produce different results due to the floating point
     16        precision.
     17        Since RenderText::computePreferredLogicalWidths() currently forces us to use the slow path
     18        (to retrieve fontfallback and glyph overflow information) the only alternative solution is to turn off the fast path
     19        for all runs that have been already measured using the slow path (which would be just wasteful).
     20
     21        Test: fast/text/fast-run-width-vs-slow-run-width.html
     22
     23        * platform/graphics/FontCascade.cpp:
     24        (WebCore::FontCascade::widthForSimpleText): Mimics WidthIterator::applyFontTransforms. Use the same set of arithmetics here. 
     25
    1262017-02-24  Simon Fraser  <simon.fraser@apple.com>
    227
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r212274 r213008  
    383383float FontCascade::widthForSimpleText(StringView text) const
    384384{
     385    if (text.isNull() || text.isEmpty())
     386        return 0;
    385387    ASSERT(codePath(TextRun(text)) != FontCascade::Complex);
    386388    float* cacheEntry = m_fonts->widthCache().add(text, std::numeric_limits<float>::quiet_NaN());
     
    410412    if (hasKerningOrLigatures) {
    411413        font.applyTransforms(&glyphs[0], &advances[0], glyphs.size(), enableKerning(), requiresShaping());
    412         runWidth = 0;
     414        // This is needed only to match the result of the slow path. Same glyph widths but different floating point arithmentics can
     415        // produce different run width.
     416        float runWidthDifferenceWithTransformApplied = -runWidth;
    413417        for (auto& advance : advances)
    414             runWidth += advance.width();
     418            runWidthDifferenceWithTransformApplied += advance.width();
     419        runWidth += runWidthDifferenceWithTransformApplied;
    415420    }
    416421
Note: See TracChangeset for help on using the changeset viewer.