@@ -1154,47 +1154,31 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
1154
1154
if weight != 400 :
1155
1155
font_parts .append (f'{ weight } ' )
1156
1156
1157
- def _format_font_name (fn ):
1158
- normalize_names = {
1159
- 'sans' : 'sans-serif' ,
1160
- 'sans serif' : 'sans-serif'
1161
- }
1162
- # A generic font family. We need to do two things:
1163
- # 1. list all of the configured fonts with quoted names
1164
- # 2. append the generic name unquoted
1157
+ def _normalize_sans (name ):
1158
+ return 'sans-serif' if name in ['sans' , 'sans serif' ] else name
1159
+
1160
+ def _expand_family_entry (fn ):
1161
+ fn = _normalize_sans (fn )
1162
+ # prepend generic font families with all configured font names
1165
1163
if fn in fm .font_family_aliases :
1166
- # fix spelling of sans-serif
1167
- # we accept 3 ways CSS only supports 1
1168
- fn = normalize_names .get (fn , fn )
1169
1164
# get all of the font names and fix spelling of sans-serif
1170
- # if it comes back
1171
- aliases = [
1172
- normalize_names .get (_ , _ ) for _ in
1173
- fm .FontManager ._expand_aliases (fn )
1174
- ]
1175
- # make sure the generic name appears at least once
1176
- # duplicate is OK, next layer will deduplicate
1177
- aliases .append (fn )
1178
-
1179
- for a in aliases :
1180
- # generic font families must not be quoted
1181
- if a in fm .font_family_aliases :
1182
- yield a
1183
- # specific font families must be quoted
1184
- else :
1185
- yield repr (a )
1186
- # specific font families must be quoted
1187
- else :
1188
- yield repr (fn )
1189
-
1190
- def _get_all_names (prop ):
1191
- for f in prop .get_family ():
1192
- yield from _format_font_name (f )
1165
+ # (we accept 3 ways CSS only supports 1)
1166
+ for name in fm .FontManager ._expand_aliases (fn ):
1167
+ yield _normalize_sans (name )
1168
+ # whether a generic name or a family name, it must appear at
1169
+ # least once
1170
+ yield fn
1171
+
1172
+ def _get_all_quoted_names (prop ):
1173
+ # only quote specific names, not generic names
1174
+ return [name if name in fm .font_family_aliases else repr (name )
1175
+ for entry in prop .get_family ()
1176
+ for name in _expand_family_entry (entry )]
1193
1177
1194
1178
font_parts .extend ([
1195
1179
f'{ _short_float_fmt (prop .get_size ())} px' ,
1196
- # ensure quoting and expansion of font names
1197
- ", " .join (dict .fromkeys (_get_all_names (prop )))
1180
+ # ensure expansion, quoting, and dedupe of font names
1181
+ ", " .join (dict .fromkeys (_get_all_quoted_names (prop )))
1198
1182
])
1199
1183
style ['font' ] = ' ' .join (font_parts )
1200
1184
if prop .get_stretch () != 'normal' :
0 commit comments