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

Commit 38f6665

Browse files
author
Harry Terkelsen
authored
Set strut font to Roboto if the given font hasn't been registered (#22129)
1 parent 9ccf9f1 commit 38f6665

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ class CkParagraphStyle implements ui.ParagraphStyle {
7575
EngineStrutStyle style = value as EngineStrutStyle;
7676
final SkStrutStyleProperties skStrutStyle = SkStrutStyleProperties();
7777
if (style._fontFamily != null) {
78-
final List<String> fontFamilies = <String>[style._fontFamily!];
78+
String fontFamily = style._fontFamily!;
79+
if (!skiaFontCollection.registeredFamilies.contains(fontFamily)) {
80+
fontFamily = 'Roboto';
81+
}
82+
final List<String> fontFamilies = <String>[fontFamily];
7983
if (style._fontFamilyFallback != null) {
8084
fontFamilies.addAll(style._fontFamilyFallback!);
8185
}
@@ -531,10 +535,10 @@ class CkParagraph extends ManagedSkiaObject<SkParagraph>
531535
for (int i = 0; i < skRects.length; i++) {
532536
final List<double> rect = skRects[i];
533537
result.add(ui.TextBox.fromLTRBD(
534-
rect[0],
535-
rect[1],
536-
rect[2],
537-
rect[3],
538+
rect[0],
539+
rect[1],
540+
rect[2],
541+
rect[3],
538542
_paragraphStyle._textDirection!,
539543
));
540544
}
@@ -563,20 +567,10 @@ class CkParagraph extends ManagedSkiaObject<SkParagraph>
563567
assert(constraints.width != null); // ignore: unnecessary_null_comparison
564568
_lastLayoutConstraints = constraints;
565569

566-
// Infinite width breaks layout, just use a very large number instead.
567-
// TODO(het): Remove this once https://bugs.chromium.org/p/skia/issues/detail?id=9874
568-
// is fixed.
569-
double width;
570-
const double largeFiniteWidth = 1000000;
571-
if (constraints.width.isInfinite) {
572-
width = largeFiniteWidth;
573-
} else {
574-
width = constraints.width;
575-
}
576570
// TODO(het): CanvasKit throws an exception when laid out with
577571
// a font that wasn't registered.
578572
try {
579-
skiaObject.layout(width);
573+
skiaObject.layout(constraints.width);
580574
} catch (e) {
581575
html.window.console.warn('CanvasKit threw an exception while laying '
582576
'out the paragraph. The font was "${_paragraphStyle._fontFamily}". '

0 commit comments

Comments
 (0)