未验证 提交 e50bfbe9 编写于 作者: F Ferhat 提交者: GitHub

Fix multi span text ruler cache lookup failure. (#12023)

上级 b9ce2500
......@@ -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
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册