@@ -99,9 +99,11 @@ class FontCollection {
9999class 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"[.,:;!`\/#\$\%\^&~\*=\-_(){}]" );
102+ // Regular expression to detect a string with no punctuations.
103+ // For example font family 'Ahem!' does not fall into this category
104+ // so the family name will be wrapped in quotes.
105+ static final RegExp notPunctuation =
106+ RegExp (r"[a-z0-9\s]+" , caseSensitive: false );
105107 // Regular expression to detect tokens starting with a digit.
106108 // For example font family 'Goudy Bookletter 1911' falls into this
107109 // category.
@@ -140,8 +142,8 @@ class FontManager {
140142 ///
141143 /// In order to avoid all these browser compatibility issues this method:
142144 /// * Detects the family names that might cause a conflict.
143- /// * Loads it with quotes.
144- /// * Loads it again without quotes.
145+ /// * Loads it with the quotes.
146+ /// * Loads it again without the quotes.
145147 /// * For all the other family names [html.FontFace] is loaded only once.
146148 ///
147149 /// See also:
@@ -153,16 +155,13 @@ class FontManager {
153155 String asset,
154156 Map <String , String > descriptors,
155157 ) {
156- // Fonts names when a package dependency is added has '/' in the family
157- // names such as 'package/material_design_icons_flutter/...'
158- if (family.contains ('/' ) ||
159- punctuations.hasMatch (family) ||
160- startWithDigit.hasMatch (family)) {
161- // Load a font family name with special chracters once here wrapped in
158+ if (startWithDigit.hasMatch (family) ||
159+ notPunctuation.stringMatch (family) != family) {
160+ // Load a font family name with special characters once here wrapped in
162161 // quotes.
163- _loadFontFace ("' $family '" , asset, descriptors);
162+ _loadFontFace (' \' $family \' ' , asset, descriptors);
164163 }
165- // Load all font fonts, without quoted family names.
164+ // Load all fonts, without quoted family names.
166165 _loadFontFace (family, asset, descriptors);
167166 }
168167
0 commit comments