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

Commit 43c80b9

Browse files
tests
1 parent 6de46a3 commit 43c80b9

3 files changed

Lines changed: 64 additions & 31 deletions

File tree

lib/web_ui/lib/src/engine/canvaskit/renderer.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ class CanvasKitRenderer implements Renderer {
329329
strutStyle: strutStyle,
330330
ellipsis: ellipsis,
331331
locale: locale,
332+
applyRoundingHack: applyRoundingHack,
332333
);
333334

334335
@override

lib/web_ui/test/canvaskit/text_test.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,40 @@ void testMain() {
122122
}
123123
});
124124
});
125+
126+
test('applyRoundingHack defaults to true', () {
127+
const double fontSize = 1.25;
128+
const String text = '12345';
129+
assert((fontSize * text.length).truncate() != fontSize * text.length);
130+
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
131+
ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'),
132+
);
133+
builder.addText(text);
134+
final ui.Paragraph paragraph = builder.build()
135+
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
136+
137+
expect(paragraph.computeLineMetrics(), hasLength(2));
138+
});
139+
140+
test('applyRoundingHack works', () {
141+
const double fontSize = 1.25;
142+
const String text = '12345';
143+
assert((fontSize * text.length).truncate() != fontSize * text.length);
144+
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
145+
ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest', applyRoundingHack: false),
146+
);
147+
builder.addText(text);
148+
final ui.Paragraph paragraph = builder.build()
149+
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
150+
151+
expect(paragraph.maxIntrinsicWidth, text.length * fontSize);
152+
switch (paragraph.computeLineMetrics()) {
153+
case [ui.LineMetrics(width: final double width)]:
154+
expect(width, text.length * fontSize);
155+
case final List<ui.LineMetrics> metrics:
156+
expect(metrics, hasLength(1));
157+
}
158+
});
125159
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
126160
}, skip: isSafari || isFirefox);
127-
128161
}

testing/dart/paragraph_test.dart

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -234,34 +234,33 @@ void main() {
234234
}
235235
});
236236

237-
test('applyRoundingHack defaults to true', () {
238-
const double fontSize = 1.25;
239-
const String text = '12345';
240-
assert((fontSize * text.length).truncate() != fontSize * text.length);
241-
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
242-
builder.addText(text);
243-
final Paragraph paragraph = builder.build()
244-
..layout(const ParagraphConstraints(width: text.length * fontSize));
245-
246-
expect(paragraph.maxIntrinsicWidth, greaterThan(text.length * fontSize));
247-
expect(paragraph.computeLineMetrics(), hasLength(2));
248-
});
249-
250-
test('applyRoundingHack works', () {
251-
const double fontSize = 1.25;
252-
const String text = '12345';
253-
assert((fontSize * text.length).truncate() != fontSize * text.length);
254-
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize, applyRoundingHack: false));
255-
builder.addText(text);
256-
final Paragraph paragraph = builder.build()
257-
..layout(const ParagraphConstraints(width: text.length * fontSize));
258-
259-
expect(paragraph.maxIntrinsicWidth, text.length * fontSize);
260-
switch (paragraph.computeLineMetrics()) {
261-
case [LineMetrics(width: final double width)]:
262-
expect(width, text.length * fontSize);
263-
case final List<LineMetrics> metrics:
264-
expect(metrics, hasLength(1));
265-
}
266-
});
237+
test('applyRoundingHack defaults to true', () {
238+
const double fontSize = 1.25;
239+
const String text = '12345';
240+
assert((fontSize * text.length).truncate() != fontSize * text.length);
241+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
242+
builder.addText(text);
243+
final Paragraph paragraph = builder.build()
244+
..layout(const ParagraphConstraints(width: text.length * fontSize));
245+
246+
expect(paragraph.computeLineMetrics(), hasLength(2));
247+
});
248+
249+
test('applyRoundingHack works', () {
250+
const double fontSize = 1.25;
251+
const String text = '12345';
252+
assert((fontSize * text.length).truncate() != fontSize * text.length);
253+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize, applyRoundingHack: false));
254+
builder.addText(text);
255+
final Paragraph paragraph = builder.build()
256+
..layout(const ParagraphConstraints(width: text.length * fontSize));
257+
258+
expect(paragraph.maxIntrinsicWidth, text.length * fontSize);
259+
switch (paragraph.computeLineMetrics()) {
260+
case [LineMetrics(width: final double width)]:
261+
expect(width, text.length * fontSize);
262+
case final List<LineMetrics> metrics:
263+
expect(metrics, hasLength(1));
264+
}
265+
});
267266
}

0 commit comments

Comments
 (0)