Skip to content

Commit

Permalink
libtxt: more accurate tracking of run positioning and width for justi…
Browse files Browse the repository at this point in the history
…fied text (flutter#8214)

Fixes flutter/flutter#28891
  • Loading branch information
jason-simmons authored Mar 19, 2019
1 parent 1728103 commit 7cbbdb4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions third_party/txt/src/txt/paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ void Paragraph::Layout(double width, bool force) {
const SkTextBlobBuilder::RunBuffer& blob_buffer =
builder.allocRunPos(font, glyph_blob.end - glyph_blob.start);

double justify_x_offset_delta = 0;

for (size_t glyph_index = glyph_blob.start;
glyph_index < glyph_blob.end;) {
size_t cluster_start_glyph_index = glyph_index;
Expand All @@ -690,7 +692,7 @@ void Paragraph::Layout(double width, bool force) {

size_t pos_index = blob_index * 2;
blob_buffer.pos[pos_index] =
layout.getX(glyph_index) + justify_x_offset;
layout.getX(glyph_index) + justify_x_offset_delta;
blob_buffer.pos[pos_index + 1] = layout.getY(glyph_index);

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

if (at_word_end) {
if (justify_line) {
justify_x_offset += word_gap_width;
justify_x_offset_delta += word_gap_width;
}
word_index++;

Expand All @@ -787,9 +789,11 @@ void Paragraph::Layout(double width, bool force) {
continue;
SkFontMetrics metrics;
font.getMetrics(&metrics);
paint_records.emplace_back(run.style(), SkPoint::Make(run_x_offset, 0),
builder.make(), metrics, line_number,
layout.getAdvance(), run.is_ghost());
paint_records.emplace_back(
run.style(), SkPoint::Make(run_x_offset + justify_x_offset, 0),
builder.make(), metrics, line_number,
layout.getAdvance() + justify_x_offset_delta, run.is_ghost());
justify_x_offset += justify_x_offset_delta;

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

double width = 0;
if (paragraph_style_.text_align == TextAlign::justify &&
record.line() != GetLineCount() - 1) {
width = width_;
} else {
width = record.GetRunWidth();
}
double width = record.GetRunWidth();

SkScalar underline_thickness;
if ((metrics.fFlags &
Expand Down

0 comments on commit 7cbbdb4

Please sign in to comment.