Use aligned toolbar icons and updated app icon. - #32095
Conversation
timhoffm
left a comment
There was a problem hiding this comment.
Thanks, this is great! I've always wondered why the buttons looked slightly blurry, but thought that's just the way it is.
Note that various backends will still have slightly blurry lines, depending on your exact configuration. qt/wx/gtk use the SVG icons and then scale them based on the user's DPI setting. There's no way to ensure pixel boundary snapping in this case. That said, it should be no worse than before this change. What this prevents is a situation where a backend is scaling twice. Prior to this change, a backend could use an already-blurry image as the source and then scale it again. Similarly, the macosx backend was using the non-pixel-aligned PDF file, rendering it to the screen buffer with blurry lines, and then re-scaling the whole screen buffer to fit the physical screen. (macOS/iOS have no concept of non-integral scale factors. Typically everything is rendered at 2x in app-land and the screen buffer is later downscaled in hardware-land to match the physical screen). |
|
I updated make_icons.py to use |
PR summary
Toolbar Icon Alignment
Previously, toolbar icons were generated directly from the Font Awesome 4.7 font and exported to SVG, PDF, 24x24 PNG, and 48x48 PNG files. This approach had a few issues. Most notably, the icons were not vertically aligned. This was especially noticeable with the "home" and "subplot" icons on newer versions of macOS:
If we zoom in and measure, there is a 19px padding on the top of the house and only a 10px-10.5px padding on the bottom:
Other icons are better, but still slightly too low. Additionally, all icons have slightly-blurry edges as scaling has occurred and straight lines are no longer on pixel boundaries:
This is not a macOS-only problem - all backends suffer these alignment issues as the source SVGs/PNGs/PDFs are misaligned. Here's qtagg:
To solve this: I took the original icons, scaled to a target of 48x48px, and redrew them to fit on pixel boundaries. The resulting icons are both vertically aligned and sharper:
App Icon
The app icon used by various backends was using an (older?) version of the matplotlib logo:
I generated a new one based on the current logo:
Additionally,
matplotlib.pngandmatplotlib_large.pngwere 24px and 48px respectively, matching the toolbar icons. I'm not sure why 24px was chosen. As far as I can tell, Windows historically used 32px as a "standard" size and 48px for "large".I changed
matplotlib.pngto be a 256px. This seems to be the maximum size for Windows and Linux when targetting high-resolution displays.I also generated a 32px icon with slightly more contrast to use as a smaller variant:
Here's a chart showing the file names, old size, and new size. I'm fairly sure that I updated all code paths where these files were used. I can try another approach if we need to maintain the old sizes for compatibility reasons.
make_icons.py
The
tools/make_icons.pyscript now loads each SVG frommpl-data/imagesand converts it to PNGs and a PDF. PNG conversion is performed via Inkscape and optipng - the same dependencies that the documentation uses. PDF conversion is handled by pikepdf.Due to the use of optipng and by-hand-SVG-optimization, the content size of the mpl-data directory went from ~141k to ~79k.
AI Disclosure
make_icons.pyscript. I fully understand all lines of said script and was capable of coding it without any AI guidance._backend_gtk.py. This is the one file that I'm not confident in as I'm not sure how to test my changes. Any guidance is appreciated!PR checklist
Questions:
mpl-data/imagesto store both the input SVG files and the output files. I'd like for the input SVG files to have more comments that would get stripped when copied tompl-data/images. Is there a location where input assets could be stored that's notmpl-data/images? I'll need such a location for [ENH]: macOS backend should match system app icons #31895.