doomemacs / doomemacs/core

doom/increase-font-size and doom/decrease-font-size unexpectedly change weight and slant

Open
#5,182 10 comments 9 reactions 0 assignees View on GitHub
core is:bug status:confirmed
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### What did you expect to happen?

When I do doom/increase-font-size (`s-=`) or doom/decrease-font-size (`s--`), the size should increase, but all other aspects of the font should remain unchanged.

### What actually happened?

Along with the size change, other font properties change too. This only happens for some fonts. (All fonts are either shipped with macOS (Georgia) or were installed from homebrew.)

Fonts which work as expected:
Fira Mono
Georgia

Fonts which behave unexpectedly (become bold and italic in addition to changing size):
Fira Code
EB Garamond

Running doom/reset-font-size (`s-+`) reverts the other properties in addition to the size.

This does not happen when doing vanilla emacs font size changes (`C-x C-=`, `C-x C--`). The issue persists in vanilla Doom (Sandbox `C-c C-d`).

### Describe your attempts to resolve the issue

Some digging I did in the source while troubleshooting... :

Before/after `s-=` for a font without the issue:
```
(setq doom-font (font-spec :family "Fira Mono" :size 12))
=> #
M-x doom/increase-font-size
doom-font
=> #
```

Before/after `s-=` for a font with the issue:
```
(setq doom-font (font-spec :family "Fira Code" :size 12))
=> #
M-x doom/increase-font-size
doom-font
=> #
```

The bold italic is arising from the `x-resolve-font-name` call in `doom--normalize-font`:
```
(defun doom--normalize-font (font)
(let* ((font (cond ((stringp font) (aref (font-info font) 0))
((fontp font) (font-xlfd-name font))
((vectorp font) (x-compose-font-name font))))
(font (x-resolve-font-name font))
(font (font-spec :name font)))
(unless (font-get font :size)
(font-put font :size
(font-get (font-spec :name (face-font 'default))
:size)))
font))
```

`x-resolve-font-name` calls `x-list-fonts` and returns the first font name which matches the pattern. Since a font specified by a font-spec call like `(font-spec :family "Fira Code" :size 12)` returns a font with the parameters aside from family and size left as wildcards, the return list is all fonts in the family, and the first one in the list in these cases turns out to be the bold italic one.

So, a workaround that is working for me is to be more specific when setting `doom-font`:
`(setq doom-font (font-spec :family "Fira Code" :slant 'normal :weight 'normal :size 12))`

However, I know this used to work fine without specifying the slant and weight explicitly, so I tried to dig a bit further to see what the cause was.

`:name` is not a property of font-spec so I tried changing it to `:family` assuming that may have been the bug, but that threw another error. I don't know for sure what the expected output from `doom--normalize-font` is so decided to stop here to report the bug.

### Steps to reproduce

1. Since this seems to vary with font, it's easiest to use one of the fonts I used: `brew install font-fira-code`
2. Open Doom emacs
3. Launch vanilla Doom sandbox
4. Eval:
```
(setq doom-font (font-spec :family "Fira Code" :size 12))
```
5. M-x doom/increase-font-size

### System Information

https://pastebin.com/801r18Gg

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.