@@ -185,10 +185,14 @@ def preferred_family(self, short_alternative = False):
185
185
# When short_alternative we get the short named alternative needed for some Windows applications
186
186
(name , rest ) = self ._shortened_name ()
187
187
if short_alternative :
188
+ # Try to come up with a shortened family name
189
+ # This is in principle the code from family() but without including weights
190
+ # because weights shall still end up in ID 17
188
191
other = self .other_token
189
192
if self .use_short_families [1 ]:
190
193
[ other ] = FontnameTools .short_styles ([ other ], self .use_short_families [2 ])
191
194
pfn = FontnameTools .concat (name , rest , other , self .short_family_suff )
195
+ # Only return something if it is different to our standard behavior
192
196
if pfn == self .preferred_family (False ):
193
197
return ''
194
198
return pfn
@@ -198,7 +202,7 @@ def preferred_family(self, short_alternative = False):
198
202
return ''
199
203
return pfn
200
204
201
- def preferred_styles (self ):
205
+ def preferred_styles (self , _ = False ):
202
206
"""Get the SFNT Preferred Styles (ID 17)"""
203
207
styles = self .style_token
204
208
weights = self .weight_token
@@ -305,6 +309,18 @@ def check_weights(self, font):
305
309
os2_weight , ps_weight , name_weight ,
306
310
font .os2_weight , font .weight , weight ))
307
311
312
+ def pfam_to_sfnt (self , name_function , entry , message ):
313
+ """Prepare SFNT entries for short and long form as two different languages"""
314
+ languages = [ 'English (US)' , 'English (British)' ]
315
+ names = [ name_function (False ), name_function (True ) ]
316
+ ret = [ ]
317
+ for i in range (2 ):
318
+ if len (names [i ]):
319
+ ret += [( languages [i ], entry , self .checklen (31 , message , names [i ]) )]
320
+ else :
321
+ break
322
+ return ret
323
+
308
324
def rename_font (self , font ):
309
325
"""Rename the font to include all information we found (font is fontforge font object)"""
310
326
font .fondname = None
@@ -358,19 +374,8 @@ def rename_font(self, font):
358
374
sfnt_list += [( 'English (US)' , 'UniqueID' , self .fullname () + version_tag )] # 3
359
375
sfnt_list += [( 'English (US)' , 'Fullname' , self .checklen (63 , 'Fullname (ID 4)' , self .fullname ()) )] # 4
360
376
sfnt_list += [( 'English (US)' , 'PostScriptName' , self .checklen (63 , 'PSN (ID 6)' , self .psname ()) )] # 6
361
-
362
- p_fam = self .preferred_family (False )
363
- if len (p_fam ):
364
- sfnt_list += [( 'English (US)' , 'Preferred Family' , self .checklen (31 , 'PrefFamily (ID 16)' , p_fam ) )] # 16
365
- p_fam = self .preferred_family (True )
366
- if len (p_fam ):
367
- sfnt_list += [( 'English (British)' , 'Preferred Family' , self .checklen (31 , 'PrefFamily (ID 16)' , p_fam ) )]
368
- p_sty = self .preferred_styles ()
369
- if len (p_sty ):
370
- sfnt_list += [( 'English (US)' , 'Preferred Styles' , self .checklen (31 , 'PrefStyles (ID 17)' , p_sty ) )] # 17
371
- if len (p_fam ):
372
- # Set only if ID16 for British has been set
373
- sfnt_list += [( 'English (British)' , 'Preferred Styles' , self .checklen (31 , 'PrefStyles (ID 17)' , p_sty ) )]
377
+ sfnt_list += self .pfam_to_sfnt (self .preferred_family , 'Preferred Family' , 'PrefFamily (ID 16)' ) # 16
378
+ sfnt_list += self .pfam_to_sfnt (self .preferred_styles , 'Preferred Styles' , 'PrefStyles (ID 17)' ) # 17
374
379
375
380
font .sfnt_names = tuple (sfnt_list )
376
381
0 commit comments