jdtsmith / kind-icon

Completion kind text/icon prefix labelling for emacs in-region completion
GNU Affero General Public License v3.0
174 stars 4 forks source link

Icon size not respect display scale factor #22

Closed jilen closed 2 years ago

jilen commented 2 years ago

image

Icon looks quite large, with a 125% scale factor on 4k display.

jdtsmith commented 2 years ago

Did you change the font? If so M-x kind-icon-reset-cache. If not, you can reduce the :height; see #18.

jilen commented 2 years ago
(kind-icon-default-style 
   '(:padding 0 :stroke 0 :margin 0 :radius 0 :height 0.5 :scale 1))

image Reduce height works, but the width of icon seems not changed.

jdtsmith commented 2 years ago

Something is up with your font sizes. The width should be precisely 2 characters, so your characters are "large". What does M-: (default-font-width) Ret say for you? Also, try disabling that fancy proportional font for the annotation (which looks to be cut off anyway). Does that change the size?

Also, try evaluating these in your *scratch* buffer:

(require 'svg-lib)

(insert "\n"
    (propertize "  " 'display
            (svg-lib-icon "key-variant" nil
                  :padding 0 :stroke 0 :margin 0 :radius 0 :height 1.0 :scale 1.0)))

Does the key look normal sized?

jilen commented 2 years ago

Note I've set the scale factor to 1.25, which might cause the incorrect svg icon size calculation.

jdtsmith commented 2 years ago

Which scale factor is 1.25? An emacs setting? A default width of 20 is quite large; mine is 7.

Since svg-lib shows a large icon, this isn't really a kind-icon issue. Instead, it's an svg-lib issue with your unusual font settings. If you can't get those fixed, I suggest playing with the values of :height and/or :scale. Note that width is always exactly two characters wide, so in your case, 40 pixels (however you monitor interprets that).

jilen commented 2 years ago

@jdtsmith Screen scale factor. Since I use a 4k display. Font is too small without scale.

Are there any option to use all-the-icons? I found it works just fine.

jilen commented 2 years ago

Switch to emacs-pgtk branch seems get problem solved

jdtsmith commented 2 years ago

Interesting. Must be an emacs issue with large fonts. screen scale shouldn’t matter since it affects everything.

jilen commented 2 years ago

Maybe related to font dpi. Since the scale factor setting in gnome might change font dpi.

shouya commented 2 years ago

With

(setq kind-icon-default-style 
   '(:padding 0 :stroke 0 :margin 0 :radius 0 :height 0.5 :scale 1))

I'm getting icons with extra padding around the sides which makes it unecessarily wide:

image

I traced it down to some hard-coded padding size around about the icon width in svg-lib, which I don't really get the purpose for. However, I figured out it's possible to get around the effect by specifying a negative padding:

(setq kind-icon-default-style 
   '(:padding -1 :stroke 0 :margin 0 :radius 0 :height 0.5 :scale 1))

Now the icon size is expected:

image

shouya commented 2 years ago
(insert (let ((kind-icon-default-style
               '(:padding -1 :stroke 0 :margin 0 :radius 0 :height 0.5 :scale 1.0)))
          (kind-icon-reset-cache)
          (kind-icon-formatted 'variable)))

It took me a long time to figure out the way to make style work as expected. Here's the code I use when playing with various settings, which I hope may be helpful to others. You can copy it to a scratch buffer and C-x C-e on the expression, adjust the style until it spit out a correctly-sized icon.

jdtsmith commented 2 years ago

I'm getting icons with extra padding around the sides

This is as expected. All icons (text or svg) are padded to be precisely 3x1 characters, so that they can be lined up at the prefix position and not affect alignment of the rest of the information on the completion line, yet still have a half space padding around them.

jdtsmith commented 2 years ago

BTW, you should only need to reset the cache while playing. If you are just looking to insert icons in buffer at arbitrary positions, you should probably just use svg-lib directly; see svg-lib-icon.

shouya commented 2 years ago

This is as expected. All icons (text or svg) are padded to be precisely 3x1 characters.

That mean the icon should be 2x1 characters plus the two half-spacess right? I understand and that is expected.

However, what I'm talking about isn't about the two half-spaces. It's the icon itself gets a lot wider than 2x1. In fact, the icon with (:height 0.5) style is already as wide as 4 characters (see my first picture), which is what I claimed as "uncessarily wide".

If you are just looking to insert icons in buffer at arbitrary positions, you should probably just use svg-lib directly

Yeah for sure. I'm only using it as a way to reliably insert an icon for me to inspect. Otherwise I have to (setq kind-icon-default-style), reset cache, then go to kind-icon-preview-all or go to a buffer with corfu and type something. It's way simpler to just C-x C-e on that piece of code.

dgutov commented 3 months ago

FWIW I'm also seeing this problem with the default config (the GTK3 build, 200% desktop scaling).

jdtsmith commented 3 months ago

svg-lib must be getting confused on these systems, possibly due to the reporting of the char sizes. Sounds like PGTK was a solution; is that what you run?

What does this command look like in *scratch*?

(insert-image (svg-lib-icon  "folder" kind-icon-default-style)) 

Should be two characters wide, ala:

image
dgutov commented 3 months ago

Sounds like PGTK was a solution; is that what you run?

No, I run GTK3 - it's still the recommended build for a lot of systems. Could be due to one of the quirks of this build - e.g. it also has smaller (non-scaled) margins compared to the PGTK build - so I kind of prefer this one. But the situation with these icons seems to be the reverse.

Should be two characters wide, ala:

The result is larger. Taller, as well.

jdtsmith commented 3 months ago

So this sounds like a problem with svg-lib and GTK builds. @rougier have you seen this before? I do note from an earlier message in this thread that people on these builds have very large reported char sizes (20 pixel width, for example; what's your char size @dgutov?). I suppose it's possible something in the chain is "double-counting" the pixel doubling. I.e. one part of the chain reports true pixels, and a later part assumes those are to be doubled. The default style used above is:

'(:padding 0 :stroke 0 :margin 0 :radius 0 :height 1.0 :scale 1.0 :background nil)

On MacOS with HDPI, the system lies and reports a 2x2 pixel grid as 1 pixel, so no-one is the wiser. This does cause occasional problems with images (e.g. in Org), which should be displayed at half as many (fake) pixels as their native size (e.g. 1000 pixels real image should be shown at 500 pixels display for pixel-perfect reproduction).

dgutov commented 3 months ago

20 pixel width, for example; what's your char size @dgutov?

(default-font-height) returns 34, (default-font-width) - 17.

rougier commented 3 months ago

Best would be to report the problem on svg-lib yes. We had such problem previously and mostly some hack to try to fix the problem. If you have consistent error, that might help.

dgutov commented 3 months ago

Done :+1: