Skip to content

Commit 29860cd

Browse files
jason-simmonsRBogie
authored andcommitted
libtxt: more accurate tracking of run positioning and width for justified text (flutter#8214)
Fixes flutter/flutter#28891
1 parent b4d1d5f commit 29860cd

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

third_party/txt/src/txt/paragraph.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ void Paragraph::Layout(double width, bool force) {
677677
const SkTextBlobBuilder::RunBuffer& blob_buffer =
678678
builder.allocRunPos(font, glyph_blob.end - glyph_blob.start);
679679

680+
double justify_x_offset_delta = 0;
681+
680682
for (size_t glyph_index = glyph_blob.start;
681683
glyph_index < glyph_blob.end;) {
682684
size_t cluster_start_glyph_index = glyph_index;
@@ -690,7 +692,7 @@ void Paragraph::Layout(double width, bool force) {
690692

691693
size_t pos_index = blob_index * 2;
692694
blob_buffer.pos[pos_index] =
693-
layout.getX(glyph_index) + justify_x_offset;
695+
layout.getX(glyph_index) + justify_x_offset_delta;
694696
blob_buffer.pos[pos_index + 1] = layout.getY(glyph_index);
695697

696698
if (glyph_index == cluster_start_glyph_index)
@@ -770,7 +772,7 @@ void Paragraph::Layout(double width, bool force) {
770772

771773
if (at_word_end) {
772774
if (justify_line) {
773-
justify_x_offset += word_gap_width;
775+
justify_x_offset_delta += word_gap_width;
774776
}
775777
word_index++;
776778

@@ -787,9 +789,11 @@ void Paragraph::Layout(double width, bool force) {
787789
continue;
788790
SkFontMetrics metrics;
789791
font.getMetrics(&metrics);
790-
paint_records.emplace_back(run.style(), SkPoint::Make(run_x_offset, 0),
791-
builder.make(), metrics, line_number,
792-
layout.getAdvance(), run.is_ghost());
792+
paint_records.emplace_back(
793+
run.style(), SkPoint::Make(run_x_offset + justify_x_offset, 0),
794+
builder.make(), metrics, line_number,
795+
layout.getAdvance() + justify_x_offset_delta, run.is_ghost());
796+
justify_x_offset += justify_x_offset_delta;
793797

794798
line_glyph_positions.insert(line_glyph_positions.end(),
795799
glyph_positions.begin(),
@@ -1050,13 +1054,7 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
10501054
// Filled when drawing wavy decorations.
10511055
SkPath path;
10521056

1053-
double width = 0;
1054-
if (paragraph_style_.text_align == TextAlign::justify &&
1055-
record.line() != GetLineCount() - 1) {
1056-
width = width_;
1057-
} else {
1058-
width = record.GetRunWidth();
1059-
}
1057+
double width = record.GetRunWidth();
10601058

10611059
SkScalar underline_thickness;
10621060
if ((metrics.fFlags &

0 commit comments

Comments
 (0)