libtxt: fix the adjustment of code unit runs for line justification (flutter/engine#5536)

Fixes https://github.com/flutter/flutter/issues/18483
This commit is contained in:
Jason Simmons
2018-06-14 16:14:37 -07:00
committed by GitHub
parent 97cf68d6c8
commit f31724a16c
2 changed files with 18 additions and 5 deletions

View File

@@ -192,8 +192,7 @@ Paragraph::GlyphPosition::GlyphPosition(double x_start,
x_pos(x_start, x_start + x_advance) {}
void Paragraph::GlyphPosition::Shift(double delta) {
x_pos.start += delta;
x_pos.end += delta;
x_pos.Shift(delta);
}
Paragraph::GlyphLine::GlyphLine(std::vector<GlyphPosition>&& p, size_t tcu)
@@ -212,6 +211,12 @@ Paragraph::CodeUnitRun::CodeUnitRun(std::vector<GlyphPosition>&& p,
font_metrics(metrics),
direction(dir) {}
void Paragraph::CodeUnitRun::Shift(double delta) {
x_pos.Shift(delta);
for (GlyphPosition& position : positions)
position.Shift(delta);
}
Paragraph::Paragraph() {
breaker_.setLocale(icu::Locale(), nullptr);
}
@@ -697,9 +702,7 @@ void Paragraph::Layout(double width, bool force) {
double line_x_offset = GetLineXOffset(run_x_offset);
if (line_x_offset) {
for (CodeUnitRun& code_unit_run : line_code_unit_runs) {
for (GlyphPosition& position : code_unit_run.positions) {
position.Shift(line_x_offset);
}
code_unit_run.Shift(line_x_offset);
}
for (GlyphPosition& position : line_glyph_positions) {
position.Shift(line_x_offset);

View File

@@ -73,11 +73,19 @@ class Paragraph {
struct Range {
Range() : start(), end() {}
Range(T s, T e) : start(s), end(e) {}
T start, end;
bool operator==(const Range<T>& other) const {
return start == other.start && end == other.end;
}
T width() { return end - start; }
void Shift(T delta) {
start += delta;
end += delta;
}
};
// Minikin Layout doLayout() and LineBreaker addStyleRun() has an
@@ -260,6 +268,8 @@ class Paragraph {
size_t line,
const SkPaint::FontMetrics& metrics,
TextDirection dir);
void Shift(double delta);
};
// Holds the laid out x positions of each glyph.