mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix multi span text ruler cache lookup failure. (flutter/engine#12023)
This commit is contained in:
parent
d61b3b3030
commit
d01050e5fc
@ -759,8 +759,13 @@ class ParagraphRuler {
|
||||
|
||||
MeasurementResult cacheLookup(
|
||||
EngineParagraph paragraph, ui.ParagraphConstraints constraints) {
|
||||
final String plainText = paragraph._plainText;
|
||||
if (plainText == null) {
|
||||
// Multi span paragraph, do not use cache item.
|
||||
return null;
|
||||
}
|
||||
final List<MeasurementResult> constraintCache =
|
||||
_measurementCache[paragraph._plainText];
|
||||
_measurementCache[plainText];
|
||||
if (constraintCache == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -62,4 +62,38 @@ void main() async {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/37744
|
||||
test('measures heights of multiple multi-span paragraphs', () {
|
||||
const double fontSize = 20.0;
|
||||
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
|
||||
fontFamily: 'Ahem',
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: fontSize,
|
||||
));
|
||||
builder.addText('1234567890 1234567890 1234567890 1234567890 1234567890');
|
||||
builder.addText('1234567890 1234567890 1234567890 1234567890 1234567890');
|
||||
builder.pushStyle(TextStyle(fontWeight: FontWeight.bold));
|
||||
builder.addText('span0');
|
||||
final Paragraph paragraph = builder.build();
|
||||
paragraph.layout(ParagraphConstraints(width: fontSize * 5.0));
|
||||
expect(
|
||||
paragraph.height, closeTo(fontSize * 3.0, 0.001)); // because it wraps
|
||||
|
||||
// Now create another builder with just a single line of text so
|
||||
// it tries to reuse ruler cache but misses.
|
||||
final ParagraphBuilder builder2 = ParagraphBuilder(ParagraphStyle(
|
||||
fontFamily: 'Ahem',
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: fontSize,
|
||||
));
|
||||
builder2.addText('span1');
|
||||
builder2.pushStyle(TextStyle(fontWeight: FontWeight.bold));
|
||||
builder2.addText('span2');
|
||||
final Paragraph paragraph2 = builder2.build();
|
||||
paragraph2.layout(ParagraphConstraints(width: fontSize * 5.0));
|
||||
expect(paragraph2.height, closeTo(fontSize, 0.001)); // because it wraps
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user