finally, fonts are configured correctly?

This commit is contained in:
Benson Chu 2023-09-03 14:46:33 +08:00
parent e1168470bf
commit 727be011ff
3 changed files with 144 additions and 56 deletions

72
lisp/fonts-legacy.el Normal file
View file

@ -0,0 +1,72 @@
;;; fonts-legacy.el --- -*- lexical-binding: t -*-
;; Copyright (C) 2023 Benson Chu
;; Author: Benson Chu <bensonchu457@gmail.com>
;; Created: [2023-09-03 14:44]
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
;; (defmacro my/english-fontspec (name size &rest extra-attr)
;; `(font-spec :name ,name :size ,size ,@extra-attr))
;; (defmacro my/roboto-mono (&rest extra-attr)
;; `(my/english-fontspec "Roboto Mono" 13 ,@extra-attr))
;; (set-face-attribute 'default nil :font (my/roboto-mono))
;; (set-face-font 'bold (my/roboto-mono :weight 'bold))
;; (set-face-font 'italic (my/roboto-mono :slant 'italic))
;; (set-face-font 'bold-italic (my/roboto-mono :weight 'bold :slant 'italic))
;; (set-fontset-font "fontset-default" 'cyrillic (font-spec :size 15 :name "PT Sans Expert"))
;; (set-fontset-font "fontset-default" 'unicode (font-spec :size 10 :name "FontAwesome"))
;; (set-fontset-font "fontset-default" 'unicode (font-spec :name "SourceCodePro"))
;; (set-fontset-font "fontset-default"
;; (cons
;; (decode-char 'ucs #x2500)
;; (decode-char 'ucs #x257F))
;; (font-spec :name "SourceCodePro"))
;; HanWangKaiMediumChuIn
;; (set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "HanWangMingMediumChuIn"))
;; (set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "HanWangKaiMediumChuIn-20"))
;; extra/adobe-source-code-pro-fonts
;; adobe-source-han-sans-otc-fonts
;; (set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "Source Han Sans TW"))
;; (set-frame-font "fontset-default")
;; You can see a difference by switching between default and
;; fontset-standard.
;;
;; (set-face-font 'default "fontset-standard")
;; (custom-set-faces
;; '(default ((t (:family "ETBookOT" :foundry "QUQA"
;; :slant normal :weight normal :height 120
;; :width normal :spacing 90)))))
;;(set-face-attribute 'variable-pitch nil :font '(:family "ETBookOT"))
(provide 'fonts-legacy)
;;; fonts-legacy.el ends here

View file

@ -23,30 +23,25 @@
;;; Commentary:
;;; Code:
(require 'hoagie-adjust)
(create-fontset-from-fontset-spec
"-*-Roboto Mono-regular-normal-normal-*-*-*-*-*-m-0-fontset-default")
;; If I reeaaaally wanted to do this property, I would use
;; #'new-fontset, but that requires LOTS of background knowledge. Just
;; look at the #'setup-default-fontset function.
;;
;; For now, I will just use the default fontset.
;; HanWangKaiMediumChuIn
;; (set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "HanWangMingMediumChuIn"))
;; (set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "HanWangKaiMediumChuIn-20"))
(set-fontset-font "fontset-default" 'unicode (font-spec :size 10 :name "FontAwesome"))
(set-fontset-font "fontset-default" 'cyrillic (font-spec :size 15 :name "PT Sans Expert"))
;; extra/adobe-source-code-pro-fonts
(set-fontset-font "fontset-default" 'unicode (font-spec :name "SourceCodePro"))
(set-fontset-font "fontset-default"
(cons
(decode-char 'ucs #x2500)
(decode-char 'ucs #x257F))
(font-spec :name "SourceCodePro"))
;; adobe-source-han-sans-otc-fonts
(set-fontset-font "fontset-default" 'han (font-spec :size 16 :name "SourceHanSans"))
;; (create-fontset-from-fontset-spec
;; "-*-*-medium-r-normal-*-15-*-*-*-*-*-fontset-default")
(set-fontset-font "fontset-default" 'ascii (font-spec :size 13 :name "Roboto Mono"))
(set-fontset-font "fontset-default" 'latin (font-spec :size 13 :name "RobotoMono"))
;; 三寶飯
;; "HanWangMingMediumChuIn"
(let ((cf (font-spec :name "SourceHanSansTW"
:size 18)))
(dolist (charset '(kana han cjk-misc bopomofo gb18030))
(set-fontset-font "fontset-default" charset cf)))
(when my-ec/at-ti
(set-fontset-font "fontset-default"
@ -69,42 +64,6 @@
(set-face-font 'default "fontset-default")
;; (custom-set-faces
;; '(default ((t (:family "ETBookOT" :foundry "QUQA"
;; :slant normal :weight normal :height 120
;; :width normal :spacing 90)))))
;;(set-face-attribute 'variable-pitch nil :font '(:family "ETBookOT"))
(defvar frame-font-size-cache
(make-hash-table))
;; Font size adjustment
(defun hoagie-adjust-font-size (&optional frame)
"Inspired by https://emacs.stackexchange.com/a/44930/17066. FRAME is ignored.
If I let Windows handle DPI everything looks blurry."
(interactive)
;; Using display names is unreliable...switched to checking the resolution
(let* ((attrs (frame-monitor-attributes)) ;; gets attribs for current frame
(monitor-name (cdr (assoc 'name attrs)))
(width-mm (second (assoc 'mm-size attrs)))
(width-px (fourth (assoc 'geometry attrs)))
(height-px (fifth (assoc 'geometry attrs)))
(size 10)) ;; default for first screen at work
(when (eq height-px 2880)
(let ((f (selected-frame)))
(set-face-attribute 'default f :height 130)
(set-face-attribute 'mode-line f :height 130)
;; (set-face-attribute 'mode-line-inactive f :height 130)
(setq doom-modeline-height 30))
(exwm-randr-refresh))
;; (unless (and (gethash frame frame-font-size-cache)
;; (= size (gethash frame frame-font-size-cache)))
;; (puthash frame size frame-font-size-cache))
))
;; (remove-hook 'window-size-change-functions #'hoagie-adjust-font-size)
;; (setq doom-modeline-height 20) ; optional
;; (if (facep 'mode-line-active)
;; (set-face-attribute 'mode-line-active nil :family "Roboto Mono" :height 100) ; For 29+

57
lisp/hoagie-adjust.el Normal file
View file

@ -0,0 +1,57 @@
;;; hoagie-adjust.el --- -*- lexical-binding: t -*-
;; Copyright (C) 2023 Benson Chu
;; Author: Benson Chu <bensonchu457@gmail.com>
;; Created: [2023-09-03 14:45]
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(defvar frame-font-size-cache
(make-hash-table))
;; Font size adjustment
(defun hoagie-adjust-font-size (&optional frame)
"Inspired by https://emacs.stackexchange.com/a/44930/17066. FRAME is ignored.
If I let Windows handle DPI everything looks blurry."
(interactive)
;; Using display names is unreliable...switched to checking the resolution
(let* ((attrs (frame-monitor-attributes)) ;; gets attribs for current frame
(monitor-name (cdr (assoc 'name attrs)))
(width-mm (second (assoc 'mm-size attrs)))
(width-px (fourth (assoc 'geometry attrs)))
(height-px (fifth (assoc 'geometry attrs)))
(size 10)) ;; default for first screen at work
(when (eq height-px 2880)
(let ((f (selected-frame)))
(set-face-attribute 'default f :height 130)
(set-face-attribute 'mode-line f :height 130)
;; (set-face-attribute 'mode-line-inactive f :height 130)
(setq doom-modeline-height 30))
(exwm-randr-refresh))
;; (unless (and (gethash frame frame-font-size-cache)
;; (= size (gethash frame frame-font-size-cache)))
;; (puthash frame size frame-font-size-cache))
))
;; (remove-hook 'window-size-change-functions #'hoagie-adjust-font-size)
(provide 'hoagie-adjust)
;;; hoagie-adjust.el ends here