Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@GaryQian
Copy link
Contributor

Fixes flutter/flutter#21679

Here, we track the TextDirection used for the styled run, and apply the most recent to ghost runs. This needs to be done because ICU interprets all non-language-specific (eg, normal space character) as LTR, which causes the space to be on the right side of the text in RTL languages. We handle this case manually and flip it to the opposite side.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started reviewing this but saw you were halfway through a conversation regarding this with @jason-simmons :) I'll defer to the conclusions from that.

for (size_t i = 0; i < runs_.size(); ++i) {
StyledRuns::Run run = runs_.GetRun(i);
// Initialize TextDirection to LTR as that is what ICU initializes it to.
styled_run_direction_map.emplace(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the emplace adds much value here as the enum value is not expensive to copy.

line_range.end_excluding_whitespace < line_range.end &&
bidi_run.start() <= line_range.end &&
bidi_run.end() > line_end_index) {
// Use the most recent TextDirection instead of the defaulted LTR value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParagraphStyle has a field that sets the base TextDirection for the paragraph. What happens in this case if you set that field to RTL?

// impact on the layout.
if (paragraph_style_.ellipsis.empty() &&
//
// RTL ghost run check (RTL ghost runs appear visually before the rest of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be merged with the LTR ghost run check below?

How about this:

  • If (end_excluding_whitespace != line_range.end), then in a separate pass scan for the ghost run. The ghost run is the BidiRun that intersects the line's (end_excluding_whitespace, line_range.end) interval. Presumably there is only one such run.
  • If the ghost run exists and its direction is RTL, then insert it into line_runs before doing the main pass that populates line_runs
  • If it's LTR, then insert it after the main pass

} else if (run.is_rtl()) {
// For RTL ghost runs, we need to shift the ghost run over here as it is
// the offset is calculated in reverse order from LTR.
rtl_ghost_x_offset += layout.getAdvance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be reduced to doing

      if (run.is_ghost() && run.is_rtl())
        run_x_offset -= layout.getAdvance();

before converting the layout into text blobs

@GaryQian GaryQian requested a review from jason-simmons April 19, 2019 22:10

std::vector<GlyphPosition> line_glyph_positions;
std::vector<CodeUnitRun> line_code_unit_runs;
std::vector<CodeUnitRun*> ghost_code_unit_runs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be necessary

@GaryQian GaryQian requested a review from jason-simmons April 19, 2019 23:19

layout.doLayout(text_ptr, text_start, text_count, text_size, run.is_rtl(),
minikin_font, minikin_paint, minikin_font_collection);
if (run.is_ghost() && run.is_rtl())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to after the layout.nGlyphs() == 0 check and add a comment

liyuqian added a commit that referenced this pull request Apr 22, 2019
liyuqian added a commit that referenced this pull request Apr 22, 2019
…" (#8681)

This reverts commit 6e79dcd.

Reverts #8638

Reason: #8638 breaks the post-submit Cirrus tests. See https://cirrus-ci.com/build/5143341531398144 and subsequent post-submit failures. Specifically, ParagraphTest.RightAlignParagraph is failing.

TBR: @GaryQian
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 22, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 22, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 22, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Apr 22, 2019
flutter/engine@206cab6...ea28bfa

git log 206cab6..ea28bfa --no-merges --oneline
ea28bfa Custom RTL handling for ghost runs, NotoNaskhArabic test font (flutter/engine#8683)
1c9457c Revert &#34;Only allow mappings for ICU initialization. (#8656)&#34; (flutter/engine#8682)
b4ed303 Revert &#34;RTL handling for ghost runs, NotoNaskhArabic test font (#8638)&#34; (flutter/engine#8681)
8b5f776 Remove support for downloading dynamic patches. (flutter/engine#8663)
1bcb96b Add framework test in engine presubmit checks (flutter/engine#8664)
6e79dcd RTL handling for ghost runs, NotoNaskhArabic test font (flutter/engine#8638)
c37d459 Roll src/third_party/skia 1c0b05afdef8..a76fad2d494a (4 commits) (flutter/engine#8665)
2e4f0a4 Put the testing lib in the flutter namespace. (flutter/engine#8661)
1239df9 Allow native bindings in secondary isolates. (flutter/engine#8658)
b0cbce4 Replace ThreadLocal with ThreadLocalUniquePtr&lt;T&gt; (flutter/engine#8659)
bd8c5b1 Only allow mappings for ICU initialization. (flutter/engine#8656)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff ([email protected]), and stop
the roller if necessary.
@mzarsaw
Copy link

mzarsaw commented Jul 16, 2021

fix that with set textDirection to ltr. it's cool

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField cursor is misplaced when regain focus & textAlign is end, right, or center

5 participants