Thanks to visit codestin.com
Credit goes to github.com

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

Commit aedc37a

Browse files
tests to verify the default is to apply the hack
1 parent 18b5b77 commit aedc37a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

lib/ui/text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ abstract class ParagraphBuilder {
30243024
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
30253025
|| _roundingHackDisabledInDebugMode;
30263026
}
3027-
static bool _roundingHackDisabledInDebugMode = true;
3027+
static bool _roundingHackDisabledInDebugMode = false;
30283028

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

lib/web_ui/lib/text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ abstract class ParagraphBuilder {
690690
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
691691
|| _roundingHackDisabledInDebugMode;
692692
}
693-
static bool _roundingHackDisabledInDebugMode = true;
693+
static bool _roundingHackDisabledInDebugMode = false;
694694
static void setDisableRoundingHack(bool disableRoundingHack) {
695695
assert(() {
696696
_roundingHackDisabledInDebugMode = disableRoundingHack;

lib/web_ui/test/canvaskit/text_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ void testMain() {
146146
}
147147
ui.ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
148148
});
149+
150+
test('rounding hack applied by default', () {
151+
const double fontSize = 1.25;
152+
const String text = '12345';
153+
assert((fontSize * text.length).truncate() != fontSize * text.length);
154+
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isFalse);
155+
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: fontSize));
156+
builder.addText(text);
157+
final ui.Paragraph paragraph = builder.build()
158+
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
159+
expect(paragraph.maxIntrinsicWidth, greaterThan(text.length * fontSize));
160+
});
161+
149162
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
150163
}, skip: isSafari || isFirefox);
151164
}

testing/dart/paragraph_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,16 @@ void main() {
254254
}
255255
ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
256256
});
257+
258+
test('rounding hack applied by default', () {
259+
const double fontSize = 1.25;
260+
const String text = '12345';
261+
assert((fontSize * text.length).truncate() != fontSize * text.length);
262+
expect(ParagraphBuilder.shouldDisableRoundingHack, isFalse);
263+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
264+
builder.addText(text);
265+
final Paragraph paragraph = builder.build()
266+
..layout(const ParagraphConstraints(width: text.length * fontSize));
267+
expect(paragraph.maxIntrinsicWidth, greaterThan(text.length * fontSize));
268+
});
257269
}

0 commit comments

Comments
 (0)