Simplify doom|init-fonts: add xft font support

custom-set-faces is somewhat overkill for this. It overwrites any user
customizations for the default & variable-pitch faces, and saves them to
custom-file, which may cause those settings to persist even when we
don't want them to.

This new solution is a little faster, is more respective of
customizations, and adds XFT font string support.

XFT font strings are a little more powerful. For example, the :antialias
font-spec property was unreliable, but now you can use:

  (setq doom-font "Fira Mono:pixelsize=12:antialias=off")
This commit is contained in:
Henrik Lissner 2018-09-18 22:48:21 -04:00
parent b76a09539c
commit 54e8577bf6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -307,17 +307,21 @@ frame's window-system, the theme will be reloaded.")
(defun doom|init-fonts ()
"Initialize fonts."
(condition-case e
(custom-set-faces
(when (fontp doom-font)
(let ((xlfd (font-xlfd-name doom-font)))
(add-to-list 'default-frame-alist (cons 'font xlfd))
`(fixed-pitch ((t (:font ,xlfd))))))
(when (fontp doom-variable-pitch-font)
`(variable-pitch ((t (:font ,(font-xlfd-name doom-variable-pitch-font))))))
;; Fallback to `doom-unicode-font' for Unicode characters
(when (fontp doom-unicode-font)
(set-fontset-font t nil doom-unicode-font nil 'append)
nil))
(progn
(when doom-font
(add-to-list
'default-frame-alist
(cons 'font
(cond ((stringp doom-font) doom-font)
((fontp doom-font) (font-xlfd-name doom-font))
((signal 'wrong-type-argument (list '(fontp stringp) doom-font)))))))
(when (fontp doom-variable-pitch-font)
(set-face-attribute 'variable-pitch t
:width 'normal :weight 'normal :slant 'normal
:font doom-variable-pitch-font))
;; Fallback to `doom-unicode-font' for Unicode characters
(when (fontp doom-unicode-font)
(set-fontset-font t nil doom-unicode-font nil 'append)))
((debug error)
(if (string-prefix-p "Font not available: " (error-message-string e))
(lwarn 'doom-ui :warning