@@ -103,9 +103,11 @@ class FontCollection {
103103class 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"[.,:;!`\/#\$\%\^&~\*=\-_(){}]" );
106+ // Regular expression to detect a string with no punctuations.
107+ // For example font family 'Ahem!' does not fall into this category
108+ // so the family name will be wrapped in quotes.
109+ static final RegExp notPunctuation =
110+ RegExp (r"[a-z0-9\s]+" , caseSensitive: false );
109111 // Regular expression to detect tokens starting with a digit.
110112 // For example font family 'Goudy Bookletter 1911' falls into this
111113 // category.
@@ -144,8 +146,8 @@ class FontManager {
144146 ///
145147 /// In order to avoid all these browser compatibility issues this method:
146148 /// * Detects the family names that might cause a conflict.
147- /// * Loads it with quotes.
148- /// * Loads it again without quotes.
149+ /// * Loads it with the quotes.
150+ /// * Loads it again without the quotes.
149151 /// * For all the other family names [html.FontFace] is loaded only once.
150152 ///
151153 /// See also:
@@ -157,16 +159,13 @@ class FontManager {
157159 String asset,
158160 Map <String , String > descriptors,
159161 ) {
160- // Fonts names when a package dependency is added has '/' in the family
161- // names such as 'package/material_design_icons_flutter/...'
162- if (family.contains ('/' ) ||
163- punctuations.hasMatch (family) ||
164- startWithDigit.hasMatch (family)) {
165- // Load a font family name with special chracters once here wrapped in
162+ if (startWithDigit.hasMatch (family) ||
163+ notPunctuation.stringMatch (family) != family) {
164+ // Load a font family name with special characters once here wrapped in
166165 // quotes.
167- _loadFontFace ("' $family '" , asset, descriptors);
166+ _loadFontFace (' \' $family \' ' , asset, descriptors);
168167 }
169- // Load all font fonts, without quoted family names.
168+ // Load all fonts, without quoted family names.
170169 _loadFontFace (family, asset, descriptors);
171170 }
172171
0 commit comments