@@ -36,8 +36,18 @@ def get_fontawesome():
3636 return cached_path
3737
3838
39- def save_icon (fig , dest_dir , name ):
40- fig .savefig (dest_dir / (name + '.svg' ))
39+ def save_icon (fig , dest_dir , name , add_black_fg_color ):
40+ if add_black_fg_color :
41+ # Add explicit black foreground color to monochromatic svg icons
42+ # so it can be replaced by backends to add dark theme support
43+ svg_bytes_io = BytesIO ()
44+ fig .savefig (svg_bytes_io , format = 'svg' )
45+ svg = svg_bytes_io .getvalue ()
46+ before , sep , after = svg .rpartition (b'\n z\n "' )
47+ svg = before + sep + b' style="fill:black;"' + after
48+ (dest_dir / (name + '.svg' )).write_bytes (svg )
49+ else :
50+ fig .savefig (dest_dir / (name + '.svg' ))
4151 fig .savefig (dest_dir / (name + '.pdf' ))
4252 for dpi , suffix in [(24 , '' ), (48 , '_large' )]:
4353 fig .savefig (dest_dir / (name + suffix + '.png' ), dpi = dpi )
@@ -102,9 +112,9 @@ def make_icons():
102112 font_path = get_fontawesome ()
103113 for name , ccode in icon_defs :
104114 fig = make_icon (font_path , ccode )
105- save_icon (fig , args .dest_dir , name )
115+ save_icon (fig , args .dest_dir , name , True )
106116 fig = make_matplotlib_icon ()
107- save_icon (fig , args .dest_dir , 'matplotlib' )
117+ save_icon (fig , args .dest_dir , 'matplotlib' , False )
108118
109119
110120if __name__ == "__main__" :
0 commit comments