Question

I would like to know how to get similar font rendering in GNU Emacs as in GVim as shown in the screenshot below. It seems Emacs has an inferior way of rendering fonts by default. I've tried installing the Infinality font patches but I got the same results. I am running GNU Emacs 24.3 on my Arch Linux virtual machine. I have no Desktop Environment and am using OpenBox as my window manager.

A lot of forum posts I dug up seemed to hint at the libxft library that Emacs uses needing patching in the past, but not anymore. According to Emacs it has been compiled --with-xft so that shouldn't be an issue. Below is a screenshot from both applications and a zoomed in view to highlight the difference in rendering.

emacs vs gvim rendering

Was it helpful?

Solution

In my experience, Emacs does not reliably read font settings from font config or from Gnome, so you may need to change Emacs' font rendering settings.

Notably, the colored pixels around the font in GVim indicate that GVim uses subpixel rendering, whereas the absence of these pixels in Emacs shows that it only uses hinting. The absence of subpixel rendering often makes fonts look blurry.

Find out GVims preferences

Find out what font rendering settings GVim uses. I presume it takes the standard ones from Gnome, so install Gnome Tweaktool to inspect the font settings from Gnome.

Tell Emacs about your font preferences

Now create an .Xresources file that tells Emacs about these settings. The following is represents my font settings, adapt it according to what you have found out in Gnome Tweaktool:

Xft.antialias:  1
Xft.hinting:    1
Xft.hintstyle:  hintfull
Xft.lcdfilter:  lcddefault
Xft.rgba:       rgb

As far as I know, the lcdfilter setting isn't available in Gnome Tweaktool, so just leave it on lcddefault. After creating the file

  1. Exit Emacs with C-x C-c
  2. Load these settings with:

    $ xrdb -merge ~/.Xresources
    
  3. Verify that the settings were loaded:

    $ xrdb -query | grep Xft
    Xft.antialias:  1
    Xft.hinting:    1
    Xft.hintstyle:  hintfull
    Xft.lcdfilter:  lcddefault
    Xft.rgba:       rgb
    
  4. Restart Emacs

Now check whether the fonts look the same now. Note that GVim may use a different font renderer (e.g. Cairo, Harfbuzz or whatever), so expect some slight differences anyway.

Check that the settings are permanent

  1. Log out of your desktop
  2. Log in again
  3. Use above xrdb -query command to verify the presence of your font settings
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top