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

Commit b47feac

Browse files
author
nturgut
committed
Documentation, renaming, gramatical/spelling error related PR comments addressed. Regexp will be addressed in the next commit.
1 parent 4b662ed commit b47feac

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

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

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ class FontCollection {
9999
class FontManager {
100100
final List<Future<void>> _fontLoadingFutures = <Future<void>>[];
101101

102+
// Regular expression to detect punctuations. For example font family
103+
// 'Ahem!' falls into this category.
104+
static final RegExp punctuations = RegExp(r"[.,:;!`\/#\$\%\^&~\*=\-_(){}]");
105+
// Regular expression to detect tokens starting with a digit.
106+
// For example font family 'Goudy Bookletter 1911' falls into this
107+
// category.
108+
static final RegExp startWithDigit = RegExp(r"\b\d");
109+
102110
factory FontManager() {
103111
if (supportsFontLoadingApi) {
104112
return FontManager._();
@@ -111,45 +119,48 @@ class FontManager {
111119

112120
/// Registers assets to Flutter Web Engine.
113121
///
114-
/// Browsers and browesers versions differ siginificantly on how a valid font
122+
/// Browsers and browsers versions differ significantly on how a valid font
115123
/// family name should be formatted. Notable issues are:
116-
/// Safari12 and Firefox crash if you create a [html.FontFace] with a font
117-
/// family that is not correct CSS syntax. Font family names accepted on these
118-
/// browsers, when wrapped it in quotes.
119-
/// Additionally, for Safari12 to work [html.FontFace] name should be loaded
120-
/// correctly on the first try.
121-
/// A font in Chrome chrashes if a [html.FontFace] is loaded only with quotes.
122-
/// Unlike Safari12 if a valid version is loaded afterwards it will show
123-
/// that fonts normally.
124+
///
125+
/// Safari 12 and Firefox crash if you create a [html.FontFace] with a font
126+
/// family that is not correct CSS syntax. Font family names with invalid
127+
/// characters are accepted accepted on these browsers, when wrapped it in
128+
/// quotes.
129+
///
130+
/// Additionally, for Safari 12 to work [html.FontFace] name should be
131+
/// loaded correctly on the first try.
132+
///
133+
/// A font in Chrome is not usable other than inside a '<p>' tag, if a
134+
/// [html.FontFace] is loaded wrapped with quotes. Unlike Safari 12 if a
135+
/// valid version of the font is also loaded afterwards it will show
136+
/// that font normally.
137+
///
124138
/// In Safari 13 the [html.FontFace] should be loaded with unquoted family
125139
/// names.
126-
/// In order to avoid all these browser compatibility issues this method;
127-
/// detects the family names that might cause a conflict, loads it with
128-
/// quotes and loads it again without quotes. For all the other family names
129-
/// [html.FontFace] is loaded only once.
130-
/// See: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#Valid_family_names
131-
/// See: https://drafts.csswg.org/css-fonts-3/#font-family-prop
140+
///
141+
/// In order to avoid all these browser compatibility issues this method:
142+
/// * Detects the family names that might cause a conflict.
143+
/// * Loads it with quotes.
144+
/// * Loads it again without quotes.
145+
/// * For all the other family names [html.FontFace] is loaded only once.
146+
///
147+
/// See also:
148+
///
149+
/// * https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#Valid_family_names
150+
/// * https://drafts.csswg.org/css-fonts-3/#font-family-prop
132151
void registerAsset(
133152
String family,
134153
String asset,
135154
Map<String, String> descriptors,
136155
) {
137-
final String familyNameInQuotes = "'$family'";
138-
// Regular expression to detect punctuations. For example font family
139-
// 'Ahem!' falls into this category.
140-
final RegExp punctuations = RegExp(r"[.,:;!`\/#\$\%\^&~\*=\-_(){}]");
141-
// Regular expression to detect tokens starting with a digit.
142-
// For example font family 'Goudy Bookletter 1911' falls into this
143-
// category.
144-
final RegExp startWithDigit = RegExp(r"\b\d");
145156
// Fonts names when a package dependency is added has '/' in the family
146157
// names such as 'package/material_design_icons_flutter/...'
147158
if (family.contains('/') ||
148159
punctuations.hasMatch(family) ||
149160
startWithDigit.hasMatch(family)) {
150161
// Load a font family name with special chracters once here wrapped in
151162
// quotes.
152-
_loadFontFace(familyNameInQuotes, asset, descriptors);
163+
_loadFontFace("'$family'", asset, descriptors);
153164
}
154165
// Load all font fonts, without quoted family names.
155166
_loadFontFace(family, asset, descriptors);

0 commit comments

Comments
 (0)