Skip to content

Commit 3b643d4

Browse files
committed
Explicitly set foreground color to black in svg icons. make_icons script adds style="fill:black;" to monochromatic icons
1 parent 5f785e3 commit 3b643d4

File tree

10 files changed

+23
-13
lines changed

10 files changed

+23
-13
lines changed

lib/matplotlib/mpl-data/images/back.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/filesave.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/forward.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/help.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/home.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/move.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/qt4_editor_options.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/subplots.svg

Lines changed: 1 addition & 1 deletion
Loading

lib/matplotlib/mpl-data/images/zoom_to_rect.svg

Lines changed: 1 addition & 1 deletion
Loading

tools/make_icons.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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'\nz\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

110120
if __name__ == "__main__":

0 commit comments

Comments
 (0)