Skip to content

Explicitly set foreground color to black in svg icons #26731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/filesave.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/forward.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/move.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/qt4_editor_options.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/subplots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/images/zoom_to_rect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions tools/make_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ def get_fontawesome():
return cached_path


def save_icon(fig, dest_dir, name):
fig.savefig(dest_dir / (name + '.svg'))
def save_icon(fig, dest_dir, name, add_black_fg_color):
if add_black_fg_color:
# Add explicit black foreground color to monochromatic svg icons
# so it can be replaced by backends to add dark theme support
svg_bytes_io = BytesIO()
fig.savefig(svg_bytes_io, format='svg')
svg = svg_bytes_io.getvalue()
before, sep, after = svg.rpartition(b'\nz\n"')
svg = before + sep + b' style="fill:black;"' + after
(dest_dir / (name + '.svg')).write_bytes(svg)
else:
fig.savefig(dest_dir / (name + '.svg'))
fig.savefig(dest_dir / (name + '.pdf'))
for dpi, suffix in [(24, ''), (48, '_large')]:
fig.savefig(dest_dir / (name + suffix + '.png'), dpi=dpi)
Expand Down Expand Up @@ -102,9 +112,9 @@ def make_icons():
font_path = get_fontawesome()
for name, ccode in icon_defs:
fig = make_icon(font_path, ccode)
save_icon(fig, args.dest_dir, name)
save_icon(fig, args.dest_dir, name, True)
fig = make_matplotlib_icon()
save_icon(fig, args.dest_dir, 'matplotlib')
save_icon(fig, args.dest_dir, 'matplotlib', False)


if __name__ == "__main__":
Expand Down