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:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user