rougier / nano-emacs

GNU Emacs / N Λ N O - Emacs made simple
GNU General Public License v3.0
2.52k stars 195 forks source link

Default font size results in tiny font size on a HiDPI display, on Linux #13

Open mrzor opened 3 years ago

mrzor commented 3 years ago

Title says most of it.

Illustration

On the left side, my fullblown Emacs config. On the right side, latest nano-emacs ran with \emacs -q -l nano.el -dark.

image

Here, on the right side, latest nano-emacs ran with \emacs -q -l nano.el -dark, after editing nano-layout.el as follows:

(setq default-frame-alist
      (append (list
           '(font . "Roboto Mono:style=Light")

image

Font diagnostics

In my non-nano configuration, default font height is set to 139 (in 1/10pts, so 13.9pts), through (custom-set-faces). Relevant part looks like: '(default ((t (:inherit nil :stipple nil :background "#0D0D0D" :foreground "#DCDCCC" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 139 :width normal :foundry "PfEd" :family "Terminus (TTF)"))))

What you can see on the right side is always \emacs -q -l nano.el -dark (with and without fix applied).

(describe-face 'default) in my fullblown Emacs returns:

           Family: Terminus (TTF)
          Foundry: PfEd
            Width: normal
           Height: 139
           Weight: normal
            Slant: normal
       Foreground: #DCDCCC
DistantForeground: unspecified
       Background: #0D0D0D
        Underline: nil
         Overline: nil
   Strike-through: nil
              Box: nil
          Inverse: nil
          Stipple: nil
             Font: #<font-object -PfEd-Terminus (TTF)-normal-normal-normal-*-37-*-*-*-m-0-iso10646-1>
          Fontset: -PfEd-Terminus (TTF)-normal-normal-normal-*-37-*-*-*-m-0-fontset-auto2
           Extend: nil
          Inherit: nil

(describe-face 'default) in master branch using "Roboto Mono:style=Light:size=14" :

           Family: Roboto Mono
          Foundry: GOOG
            Width: normal
           Height: 53
           Weight: normal
            Slant: normal
       Foreground: #37474F
DistantForeground: unspecified
       Background: #FFFFFF
        Underline: nil
         Overline: nil
   Strike-through: nil
              Box: nil
          Inverse: nil
          Stipple: nil
             Font: #<font-object -GOOG-Roboto Mono-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1>
          Fontset: -GOOG-Roboto Mono-normal-normal-normal-*-14-*-*-*-m-0-fontset-auto1
           Extend: nil
          Inherit: nil

(describe-face 'default) using my patched nano config:

           Family: Roboto Mono
          Foundry: GOOG
            Width: normal
           Height: 120
           Weight: normal
            Slant: normal
       Foreground: black
DistantForeground: unspecified
       Background: white
        Underline: nil
         Overline: nil
   Strike-through: nil
              Box: nil
          Inverse: nil
          Stipple: nil
             Font: #<font-object -GOOG-Roboto Mono-normal-normal-normal-*-32-*-*-*-m-0-iso10646-1>
          Fontset: -GOOG-Roboto Mono-normal-normal-normal-*-32-*-*-*-m-0-fontset-auto1
           Extend: nil
          Inherit: nil

Adding size=14 to the font definitions results into Emacs selecting -GOOG-Roboto Mono-normal-normal-normal-*-14-*-*-*-m-0-fontset-auto1 with Height: 53. Omitting it results into Emacs selecting -GOOG-Roboto Mono-normal-normal-normal-*-32-*-*-*-m-0-iso10646-1 with Height: 120.

Hypotheses

a. This could be some weird fontconfig related issue - the interfering thing here would therefore be my chosen way of installing Roboto Mono. I'll look into it more.

b. Wild guess. Using such font definitions in Emacs 27.1+ could be problematic. I seem to recall they added a full new Harfbuzz glyph rendering engine.

c. There are others ways to set the default font, (set-face-font 'default ... comes to mind. Maybe this way works correctly on all platforms.

rougier commented 3 years ago

Do you have a desktop setting such as scale or zoom that transforms fonts ? It seems that Emacs catch the right font file with the right size but it seems to be transformed somehow. 14 should be 140 in emacs but it is not the case.

rougier commented 3 years ago

And the ratio seems to be 3.75 (14/53 and 37/139)

nobiot commented 3 years ago

Great theme/user experience. Thank you.

Just to let you know a result from a Windows user (HiDPI display, Emacs 27.1). Resolution set to 3840 x 2160, scale 2.0 (200%).

Launching the GUI mode of Emacs via emacs -q -l nano.el in Windows Terminal. The entire application (only Emacs window) is displayed in a shrunken size (I presume it's half the size based on the display scaling; can't be precise)

Changing the default-frame-alist in nano-layout.el as below fixed the problem for me.

 (setq default-frame-alist
       (append (list
               '(vertical-scroll-bars . nil)
               '(internal-border-width . 24)
               '(left-fringe    . 0)
               '(right-fringe   . 0)
               '(tool-bar-lines . 0)
               '(menu-bar-lines . 0))))

I then set the fonts using set-font-attribute like this below; it looks to be working in my light testing.

(set-face-attribute 'variable-pitch nil :font "Concourse T3-13")
(set-face-attribute 'fixed-pitch nil :font "Go Mono-11")
(set-face-attribute 'default nil :font "Cascadia Mono PL-11")
(set-fontset-font nil 'symbol (font-spec :family "Segoe UI Symbol" :size 11.0))

Just to illustrate the "shrinking" problem, here is my screen shot. Emacs window on the left is before the change (as per this repo); on the right is after the change I mention above. Just as a reference, the Windows Terminal Window is also shown behind Emacs windows. That's the normal size.

rougier commented 3 years ago

Thanks for the report. From all these reports it seems that setting the font size in the frame default definition does not really work. Maybe we can have a specific nano-typography.el file for setting fonts, line-spacing, etc. @mrzor What do you think ?

mrzor commented 3 years ago

I think going with dedicated nano-typography.el makes sense. On the other hand, we already have nano-faces which already covers the "setting fonts" part, at least in principle. Default font in frame parameters can also be set through the default face, which I believe to be the usual way to do it.

I'm not too sure about how to detect if a font is available, but nano-typography.el could do that as well and provide a better experience for users that do not have Roboto Mono installed - which seems to be a common theme in recent issues.

nobiot commented 3 years ago

For existing check of a font, I wonder if you could use the same way as this: https://github.com/kjhealy/emacs-starter-kit/blob/master/init.el#L44-L66 I just tested x-list-fonts "Roboto Mono"); it works -- if it works on Windows, I am confident it works on Mac and Linux... ;)

rougier commented 3 years ago

@nobiot Thanks for the link. Just tested it on OSX and I confirm it works. I think we shouls definitely reuse this code.