After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741259 - gtkmodelmenuitem: force icon scaling
gtkmodelmenuitem: force icon scaling
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 742962 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-12-08 17:43 UTC by Lars Karlitski
Modified: 2015-09-12 20:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtkmodelmenuitem: force icon scaling (4.35 KB, patch)
2014-12-08 17:43 UTC, Lars Karlitski
needs-work Details | Review
gtkimagemenuitem: force icon scaling (3.60 KB, patch)
2014-12-08 21:59 UTC, Lars Karlitski
none Details | Review
Menu items: force loading 16x16 icons (1.62 KB, patch)
2014-12-11 16:51 UTC, Lars Karlitski
committed Details | Review

Description Lars Karlitski 2014-12-08 17:43:47 UTC
The height of menu items with icons currently depends on the icon size which
the theme provides.

The attached patch forces icons in menus to be exactly as large as the text
next to them.
Comment 1 Lars Karlitski 2014-12-08 17:43:49 UTC
Created attachment 292308 [details] [review]
gtkmodelmenuitem: force icon scaling

GtkIconTheme doesn't scale icons beyond the size specified in the theme
anymore. This can result in arbitrarily large menu items when a theme
only provides large icons.

Force icons to be always the same height as the text in the menu item,
and react to font size changes.
Comment 2 Allison Karlitskaya (desrt) 2014-12-08 17:50:04 UTC
Review of attachment 292308 [details] [review]:

::: gtk/gtkmodelmenuitem.c
@@ +83,3 @@
+      height = (pango_font_metrics_get_ascent (metrics) +
+                pango_font_metrics_get_descent (metrics)) / PANGO_SCALE;
+      gtk_image_set_pixel_size (GTK_IMAGE (item->image), height);

I don't like the approach here.

You request a ICON_SIZE_MENU icon but then you scale it according to the font size.

This can be bad for at least two reasons:

 (a) you could end up scaling 16x16 up to 18x18 and making the icon distorted/blurry

 (b) even worse, if the font size is really large, you could end up picking the wrong-sized icon to start with


If you want to take this patch then it needs to be made more clever...
Comment 3 Matthias Clasen 2014-12-08 18:09:37 UTC
In particular for small sizes, the only right approach here is to fix the theme to provide the required sizes. scaling things with a target size of 16 or 20 pixels is never going to look good (unless you happen to start from an integer multiple).
Comment 4 Lars Karlitski 2014-12-08 18:11:11 UTC
(In reply to comment #3)
> In particular for small sizes, the only right approach here is to fix the theme
> to provide the required sizes. scaling things with a target size of 16 or 20
> pixels is never going to look good (unless you happen to start from an integer
> multiple).

Of course, but I don't think we should have unusable menus because of a buggy theme.
Comment 5 Matthias Clasen 2014-12-08 18:31:07 UTC
any concrete examples of problematic cases ?
Comment 6 Lars Karlitski 2014-12-08 18:42:21 UTC
(In reply to comment #5)
> any concrete examples of problematic cases ?

I've noticed it first with unity's icon theme, which misses some icons in the right sizes.

However, this is also an issue with application icons. For example, gvim installs an svg icon with width=height=550pt into /usr/share/pixmaps, which makes the GVim menu item in nautilus' open-with menu take the full size of my screen.  (That menu doesn't use GtkModelMenuItem yet, but unity's sound and messaging menus use it and have application icons in them as well.)
Comment 7 Matthias Clasen 2014-12-08 18:50:44 UTC
get a better vim :-)

$ rpm -ql vim-X11 | grep icons
/usr/share/icons/hicolor/16x16/apps/gvim.png
/usr/share/icons/hicolor/32x32/apps/gvim.png
/usr/share/icons/hicolor/48x48/apps/gvim.png
/usr/share/icons/hicolor/64x64/apps/gvim.png

but I accept the point that we can't show a 550 pixel 'icon' in the menu (or the dialog). I was 100% sure that I had added a pixel-size to the app chooser dialog for this very reason, but I can't find that commit now.
Comment 8 Lars Karlitski 2014-12-08 21:59:37 UTC
Created attachment 292335 [details] [review]
gtkimagemenuitem: force icon scaling

The same for GtkImageMenuItem. Nautilus still uses that for its open with
dialog.
Comment 9 Matthias Clasen 2014-12-09 00:15:57 UTC
Review of attachment 292335 [details] [review]:

::: gtk/deprecated/gtkimagemenuitem.c
@@ +1241,3 @@
+      height = (pango_font_metrics_get_ascent (metrics) +
+                pango_font_metrics_get_descent (metrics)) / PANGO_SCALE;
+      gtk_image_set_pixel_size (GTK_IMAGE (item->priv->image), height);

This looks really bad - very likely this will end up with a pixel size of 17 or 19 or something similarly horrible that will cause every single icon to be scaled off, even if it is a perfectly fine 16x16 or 20x20.
Comment 10 Sebastien Bacher 2014-12-09 09:32:12 UTC
@Matthias, seems like your icons are a fedora changeset
http://pkgs.fedoraproject.org/cgit/vim.git/tree/vim.spec#n1423

would be nice to get that in upstream vim so every distro could have "a better vim" ;-)
Comment 11 Matthias Clasen 2014-12-09 15:08:27 UTC
(In reply to comment #10)

> would be nice to get that in upstream vim so every distro could have "a better
> vim" ;-)

Oh, I agree. Sadly, experience shows that pushing better app icons upstream is a suprisingly difficult challenge. Not sure if that is the case here, or what...
Comment 12 Lars Karlitski 2014-12-09 16:37:50 UTC
(In reply to comment #9)
> [...]
> This looks really bad - very likely this will end up with a pixel size of 17 or
> 19 or something similarly horrible that will cause every single icon to be
> scaled off, even if it is a perfectly fine 16x16 or 20x20.

I agree that always scaling to the font size can lead to ugly artifacts at some font sizes. (I'd argue having those is better than the current situation, though.)

I think we should always scale icons that are larger than the text. A blurry icon is preferable to menu items with inconsistent heights.

However, we could allow icons to be slightly smaller than the text if we can load them without scaling. Not sure what a good value for "slightly smaller" might be, maybe 2px?
Comment 13 Cosimo Cecchi 2014-12-09 17:15:28 UTC
I very much disagree that we should always scale icons to the size of the text; blurry icons suck and we should avoid them at all costs.
I think the most flexible approach would be to load icons only at sizes compatible with the theme that are near text size, and only scale icons (but still to that exact size) when the theme does not have one for that specific size. That's similar to what the Shell does e.g. with the dash. This also has the nice property that you never end up with icons larger than what the theme gives you.
A much simpler approach is to just use GTK_ICON_SIZE_MENU without any dynamic scaling at all.
Comment 14 Lars Karlitski 2014-12-09 19:37:05 UTC
(In reply to comment #13)
> I very much disagree that we should always scale icons to the size of the text;
> blurry icons suck and we should avoid them at all costs.

I'm arguing that the cost of having inconsistently sized icons (or even menu items) is too large.

> I think the most flexible approach would be to load icons only at sizes
> compatible with the theme that are near text size, and only scale icons (but
> still to that exact size) when the theme does not have one for that specific
> size. That's similar to what the Shell does e.g. with the dash. This also has
> the nice property that you never end up with icons larger than what the theme
> gives you.

If we do it on a per-icon basis, we can still get icons of different sizes in the same menu. That's why I suggested basing it on text size. But I agree, choosing a size that is an exact match but a bit smaller is better than scaling.

> A much simpler approach is to just use GTK_ICON_SIZE_MENU without any dynamic
> scaling at all.

Well, the original problem is that gtk doesn't scale icons when the theme doesn't supply them in GTK_ICON_SIZE_MENU, but shows very large (or very small)  icons instead. Obviously these are bugs in the themes and application icons, but I think such bugs shouldn't result in a different layout of the UI.
Comment 15 Matthias Clasen 2014-12-10 03:42:36 UTC
> Obviously these are bugs in the themes and application icons,
> but I think such bugs shouldn't result in a different layout of the UI.

You are treating an obvious bug (different layout) for a more subtle one (miserable, scaled icons) - which one do you think is more likely to get fixed, and which one will linger forever ?
Comment 16 Cosimo Cecchi 2014-12-10 06:17:18 UTC
(In reply to comment #14)
> If we do it on a per-icon basis, we can still get icons of different sizes in
> the same menu. That's why I suggested basing it on text size. But I agree,
> choosing a size that is an exact match but a bit smaller is better than
> scaling.

I disagree with this statement; assuming the text size doesn't change between menu items, I think it's possible to write an implementation that always chooses icons of the same size, regardless of whether they get scaled or not.
What I'm thinking is probably best illustrated by an example: with a text size of say 30px you would choose always icons of 24px (a size that is typically offered by the theme) and only scale (to 24px) those icons that are not available at that size natively.
Comment 17 Matthias Clasen 2014-12-11 05:23:36 UTC
I think a force-scale implementation that picks pixel sizes other than 16, 20 or 24 is unacceptable, since it will force every icon to be fuzzy.
Comment 18 Lars Karlitski 2014-12-11 16:51:10 UTC
Created attachment 292547 [details] [review]
Menu items: force loading 16x16 icons

After writing quite a complex patch trying to choose the "best" icon, I
realized that this is probably not worth making the code more complex for.

Attaching a new patch which simply scales icons to 16x16, effectively restoring
the old behavior for menu items.
Comment 19 Matthias Clasen 2014-12-14 21:10:09 UTC
Review of attachment 292547 [details] [review]:

ok
Comment 20 Lars Karlitski 2014-12-17 16:52:54 UTC
Attachment 292547 [details] pushed as b44df22 - Menu items: force loading 16x16 icons
Comment 21 Lars Karlitski 2015-01-15 10:54:37 UTC
*** Bug 742962 has been marked as a duplicate of this bug. ***
Comment 22 weyer 2015-09-12 20:20:04 UTC
Please have a look at: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=773135
Seems like it is caused by this bug's fix.