feat(bidi): add +bidi-*-font-scale vars

Close: #7687
This commit is contained in:
Henrik Lissner 2024-08-23 17:26:34 -04:00
parent f90f1c212e
commit a2814629a0
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 42 additions and 11 deletions

View file

@ -39,6 +39,18 @@ It also provides easy font configuration for Hebrew and Arabic-derived scripts
See [[Fonts]] for more information. If you use an RTL language that isn't covered by See [[Fonts]] for more information. If you use an RTL language that isn't covered by
these characters, open an issue requesting support for it. these characters, open an issue requesting support for it.
To resize fonts, don't include a ~:size~ parameter in ~+bidi-hebrew-font~ or
~+bidi-arabic-font~, set ~+bidi-hebrew-font-scale~ or ~+bidi-arabic-font-scale~
instead, or add an entry to ~face-font-rescale-alist~ for your font. E.g.
#+begin_src emacs-lisp
;;; Add to $DOOMDIR/config.el
(setq +bidi-arabic-font-scale 1.5)
;; or
(setq +bidi-hebrew-font-scale 2.5)
;; or
(add-to-list 'face-font-rescale-alist '("DejaVu Sans" . 1.2))
#+end_src
* Configuration * Configuration
** Using ~+bidi-mode~ ** Using ~+bidi-mode~
~+bidi-mode~ is a local minor mode, meaning it has to be turned on a per-buffer ~+bidi-mode~ is a local minor mode, meaning it has to be turned on a per-buffer

View file

@ -1,14 +1,16 @@
;;; input/bidi/config.el -*- lexical-binding: t; -*- ;;; input/bidi/config.el -*- lexical-binding: t; -*-
(defvar +bidi-mode-map (make-sparse-keymap)
"Keymap for `+bidi-mode'.")
(defvar +bidi-hebrew-font (font-spec :family "DejaVu Sans") (defvar +bidi-hebrew-font (font-spec :family "DejaVu Sans")
"Overriding font for hebrew script. "Overriding font for hebrew script.
Must be a `font-spec', see `doom-font' for examples. Must be a `font-spec', see `doom-font' for examples.
WARNING: if you specify a size for this font it will hard-lock any usage of this WARNING: if you specify a size for this font it will hard-lock any usage of this
font to that size. It's rarely a good idea to do so!") font to that size. It's rarely a good idea to do so! Set
`+bidi-hebrew-font-scale' to scale the font up or down.")
(defcustom +bidi-hebrew-font-scale 1.0
"What scale to display `+bidi-hebrew-font' at."
:type 'float)
(defface +bidi-hebrew-face `((t :font ,+bidi-hebrew-font)) "") (defface +bidi-hebrew-face `((t :font ,+bidi-hebrew-font)) "")
@ -17,7 +19,12 @@ font to that size. It's rarely a good idea to do so!")
Must be a `font-spec', see `doom-font' for examples. Must be a `font-spec', see `doom-font' for examples.
WARNING: if you specify a size for this font it will hard-lock any usage of this WARNING: if you specify a size for this font it will hard-lock any usage of this
font to that size. It's rarely a good idea to do so!") font to that size. It's rarely a good idea to do so! Set
`+bidi-arabic-font-scale' to scale the font up or down.")
(defcustom +bidi-arabic-font-scale 1.0
"What scale to display `+bidi-arabic-font' at."
:type 'float)
(defface +bidi-arabic-face `((t :font ,+bidi-arabic-font)) "") (defface +bidi-arabic-face `((t :font ,+bidi-arabic-font)) "")
@ -51,7 +58,10 @@ Warning: do not change this if you are using `+bidi-global-mode'.'"
(const :tag "Right to Left" right-to-left) (const :tag "Right to Left" right-to-left)
(const :tag "Dynamic, according to paragraph text" nil))) (const :tag "Dynamic, according to paragraph text" nil)))
;;;###autoload
(defvar +bidi-mode-map (make-sparse-keymap)
"Keymap for `+bidi-mode'.")
(define-minor-mode +bidi-mode (define-minor-mode +bidi-mode
"Minor mode for using bidirectional text in a buffer. "Minor mode for using bidirectional text in a buffer.
@ -85,9 +95,18 @@ easier."
(define-globalized-minor-mode +bidi-global-mode +bidi-mode +bidi-mode) (define-globalized-minor-mode +bidi-global-mode +bidi-mode +bidi-mode)
(add-hook! 'after-setting-font-hook (add-hook! 'after-setting-font-hook
(defun +bidi-set-fonts-h () (defun +bidi-init-fonts-h ()
(set-fontset-font t 'hebrew +bidi-hebrew-font) (when +bidi-hebrew-font
(set-fontset-font t 'arabic +bidi-arabic-font) (set-fontset-font t 'hebrew +bidi-hebrew-font)
(set-face-font '+bidi-arabic-face +bidi-arabic-font) (set-face-font '+bidi-hebrew-face +bidi-hebrew-font)
(set-face-font '+bidi-hebrew-face +bidi-hebrew-font))) (when (/= +bidi-hebrew-font-scale 1.0)
(setf (alist-get (font-get +bidi-hebrew-font :family) face-font-rescale-alist nil nil #'equal)
+bidi-hebrew-font-scale)))
(when +bidi-arabic-font
(set-fontset-font t 'arabic +bidi-arabic-font)
(set-face-font '+bidi-arabic-face +bidi-arabic-font)
(when (/= +bidi-arabic-font-scale 1.0)
(setf (alist-get (font-get +bidi-arabic-font :family) face-font-rescale-alist nil nil #'equal)
+bidi-arabic-font-scale)))))