Skip to content

Implement font fallback#187520

Open
Rusino wants to merge 4 commits into
flutter:masterfrom
Rusino:fallback
Open

Implement font fallback#187520
Rusino wants to merge 4 commits into
flutter:masterfrom
Rusino:fallback

Conversation

@Rusino
Copy link
Copy Markdown
Contributor

@Rusino Rusino commented Jun 3, 2026

Pass the correct font line to Canvas2D
I was only able to demonstrate it working on text fonts (Sans vs Serif).

Part of #172561

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 3, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Jun 3, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for fallback font families in WebTextStyle and updates WebStrutStyle to apply styles using WebTextStyle. It also adds a test verifying fallback font rendering. Feedback on these changes highlights that unconditionally quoting the font family and bypassing canonicalizeFontFamily can break generic font families, and that fallback fonts themselves should be canonicalized. Additionally, the reviewer noted that fontFamilyFallback was omitted in WebStrutStyle's usage of WebTextStyle, and pointed out leftover commented-out code.

Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 3, 2026
@mdebbar mdebbar added the CICD Run CI/CD label Jun 3, 2026
mdebbar
mdebbar previously approved these changes Jun 3, 2026
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/test/webparagraph/paragraph_test.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/test/webparagraph/paragraph_test.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 4, 2026
@Rusino Rusino added the CICD Run CI/CD label Jun 4, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 4, 2026
@Rusino Rusino added the CICD Run CI/CD label Jun 4, 2026
@Rusino Rusino requested a review from mdebbar June 4, 2026 17:07
@Rusino Rusino self-assigned this Jun 4, 2026
Comment on lines +557 to +596
List<String> get _fallbackFontFamilies {
if (isIOS15) {
// Remove the "-apple-system" fallback font because it causes a crash in
// iOS 15.
//
// See github issue: https://github.com/flutter/flutter/issues/90705
// See webkit bug: https://bugs.webkit.org/show_bug.cgi?id=231686
return <String>['BlinkMacSystemFont'];
}
if (isMacOrIOS) {
return <String>['-apple-system', 'BlinkMacSystemFont'];
}
return <String>['Arial'];
}

String _canonicalizeFontFamily(String? fontFamily, [List<String>? fontFamilyFallback]) {
final processedFontFamilyFallback = fontFamilyFallback == null || fontFamilyFallback.isEmpty
? ''
: '${fontFamilyFallback.map(_processFontFamily).join(', ')}, ';
return '${_processFontFamily(fontFamily)}, $processedFontFamilyFallback ${_fallbackFontFamilies.join(', ')}, sans-serif';
}

String? _processFontFamily(String? fontFamily) {
if (genericFontFamilies.contains(fontFamily)) {
return fontFamily;
}
if (isMacOrIOS) {
// Unlike Safari, Chrome on iOS does not correctly fallback to cupertino
// on sans-serif.
// Map to San Francisco Text/Display fonts, use -apple-system,
// BlinkMacSystemFont.
if (fontFamily == '.SF Pro Text' ||
fontFamily == '.SF Pro Display' ||
fontFamily == '.SF UI Text' ||
fontFamily == '.SF UI Display') {
return _fallbackFontFamilies.join(', ');
}
}
return '"$fontFamily"';
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that requires duplicating this code here instead of refactoring the one in util.dart?

Comment on lines +546 to +555
String? get sharedFontFamily;
List<String>? get sharedFontFamilyFallback;
double? get sharedFontSize;
ui.FontWeight? get sharedFontWeight;
ui.FontStyle? get sharedFontStyle;
ui.Locale? get sharedLocale => null;
List<ui.FontFeature>? get sharedFontFeature => null;
List<ui.FontVariation>? get sharedFontVariations => null;
double? get sharedLetterSpacing => null;
double? get sharedWordSpacing => null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the original property names instead of sharedXYZ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants