Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a08d4e3

Browse files
disable text rounding hack by default
1 parent a9cd8a3 commit a08d4e3

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

lib/ui/text.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,11 +3026,14 @@ abstract class ParagraphBuilder {
30263026
///
30273027
/// Do not rely on this getter as it exists for migration purposes only and
30283028
/// will soon be removed.
3029+
@Deprecated('''
3030+
The shouldDisableRoundingHack flag is for internal migration purposes only and should not be used.
3031+
''')
30293032
static bool get shouldDisableRoundingHack {
3030-
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
3033+
return const bool.fromEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK', defaultValue: true)
30313034
|| _roundingHackDisabledInDebugMode;
30323035
}
3033-
static bool _roundingHackDisabledInDebugMode = false;
3036+
static bool _roundingHackDisabledInDebugMode = true;
30343037

30353038
/// Only works in debug mode. Do not call this method as it is for migration
30363039
/// purposes only and will soon be removed.

lib/web_ui/lib/text.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,10 @@ abstract class ParagraphBuilder {
687687
engine.renderer.createParagraphBuilder(style);
688688

689689
static bool get shouldDisableRoundingHack {
690-
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
690+
return const bool.fromEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK', defaultValue: true)
691691
|| _roundingHackDisabledInDebugMode;
692692
}
693-
static bool _roundingHackDisabledInDebugMode = false;
693+
static bool _roundingHackDisabledInDebugMode = true;
694694
static void setDisableRoundingHack(bool disableRoundingHack) {
695695
assert(() {
696696
_roundingHackDisabledInDebugMode = disableRoundingHack;

lib/web_ui/test/canvaskit/text_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ void testMain() {
156156
ui.ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
157157
});
158158

159-
test('rounding hack applied by default', () {
159+
test('rounding hack disabled by default', () {
160160
const double fontSize = 1.25;
161161
const String text = '12345';
162162
assert((fontSize * text.length).truncate() != fontSize * text.length);
163-
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isFalse);
163+
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isTrue);
164164
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'));
165165
builder.addText(text);
166166
final ui.Paragraph paragraph = builder.build()
167167
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
168-
expect(paragraph.computeLineMetrics().length, greaterThan(1));
168+
expect(paragraph.computeLineMetrics().length, 1);
169169
});
170170

171171
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520

testing/dart/paragraph_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void main() {
246246
const double fontSize = 1.25;
247247
const String text = '12345';
248248
assert((fontSize * text.length).truncate() != fontSize * text.length);
249+
// ignore: deprecated_member_use
249250
final bool roundingHackWasDisabled = ParagraphBuilder.shouldDisableRoundingHack;
250251
ParagraphBuilder.setDisableRoundingHack(true);
251252
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
@@ -263,15 +264,16 @@ void main() {
263264
ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
264265
});
265266

266-
test('rounding hack applied by default', () {
267+
test('rounding hack disabled by default', () {
267268
const double fontSize = 1.25;
268269
const String text = '12345';
269270
assert((fontSize * text.length).truncate() != fontSize * text.length);
270-
expect(ParagraphBuilder.shouldDisableRoundingHack, isFalse);
271+
// ignore: deprecated_member_use
272+
expect(ParagraphBuilder.shouldDisableRoundingHack, isTrue);
271273
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
272274
builder.addText(text);
273275
final Paragraph paragraph = builder.build()
274276
..layout(const ParagraphConstraints(width: text.length * fontSize));
275-
expect(paragraph.computeLineMetrics().length, greaterThan(1));
277+
expect(paragraph.computeLineMetrics().length, 1);
276278
});
277279
}

0 commit comments

Comments
 (0)