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

Commit 09a704c

Browse files
author
nturgut
committed
Documentation, renaming, gramatical/spelling error related PR comments addressed. Regexp will be addressed in the next commit.
1 parent 6c0b4f3 commit 09a704c

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
@@ -103,6 +103,14 @@ class FontCollection {
103103
class FontManager {
104104
final List<Future<void>> _fontLoadingFutures = <Future<void>>[];
105105

106+
// Regular expression to detect punctuations. For example font family
107+
// 'Ahem!' falls into this category.
108+
static final RegExp punctuations = RegExp(r"[.,:;!`\/#\$\%\^&~\*=\-_(){}]");
109+
// Regular expression to detect tokens starting with a digit.
110+
// For example font family 'Goudy Bookletter 1911' falls into this
111+
// category.
112+
static final RegExp startWithDigit = RegExp(r"\b\d");
113+
106114
factory FontManager() {
107115
if (supportsFontLoadingApi) {
108116
return FontManager._();
@@ -115,45 +123,48 @@ class FontManager {
115123

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

0 commit comments

Comments
 (0)