File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2361,6 +2361,10 @@ def to_static(
23612361 # instantiate the static font
23622362 instancer .instantiateVariableFont (font , coordinates , ** options )
23632363
2364+ # remove STAT table
2365+ # not useful in static fonts and after instancing it may contain incorrect values
2366+ self ._remove_stat_table ()
2367+
23642368 # update name records and style flags based on instance style name
23652369 if instance and update_names :
23662370 self .rename (
@@ -2375,6 +2379,19 @@ def to_static(
23752379 if has_italic or has_slant :
23762380 self .set_style_flags (regular = False , italic = True )
23772381
2382+ def _remove_stat_table (self ) -> bool :
2383+ """
2384+ Removes the STAT table from the font.
2385+
2386+ :returns: True if the STAT table was removed, False if it was not present.
2387+ :rtype: bool
2388+ """
2389+ font = self .get_ttfont ()
2390+ if "STAT" in font :
2391+ del font ["STAT" ]
2392+ return True
2393+ return False
2394+
23782395 def __str__ (
23792396 self ,
23802397 ) -> str :
Original file line number Diff line number Diff line change 1+ from fontbro import Font
12from tests import AbstractTestCase
23
34
@@ -131,6 +132,20 @@ def test_to_static_without_update_names_without_update_style_flags_and_italic_in
131132 )
132133 self .assertFalse (font .get_style_flag ("italic" ))
133134
135+ def test_to_static_removes_stat_table (self ):
136+ font = self ._get_variable_font ()
137+ self .assertIn ("STAT" , font .get_ttfont ())
138+ font .to_static (coordinates = {"wght" : 400 , "wdth" : 100 })
139+ self .assertNotIn ("STAT" , font .get_ttfont ())
140+
141+ def test_to_static_stat_table_not_present_in_saved_file (self ):
142+ font = self ._get_variable_font ()
143+ font .to_static (coordinates = {"wght" : 400 , "wdth" : 100 })
144+ output_filepath = self ._get_font_temp_path ("" )
145+ font_saved_filepath = font .save (output_filepath , overwrite = True )
146+ font_saved = Font (font_saved_filepath )
147+ self .assertNotIn ("STAT" , font_saved .get_ttfont ())
148+
134149 def test_to_sliced_variable_with_static_font (self ):
135150 font = self ._get_static_font ()
136151 with self .assertRaises (TypeError ):
You can’t perform that action at this time.
0 commit comments