Bug 138348 - Some words are placed on top of each other in complex text layout
Summary: Some words are placed on top of each other in complex text layout
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on: 138573
Blocks:
  Show dependency treegraph
 
Reported: 2014-11-03 20:48 PST by Myles C. Maxfield
Modified: 2015-09-14 11:18 PDT (History)
7 users (show)

See Also:


Attachments
Patch (674.93 KB, patch)
2014-11-03 20:56 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 (722.74 KB, application/zip)
2014-11-03 22:05 PST, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-07 for mac-mountainlion (735.06 KB, application/zip)
2014-11-03 22:36 PST, Build Bot
no flags Details
Updated for older OS X (794.96 KB, patch)
2014-11-04 11:29 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Updated for older OS X (924.59 KB, patch)
2014-11-04 11:38 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
WIP (2.26 KB, patch)
2015-05-05 18:23 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Reduction (200 bytes, text/html)
2015-05-05 18:26 PDT, Myles C. Maxfield
no flags Details
WIP (22.42 KB, patch)
2015-05-06 22:29 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
WIP (23.44 KB, patch)
2015-05-07 00:42 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (28.12 KB, patch)
2015-05-07 19:12 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (28.16 KB, patch)
2015-05-07 19:16 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (65.34 KB, patch)
2015-05-10 20:06 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2014-11-03 20:48:02 PST
[OSX] Some words are placed on top of each other in complex text layout
Comment 1 Myles C. Maxfield 2014-11-03 20:56:12 PST
Created attachment 240909 [details]
Patch
Comment 2 Build Bot 2014-11-03 22:05:12 PST
Created attachment 240911 [details]
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-09  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 3 Build Bot 2014-11-03 22:36:48 PST
Created attachment 240912 [details]
Archive of layout-test-results from webkit-ews-07 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-07  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 4 Myles C. Maxfield 2014-11-04 09:42:18 PST
<rdar://problem/18797255>
Comment 5 Myles C. Maxfield 2014-11-04 11:29:58 PST
Created attachment 240934 [details]
Updated for older OS X
Comment 6 Myles C. Maxfield 2014-11-04 11:38:21 PST
Created attachment 240935 [details]
Updated for older OS X
Comment 7 mitz 2014-11-04 11:56:06 PST
Comment on attachment 240935 [details]
Updated for older OS X

View in context: https://bugs.webkit.org/attachment.cgi?id=240935&action=review

> Source/WebCore/platform/graphics/mac/ComplexTextController.cpp:620
> +            CGSize advance = advances[i];

Last time we tried something like this was in http://trac.webkit.org/r129176, and we had to revert it in http://trac.webkit.org/r129389. Is this different?
Comment 8 Myles C. Maxfield 2014-11-04 13:10:33 PST
I'm not going to submit this until I make sure that line breaking and max width works correctly (or fix them)
Comment 9 Myles C. Maxfield 2014-11-10 10:40:41 PST
1. I found some problems with width calculations, but these problems are present both with and without this patch. Fixing these seems to be a part of https://bugs.webkit.org/show_bug.cgi?id=138213

2. I looked at the code which calculates max-width and line breaking, and couldn't find anything wrong from inspection.

I think the combination of these two things is enough to land this, keeping in mind that we can easily roll it out if we discover a reason to. Also, if this occurs, I'll create a test showing the incorrect behavior.
Comment 10 Myles C. Maxfield 2014-11-10 10:55:41 PST
http://trac.webkit.org/changeset/175813
Comment 11 Myles C. Maxfield 2014-11-10 10:58:41 PST
<rdar://problem/18928367>
Comment 12 mitz 2014-11-10 11:58:26 PST
(In reply to comment #9)
> 1. I found some problems with width calculations, but these problems are
> present both with and without this patch. Fixing these seems to be a part of
> https://bugs.webkit.org/show_bug.cgi?id=138213
> 
> 2. I looked at the code which calculates max-width and line breaking, and
> couldn't find anything wrong from inspection.
> 
> I think the combination of these two things is enough to land this, keeping
> in mind that we can easily roll it out if we discover a reason to. Also, if
> this occurs, I'll create a test showing the incorrect behavior.

There are actually two problems with the patch you landed, and this test case demonstrates both:

<style>
    div { font-size: 36px; font-family: times; border-right: solid black; float: left; clear: both; }
</style>
<div>
    Woe&#x0300; Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe
</div>
<div>
    Wo&#xe8; Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe Woe
</div>

1. The patch introduced a discrepancy between the complex code path and the simple code path. We need to maintain the invariant that whenever something that can be rendered with the simple path is rendered with the complex path, it remains the same.
2. The patch introduced a mismatch in the complex code path between actual width and computed max-width.

I think you should revert your change for now.
Comment 13 Simon Fraser (smfr) 2014-11-10 12:11:32 PST
(In reply to comment #12)
> 1. The patch introduced a discrepancy between the complex code path and the
> simple code path. We need to maintain the invariant that whenever something
> that can be rendered with the simple path is rendered with the complex path,
> it remains the same.
> 2. The patch introduced a mismatch in the complex code path between actual
> width and computed max-width.

Are there no tests that detect these issues?
Comment 14 WebKit Commit Bot 2014-11-10 12:27:32 PST
Re-opened since this is blocked by bug 138573
Comment 15 Myles C. Maxfield 2014-11-10 14:52:04 PST
This is because RenderText::computePreferredLogicalWidths() is completely broken. When this function tries to calculate the width of “word1 word2“ it first calculates the width of a space by itself, and then will add up the following measurements:
“word1 “ minus the width of the space alone
“ “
“word2“

Similarly, stripTrailingSpace() subtracts a space width from the total width, which is not correct (since the space width is measured in isolation)
Comment 16 Myles C. Maxfield 2014-11-10 22:08:51 PST
https://bugs.webkit.org/show_bug.cgi?id=138581
Comment 17 Myles C. Maxfield 2015-05-05 18:23:10 PDT
Created attachment 252430 [details]
WIP
Comment 18 Myles C. Maxfield 2015-05-05 18:26:42 PDT
Created attachment 252431 [details]
Reduction
Comment 19 Myles C. Maxfield 2015-05-05 19:02:21 PDT
In addition to RenderText::computePreferredLogicalWidths(), TextFragmentIterator in SimpleLineLayout must be updated.
Comment 20 Myles C. Maxfield 2015-05-05 19:20:46 PDT
TextFragmentIterator:

spaceWidth(font.width(TextRun(&space, 1)))

if (startPosition < nextPosition)
        width = m_style.spaceWidth;
Comment 21 Myles C. Maxfield 2015-05-06 20:47:53 PDT
BreakingContext::handleText() also needs to be updated.
Comment 22 Myles C. Maxfield 2015-05-06 20:49:19 PDT
Man, the code inside RenderText::computePreferredLogicalWidths() and BreakingContext::handleText() really have to be unified some day.
Comment 23 Myles C. Maxfield 2015-05-06 21:38:56 PDT
BreakingContext::handleText() actually already includes 1 character of prior whitespace
Comment 24 Myles C. Maxfield 2015-05-06 22:29:01 PDT
Created attachment 252570 [details]
WIP
Comment 25 Myles C. Maxfield 2015-05-07 00:13:33 PDT
(In reply to comment #23)
> BreakingContext::handleText() actually already includes 1 character of prior
> whitespace

... except if the previous run of spaces is longer than 1 character.

We try to include a single prior space in every word. However, if there are two spaces in a row, we will add the leftmost space alone, and ignore spaces from here on until we hit a non-space. The next word we hit, we will not include a prior space (but we'll pick up doing this afterwards)
Comment 26 Myles C. Maxfield 2015-05-07 00:34:29 PDT
RenderText::computePreferredLogicalWidths() measures each character individually for CJK text. :(
Comment 27 Myles C. Maxfield 2015-05-07 00:42:09 PDT
Created attachment 252578 [details]
WIP
Comment 28 Myles C. Maxfield 2015-05-07 19:12:02 PDT
Created attachment 252673 [details]
Patch
Comment 29 Myles C. Maxfield 2015-05-07 19:16:57 PDT
Created attachment 252674 [details]
Patch
Comment 30 Myles C. Maxfield 2015-05-10 12:34:33 PDT
stripTrailingSpace() in RenderBlockFlow also needs to be updated
Comment 31 Myles C. Maxfield 2015-05-10 12:40:23 PDT
Also RenderText::trimmedPrefWidths()
Comment 32 Myles C. Maxfield 2015-05-10 12:44:28 PDT
Callers of SVGInlineTextBox::constructTextRun() as well
Comment 33 Myles C. Maxfield 2015-05-10 12:46:30 PDT
.... along with SVGTextMetrics::constructTextRun
Comment 34 Myles C. Maxfield 2015-05-10 20:06:02 PDT
Created attachment 252838 [details]
Patch
Comment 35 Myles C. Maxfield 2015-05-11 17:38:17 PDT
And Font::widthForGlyph()
Comment 36 Csaba Osztrogonác 2015-09-14 11:18:01 PDT
Comment on attachment 240909 [details]
Patch

Cleared Simon Fraser's review+ from obsolete attachment 240909 [details] so that this bug does not appear in http://webkit.org/pending-commit.