Disable HTML renderer paragraph input width flooring (flutter/engine#44478)
Hopefully the flooring will no longer be needed once the framework stops doing the rounding. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -94,9 +94,9 @@ class CanvasParagraph implements ui.Paragraph {
|
||||
// `30.5` then the TextPainter in the framework will ceil the `30.5` width
|
||||
// which will result in a width of `40.0` that's higher than the constraint
|
||||
// width.
|
||||
constraints = ui.ParagraphConstraints(
|
||||
width: constraints.width.floorToDouble(),
|
||||
);
|
||||
if (!ui.ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
constraints = ui.ParagraphConstraints(width: constraints.width.floorToDouble());
|
||||
}
|
||||
|
||||
if (constraints == _lastUsedConstraints) {
|
||||
return;
|
||||
|
||||
@@ -94,6 +94,32 @@ Future<void> testMain() async {
|
||||
}
|
||||
});
|
||||
|
||||
test('Can disable rounding hack', () {
|
||||
if (!ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
ParagraphBuilder.setDisableRoundingHack(true);
|
||||
addTearDown(() => ParagraphBuilder.setDisableRoundingHack(false));
|
||||
}
|
||||
assert(ParagraphBuilder.shouldDisableRoundingHack);
|
||||
const double fontSize = 1;
|
||||
const String text = '12345';
|
||||
const double letterSpacing = 0.25;
|
||||
const double expectedIntrinsicWidth = text.length * (fontSize + letterSpacing);
|
||||
assert(expectedIntrinsicWidth.truncate() != expectedIntrinsicWidth);
|
||||
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'));
|
||||
builder.pushStyle(TextStyle(letterSpacing: letterSpacing));
|
||||
builder.addText(text);
|
||||
final Paragraph paragraph = builder.build()
|
||||
..layout(const ParagraphConstraints(width: expectedIntrinsicWidth));
|
||||
|
||||
expect(paragraph.maxIntrinsicWidth, expectedIntrinsicWidth);
|
||||
switch (paragraph.computeLineMetrics()) {
|
||||
case [LineMetrics(width: final double width)]:
|
||||
expect(width, expectedIntrinsicWidth);
|
||||
case final List<LineMetrics> metrics:
|
||||
expect(metrics, hasLength(1));
|
||||
}
|
||||
});
|
||||
|
||||
test('lay out unattached paragraph', () {
|
||||
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
||||
fontFamily: 'sans-serif',
|
||||
|
||||
Reference in New Issue
Block a user