diff --git a/core/autoload/fonts.el b/core/autoload/fonts.el index 1eb0a923a..73f940acf 100644 --- a/core/autoload/fonts.el +++ b/core/autoload/fonts.el @@ -20,10 +20,17 @@ If nil, `doom-font' will be used, scaled up by `doom-big-font-increment'. See ;; ;;; Library -(defun doom--font2xlfd (font) - (cond ((stringp font) (aref (font-info font) 0)) - ((fontp font) (font-xlfd-name font)) - ((vectorp font) 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)) ;;;###autoload (defun doom-adjust-font-size (increment &optional fixed-size-p font-alist) @@ -52,46 +59,30 @@ Doesn't work in terminal Emacs." (if (null increment) (when (get var 'initial-value) (set var (get var 'initial-value)) - (put var 'new-size nil) (put var 'initial-value nil) (setq changed t)) - (let* ((orig-font (or (symbol-value var) - (face-font face t) - (with-temp-buffer (face-font face)))) - (font (doom--font2xlfd orig-font)) - (font (or (and (query-fontset font) - (if-let (ascii (assq 'ascii (aref (fontset-info font) 2))) - (nth 2 ascii) - font)) - font)) - (dfont (and (stringp font) (x-decompose-font-name font))) - (dfont (if-let* ((remap-font (alist-get var font-alist)) - (remap-xlfd (if (stringp remap-font) - (aref (font-info remap-font) 0) - (font-xlfd-name remap-font)))) - (x-decompose-font-name remap-xlfd) - dfont))) - (unless (get var 'initial-value) - (put var 'initial-value orig-font)) - (unless (vectorp dfont) - (error "Could not decompose %S font: %S" var font)) + (let* ((original-font (or (symbol-value var) + (face-font face t) + (with-temp-buffer (face-font face)))) + (font (doom--normalize-font original-font)) + (dfont + (or (if-let* ((remap-font (alist-get var font-alist)) + (remap-xlfd (doom--normalize-font remap-font))) + remap-xlfd + (purecopy font)) + (error "Could not decompose %s font" var)))) (let* ((step (if fixed-size-p 0 (* increment doom-font-increment))) - (orig-size (string-to-number (aref dfont xlfd-regexp-pixelsize-subnum))) + (orig-size (font-get dfont :size)) (new-size (if fixed-size-p increment (+ orig-size step)))) - (unless (> new-size 0) - (error "`%s' font is too small to be reszied (%d)" var new-size)) - (if (= orig-size new-size) - (message "Could not resize `%s' for some reason" var) - (put var 'new-size new-size) - (aset dfont xlfd-regexp-pixelsize-subnum (number-to-string new-size)) - ;; Set point size & width to "*", so frame width will adjust to new font size - (aset dfont xlfd-regexp-pointsize-subnum "*") - (aset dfont xlfd-regexp-avgwidth-subnum "*") - (setq font (x-compose-font-name dfont)) - (unless (x-list-fonts font) - (error "Cannot change font size")) - (set var font) - (setq changed t)))))))) + (cond ((<= new-size 0) + (error "`%s' font is too small to be resized (%d)" var new-size)) + ((= orig-size new-size) + (user-error "Could not resize `%s' for some reason" var)) + ((setq changed t) + (unless (get var 'initial-value) + (put var 'initial-value original-font)) + (font-put dfont :size new-size) + (set var dfont))))))))) (error (ignore-errors (doom-adjust-font-size nil)) (signal (car e) (cdr e))))) @@ -154,9 +145,8 @@ Also resizees `doom-variable-pitch-font' and `doom-serif-font'." (if doom-big-font ;; Use `doom-big-font' in lieu of `doom-font' (doom-adjust-font-size - (and doom-big-font-mode - (aref (x-decompose-font-name (doom--font2xlfd font)) - xlfd-regexp-pixelsize-subnum)) + (if doom-big-font-mode + (font-get (doom--normalize-font doom-big-font) :size)) t `((doom-font . ,doom-big-font))) ;; Resize the current font (doom-adjust-font-size (if doom-big-font-mode doom-big-font-increment))))