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

libtxt: more accurate tracking of run positioning and width for justified text #8214

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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