Disable text rounding hack by default (flutter/engine#44544)

This depends on https://github.com/flutter/flutter/pull/132094 and customer_testing migration.

I'll announce this change and add a g3 fix after this lands.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
LongCatIsLooong 2023-08-09 18:44:23 -07:00 committed by GitHub
parent 8e687347b3
commit e156901deb
5 changed files with 28 additions and 11 deletions

View File

@ -3026,11 +3026,14 @@ abstract class ParagraphBuilder {
///
/// Do not rely on this getter as it exists for migration purposes only and
/// will soon be removed.
@Deprecated('''
The shouldDisableRoundingHack flag is for internal migration purposes only and should not be used.
''')
static bool get shouldDisableRoundingHack {
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
return const bool.fromEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK', defaultValue: true)
|| _roundingHackDisabledInDebugMode;
}
static bool _roundingHackDisabledInDebugMode = false;
static bool _roundingHackDisabledInDebugMode = true;
/// Only works in debug mode. Do not call this method as it is for migration
/// purposes only and will soon be removed.

View File

@ -687,10 +687,10 @@ abstract class ParagraphBuilder {
engine.renderer.createParagraphBuilder(style);
static bool get shouldDisableRoundingHack {
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
return const bool.fromEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK', defaultValue: true)
|| _roundingHackDisabledInDebugMode;
}
static bool _roundingHackDisabledInDebugMode = false;
static bool _roundingHackDisabledInDebugMode = true;
static void setDisableRoundingHack(bool disableRoundingHack) {
assert(() {
_roundingHackDisabledInDebugMode = disableRoundingHack;

View File

@ -156,16 +156,16 @@ void testMain() {
ui.ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
});
test('rounding hack applied by default', () {
test('rounding hack disabled by default', () {
const double fontSize = 1.25;
const String text = '12345';
assert((fontSize * text.length).truncate() != fontSize * text.length);
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isFalse);
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isTrue);
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'));
builder.addText(text);
final ui.Paragraph paragraph = builder.build()
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
expect(paragraph.computeLineMetrics().length, greaterThan(1));
expect(paragraph.computeLineMetrics().length, 1);
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520

View File

@ -776,7 +776,19 @@ Future<void> testMain() async {
expect(paragraph.longestLine, 50.0);
});
test('$CanvasParagraph.width should be a whole integer', () {
test('$CanvasParagraph.width should be a whole integer when shouldDisableRoundingHack is false', () {
if (ui.ParagraphBuilder.shouldDisableRoundingHack) {
// Try applying the rounding hack if it's disabled. This may not work if
// the 'SKPARAGRAPH_REMOVE_ROUNDING_HACK' dart environment declaration
// is set to 'false'.
ui.ParagraphBuilder.setDisableRoundingHack(false);
addTearDown(() => ui.ParagraphBuilder.setDisableRoundingHack(true));
}
// The paragraph width is only rounded to a whole integer if
// shouldDisableRoundingHack is false.
if (ui.ParagraphBuilder.shouldDisableRoundingHack) {
return;
}
final ui.Paragraph paragraph = plain(ahemStyle, 'abc');
paragraph.layout(const ui.ParagraphConstraints(width: 30.8));

View File

@ -246,6 +246,7 @@ void main() {
const double fontSize = 1.25;
const String text = '12345';
assert((fontSize * text.length).truncate() != fontSize * text.length);
// ignore: deprecated_member_use
final bool roundingHackWasDisabled = ParagraphBuilder.shouldDisableRoundingHack;
ParagraphBuilder.setDisableRoundingHack(true);
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
@ -263,15 +264,16 @@ void main() {
ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
});
test('rounding hack applied by default', () {
test('rounding hack disabled by default', () {
const double fontSize = 1.25;
const String text = '12345';
assert((fontSize * text.length).truncate() != fontSize * text.length);
expect(ParagraphBuilder.shouldDisableRoundingHack, isFalse);
// ignore: deprecated_member_use
expect(ParagraphBuilder.shouldDisableRoundingHack, isTrue);
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
builder.addText(text);
final Paragraph paragraph = builder.build()
..layout(const ParagraphConstraints(width: text.length * fontSize));
expect(paragraph.computeLineMetrics().length, greaterThan(1));
expect(paragraph.computeLineMetrics().length, 1);
});
}