中英文对齐与斜体

我想让中英文等宽、支持斜体并不更换字体(current font: fira code nerd font mono) 这能实现吗?

  1. fira code里面不包含中文字符,想要中英文等宽同时使用fira code字体,请参考 @tumashu 大神的
  1. fira code没有斜体版本,中文可以自己找一个有斜体版的

想要中英字体等宽需要使用同时包含中英文的字体,或者对中文使用不同的charset,并且针对每一个英文字号,设置相应的中文字号。斜体也是一样的原理。

我现在的设置是

(when (display-graphic-p)

  (defun display-name (&optional frame)
    (pcase (sort (frame-monitor-attribute 'mm-size frame) '>)
      ('(599 340) 'lg-ultrafine-27)
      ('(596 335) 'dell-up2716d)
      ('(330 206) 'macbook-pro-15)
      ('(344 214) 'macbook-pro-16)))

  (defun Menlo-font (size)
    (format "-*-Menlo-normal-normal-normal-*-%d-*-*-*-m-0-iso10646-1"
            size))

  (defun SFMono-font (size)
    (format "-*-SF Mono-normal-normal-normal-*-%d-*-*-*-m-0-iso10646-1"
            size))

  (defun UbuntuMono-font (size)
    (format "-*-Ubuntu Mono-normal-normal-normal-*-%d-*-*-*-m-0-iso10646-1"
            size))

  (defconst default-font-size 12
    "Default font size")

  (defconst font-size-map-STHeiTi
    `((,(Menlo-font 11)      . 14.0)
      (,(Menlo-font 12)      . 14.0)
      (,(Menlo-font 13)      . 16.0)
      (,(Menlo-font 14)      . 16.0)
      (,(Menlo-font 15)      . 18.0)
      (,(Menlo-font 16)      . 20.0)
      (,(Menlo-font 17)      . 20.0)
      (,(Menlo-font 18)      . 22.0)
      (,(Menlo-font 19)      . 22.0)
      (,(Menlo-font 20)      . 24.0)
      (,(Menlo-font 21)      . 26.0)
      (,(Menlo-font 22)      . 26.0)
      (,(SFMono-font 11)     . 14.0)
      (,(SFMono-font 12)     . 16.0)
      (,(SFMono-font 13)     . 16.0)
      (,(SFMono-font 14)     . 18.0)
      (,(SFMono-font 15)     . 18.0)
      (,(SFMono-font 16)     . 20.0)
      (,(SFMono-font 17)     . 22.0)
      (,(SFMono-font 18)     . 22.0)
      (,(SFMono-font 19)     . 24.0)
      (,(SFMono-font 20)     . 24.0)
      (,(SFMono-font 21)     . 26.0)
      (,(SFMono-font 22)     . 28.0)
      (,(UbuntuMono-font 11) . 12.0)
      (,(UbuntuMono-font 12) . 12.0)
      (,(UbuntuMono-font 13) . 14.0)
      (,(UbuntuMono-font 14) . 14.0)
      (,(UbuntuMono-font 15) . 16.0)
      (,(UbuntuMono-font 16) . 16.0)
      (,(UbuntuMono-font 17) . 18.0)
      (,(UbuntuMono-font 18) . 18.0)
      (,(UbuntuMono-font 19) . 20.0)
      (,(UbuntuMono-font 20) . 20.0)
      (,(UbuntuMono-font 21) . 22.0)
      (,(UbuntuMono-font 22) . 22.0))
    "Font size mapping to STHeiTi that can align with the
    corresponding font and size.")


  (defun emacs-set-frame (&optional size)
    (interactive "nFont Size: ")
    (setq size (cond
                ((not size)
                 (message "Use default font size %d" default-font-size)
                 default-font-size)
                ((< size 11)
                 (message "Use min font size 11")
                 11)
                ((> size 22)
                 (message "Use max font size 22")
                 22)
                (t size)))

    ;; `default' face
    (set-face-font 'default (SFMono-font size))

    (dolist (charset '(han cjk-misc bopomofo))
      (set-fontset-font t charset (font-spec :family "STHeiTi")))

    (setq face-font-rescale-alist
          `(("STHeiTi" . ,(/ (cdr (assoc (frame-parameter nil 'font)
                                         font-size-map-STHeiTi))
                             size))))

    (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji"))

    ;; `variable-pitch' face uses the same height as the `default'.
    ;; https://protesilaos.com/codelog/2020-09-05-emacs-note-mixed-font-heights/
    (set-face-attribute 'variable-pitch nil :family "Palatino" :height 1.0)

    ;; Set frame dimension based on the current display
    (pcase (display-name nil)
      ('lg-ultrafine-27
       (set-frame-position nil 260 120)
       (set-frame-height nil (/ 1200 (frame-char-height)))
       (set-frame-width  nil (/ 2020 (frame-char-width))))
      (_
       (toggle-frame-maximized))))

  (add-hook 'after-init-hook #'emacs-set-frame t)

  (bind-key "M-`" #'emacs-set-frame))