Bug 205486 - ComplexTextController::offsetForPosition returns a wrong offset for a glyph boundary in a RTL text
Summary: ComplexTextController::offsetForPosition returns a wrong offset for a glyph b...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-12-19 20:37 PST by Fujii Hironori
Modified: 2020-01-07 18:05 PST (History)
12 users (show)

See Also:


Attachments
offset-from-point-complex-scripts-actual.txt of GTK port (20 bytes, text/plain)
2019-12-22 23:38 PST, Fujii Hironori
no flags Details
Add a new test case with Ahem (1.67 KB, patch)
2019-12-23 00:03 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
rtl.html (1.08 KB, text/html)
2019-12-23 01:14 PST, Fujii Hironori
no flags Details
screenshot of Chrome for Mac with Ahem font (77.30 KB, image/png)
2019-12-23 01:18 PST, Fujii Hironori
no flags Details
Patch (60.17 KB, patch)
2019-12-23 03:15 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (5.63 KB, patch)
2019-12-23 03:17 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (5.44 KB, patch)
2019-12-23 03:54 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (5.43 KB, patch)
2019-12-23 03:58 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (7.88 KB, patch)
2019-12-23 20:46 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (7.08 KB, patch)
2019-12-23 20:49 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (7.30 KB, patch)
2019-12-24 03:25 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch for landing (7.66 KB, patch)
2020-01-06 21:58 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2019-12-19 20:37:14 PST
[Win] imported/blink/editing/selection/offset-from-point-complex-scripts.html is failing since Bug 204884

ComplexTextController::offsetForPosition returns a incorrect offset for RTL text.
Comment 1 Fujii Hironori 2019-12-22 23:38:38 PST
Created attachment 386327 [details]
offset-from-point-complex-scripts-actual.txt of GTK port

GTK port is also failing since adopting ComplexTextController.
Comment 2 Fujii Hironori 2019-12-23 00:03:24 PST
Created attachment 386328 [details]
Add a new test case with Ahem
Comment 3 Fujii Hironori 2019-12-23 01:10:31 PST
This issue can be reproduced for Mac port.

Expected: 6 5 4 3 2 1 0
Actual: 6 5 6 5 4 5 4 3 4 3 2 3 2 1 2 1 0

Chrome for Mac looks working fine.

This issue can be reproduced by two conditions:

* Glyphs have integral width
* using ComplexTextController
Comment 4 Fujii Hironori 2019-12-23 01:12:49 PST
(In reply to Fujii Hironori from comment #3)
> This issue can be reproduced by two conditions:
> 
> * Glyphs have integral width
> * using ComplexTextController

And,

* RTL
Comment 5 Fujii Hironori 2019-12-23 01:14:26 PST
Created attachment 386331 [details]
rtl.html
Comment 6 Fujii Hironori 2019-12-23 01:18:25 PST
Created attachment 386332 [details]
screenshot of Chrome for Mac with Ahem font
Comment 7 Fujii Hironori 2019-12-23 01:54:49 PST
ComplexTextController::offsetForPosition has the following code:

> unsigned hitIndex = hitGlyphStart + (hitGlyphEnd - hitGlyphStart) * (m_run.ltr() ? x / adjustedAdvance : 1 - x / adjustedAdvance);

If m_run.ltr() is true and x == 0, hitIndex would become hitGlyphEnd.
This is not expected.
Comment 8 Fujii Hironori 2019-12-23 03:15:32 PST
Created attachment 386334 [details]
Patch
Comment 9 Fujii Hironori 2019-12-23 03:17:56 PST
Created attachment 386335 [details]
Patch
Comment 10 Fujii Hironori 2019-12-23 03:54:06 PST
Created attachment 386338 [details]
Patch
Comment 11 Fujii Hironori 2019-12-23 03:58:32 PST
Created attachment 386339 [details]
Patch
Comment 12 Fujii Hironori 2019-12-23 19:44:59 PST
fast/text/ellipsis-text-rtl.html failed on Mac EWS.
This is a edge case.

In RTL text, the char offset of *previous* glyph needs to be returned for glyph boundary.

For example,

characters: [A] [B]
LTR glyphs: (A) (B)
RTL glyphs: (B) (A)

Assuming glyph widths are 20px,
and argument 'h' of offsetForPosition is 20px, which is the position between (A) and (B).

In LTR, glyph (B) is hit, and offset of [B] should be returned.
In RTL, glyph (B) is hit, and offset of [B] should be returned.

In my patch, in RTL, glyph (A) is hit, and offset of [A] is returned.
Comment 13 Fujii Hironori 2019-12-23 20:46:16 PST
Created attachment 386371 [details]
Patch
Comment 14 Fujii Hironori 2019-12-23 20:49:35 PST
Created attachment 386372 [details]
Patch
Comment 15 Fujii Hironori 2019-12-24 03:25:49 PST
Created attachment 386385 [details]
Patch
Comment 16 Darin Adler 2019-12-26 17:53:50 PST
Comment on attachment 386385 [details]
Patch

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

> Source/WebCore/platform/graphics/ComplexTextController.cpp:227
> +                        hitIndex = hitGlyphEnd - (hitGlyphEnd - hitGlyphStart) * (x / adjustedAdvance);

Is the rounding here correct? This truncates toward towards the end. Is that what’s intended?
Comment 17 Fujii Hironori 2019-12-27 00:28:36 PST
Comment on attachment 386385 [details]
Patch

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

Thank you for reviewing my patch.

>> Source/WebCore/platform/graphics/ComplexTextController.cpp:227
>> +                        hitIndex = hitGlyphEnd - (hitGlyphEnd - hitGlyphStart) * (x / adjustedAdvance);
> 
> Is the rounding here correct? This truncates toward towards the end. Is that what’s intended?

In my understanding, Neither rounding nor truncating toward the end happen in this expression.
Only truncating toward the start can happen by assigning a float value to hitIndex. It is expected.
Comment 18 Fujii Hironori 2020-01-06 03:43:26 PST
Myles, do you have a chance to review this patch? Should I look for other reviewers?
Comment 19 Ross Kirsling 2020-01-06 21:04:31 PST
Comment on attachment 386385 [details]
Patch

While this isn't my usual reviewing domain, the change and your explanation are quite clear, a test is fixed and another added, and EWS is happy, so that makes me feel pretty good about this patch.
Comment 20 Fujii Hironori 2020-01-06 21:58:19 PST
Created attachment 386935 [details]
Patch for landing
Comment 21 Fujii Hironori 2020-01-06 23:50:58 PST
Comment on attachment 386935 [details]
Patch for landing

Clearing flags on attachment: 386935

Committed r254114: <https://trac.webkit.org/changeset/254114>
Comment 22 Fujii Hironori 2020-01-06 23:51:03 PST
All reviewed patches have been landed.  Closing bug.
Comment 23 Radar WebKit Bug Importer 2020-01-06 23:52:14 PST
<rdar://problem/58366513>
Comment 24 Fujii Hironori 2020-01-07 18:05:20 PST
Filed: Bug 205898 – [GTK] fast/text/atsui-rtl-override-selection.html is failing since r254114