Fix #5146: errors when adjusting font size live
This commit is contained in:
parent
b2376a847f
commit
c34ed0d194
1 changed files with 33 additions and 43 deletions
|
@ -20,10 +20,17 @@ If nil, `doom-font' will be used, scaled up by `doom-big-font-increment'. See
|
||||||
;;
|
;;
|
||||||
;;; Library
|
;;; Library
|
||||||
|
|
||||||
(defun doom--font2xlfd (font)
|
(defun doom--normalize-font (font)
|
||||||
(cond ((stringp font) (aref (font-info font) 0))
|
(let* ((font (cond ((stringp font) (aref (font-info font) 0))
|
||||||
((fontp font) (font-xlfd-name font))
|
((fontp font) (font-xlfd-name font))
|
||||||
((vectorp font) 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
|
;;;###autoload
|
||||||
(defun doom-adjust-font-size (increment &optional fixed-size-p font-alist)
|
(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)
|
(if (null increment)
|
||||||
(when (get var 'initial-value)
|
(when (get var 'initial-value)
|
||||||
(set var (get var 'initial-value))
|
(set var (get var 'initial-value))
|
||||||
(put var 'new-size nil)
|
|
||||||
(put var 'initial-value nil)
|
(put var 'initial-value nil)
|
||||||
(setq changed t))
|
(setq changed t))
|
||||||
(let* ((orig-font (or (symbol-value var)
|
(let* ((original-font (or (symbol-value var)
|
||||||
(face-font face t)
|
(face-font face t)
|
||||||
(with-temp-buffer (face-font face))))
|
(with-temp-buffer (face-font face))))
|
||||||
(font (doom--font2xlfd orig-font))
|
(font (doom--normalize-font original-font))
|
||||||
(font (or (and (query-fontset font)
|
(dfont
|
||||||
(if-let (ascii (assq 'ascii (aref (fontset-info font) 2)))
|
(or (if-let* ((remap-font (alist-get var font-alist))
|
||||||
(nth 2 ascii)
|
(remap-xlfd (doom--normalize-font remap-font)))
|
||||||
font))
|
remap-xlfd
|
||||||
font))
|
(purecopy font))
|
||||||
(dfont (and (stringp font) (x-decompose-font-name font)))
|
(error "Could not decompose %s font" var))))
|
||||||
(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* ((step (if fixed-size-p 0 (* increment doom-font-increment)))
|
(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))))
|
(new-size (if fixed-size-p increment (+ orig-size step))))
|
||||||
(unless (> new-size 0)
|
(cond ((<= new-size 0)
|
||||||
(error "`%s' font is too small to be reszied (%d)" var new-size))
|
(error "`%s' font is too small to be resized (%d)" var new-size))
|
||||||
(if (= orig-size new-size)
|
((= orig-size new-size)
|
||||||
(message "Could not resize `%s' for some reason" var)
|
(user-error "Could not resize `%s' for some reason" var))
|
||||||
(put var 'new-size new-size)
|
((setq changed t)
|
||||||
(aset dfont xlfd-regexp-pixelsize-subnum (number-to-string new-size))
|
(unless (get var 'initial-value)
|
||||||
;; Set point size & width to "*", so frame width will adjust to new font size
|
(put var 'initial-value original-font))
|
||||||
(aset dfont xlfd-regexp-pointsize-subnum "*")
|
(font-put dfont :size new-size)
|
||||||
(aset dfont xlfd-regexp-avgwidth-subnum "*")
|
(set var dfont)))))))))
|
||||||
(setq font (x-compose-font-name dfont))
|
|
||||||
(unless (x-list-fonts font)
|
|
||||||
(error "Cannot change font size"))
|
|
||||||
(set var font)
|
|
||||||
(setq changed t))))))))
|
|
||||||
(error
|
(error
|
||||||
(ignore-errors (doom-adjust-font-size nil))
|
(ignore-errors (doom-adjust-font-size nil))
|
||||||
(signal (car e) (cdr e)))))
|
(signal (car e) (cdr e)))))
|
||||||
|
@ -154,9 +145,8 @@ Also resizees `doom-variable-pitch-font' and `doom-serif-font'."
|
||||||
(if doom-big-font
|
(if doom-big-font
|
||||||
;; Use `doom-big-font' in lieu of `doom-font'
|
;; Use `doom-big-font' in lieu of `doom-font'
|
||||||
(doom-adjust-font-size
|
(doom-adjust-font-size
|
||||||
(and doom-big-font-mode
|
(if doom-big-font-mode
|
||||||
(aref (x-decompose-font-name (doom--font2xlfd font))
|
(font-get (doom--normalize-font doom-big-font) :size))
|
||||||
xlfd-regexp-pixelsize-subnum))
|
|
||||||
t `((doom-font . ,doom-big-font)))
|
t `((doom-font . ,doom-big-font)))
|
||||||
;; Resize the current font
|
;; Resize the current font
|
||||||
(doom-adjust-font-size (if doom-big-font-mode doom-big-font-increment))))
|
(doom-adjust-font-size (if doom-big-font-mode doom-big-font-increment))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue