rougier / svg-tag-mode

A minor mode for Emacs that replace keywords with nice SVG labels
GNU General Public License v3.0
494 stars 28 forks source link

Font size messed up #38

Open gaetgu opened 1 year ago

gaetgu commented 1 year ago

I am trying to get svg-tags set up with org mode (using org-modern and doom emacs). However, I am having some issues. Here is what the tags look like:

image

I have looked through some of the other issues (mostly #12 and #10) and I have tried using the fork from PR #14, with no success. I am wondering if there is anything obvious that I am missing?

rougier commented 1 year ago

No, it's a recurrent problem that I've hard time fixing. Do you use any kind of magnification on your os?

ronisbr commented 1 year ago

I have the exactly the same problem in macOS with default configurations of monitor.

rougier commented 1 year ago

@ronisbr Do you have a second monitor ? What is your version of Emacs ?

ronisbr commented 1 year ago

@rougier Yes, I do! I am using Emacs 29. I will try removing the second monitor.

ronisbr commented 1 year ago
Captura de Tela 2023-02-27 às 15 34 36

No, removing the second monitor did not change anything.

rougier commented 1 year ago

@ronisbr Could you tr the various fixes pointed by @gaetgu (#12 and #10) and the fork?

ronisbr commented 1 year ago

Hi @rougier !

I found the problem here! Everything started to work if I change this line:

         (font-info       (font-info (format "%s-%d" font-family font-size)))

to

         (font-info       (font-info "JetBrainsMono Nerd Font Mono"))

The problem is that the name of my font does not appear to follow the expected format! By default, font-size is set to 10 whereas my font size is 13. If I change font-size to 13, everything works perfectly.

EDIT:

I found the problem! The library is picking the default font probably at a stage where my current font is not defined. The following screenshot shows the default values:

Captura de Tela 2023-03-21 às 12 47 56

I user JetBrainsMono with size 13.

The final fix for me is just to set the configuration as follows (Doom emacs):

(use-package! svg-tag-mode
  :config
  (plist-put svg-lib-style-default :font-family "JetBrainsMono Nerd Font")
  (plist-put svg-lib-style-default :font-size 13))
ronisbr commented 1 year ago

After the modification:

Captura de Tela 2023-03-21 às 12 34 43
rougier commented 1 year ago

Fantastic! Thanks for the very helpful debug! This size problem has plagued the library from the start without any obvious solution. Now the question is why do I not pick the right size when required? Do you know when your default font size is actually set?

ronisbr commented 1 year ago

Hi @rougier !

I have no idea. Since I use Doom Emacs, it has its own method to customize the default fonts. This is the code where I set the font in Doom: https://github.com/ronisbr/doom.d/blob/25c12efa4dc90ca2b6b2824047c33fc4f2b596d4/settings/setup-theme.el#L3 It is a variable that is used to set Emacs fonts at some stage.

If we manage to find a hook that runs after that, we might just add comments to the README here instructing the users to add a specific function to that hook setting the fonts in svg-tag-mode.

rougier commented 1 year ago

I see. Then maybe a warning/howto in the README would be our best option since I don't think it's possible to have a hook on default font change.

tam5 commented 1 year ago

Re: above regarding hooks and such, for temp fix I'm doing the following:

(use-package! svg-lib
  :init (add-hook 'after-setting-font-hook (lambda () (setq svg-lib-style-default (svg-lib-style-compute-default)))))

Which seems to alleviate the issue for me.

Will try to add more debug info i've found soon

(presumably same thing if using svg-tag-mode directly just replace as necessary)

rougier commented 1 year ago

Oh, the after-setting-font-hook is really useful. Maybe we could include your fix in the lib. Could you make a PR (for this and svg-lib as well since it may suffer from the same problem)