From a2814629a0f0a21214c532698dbd2e774012c0b4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 23 Aug 2024 17:26:34 -0400 Subject: [PATCH] feat(bidi): add +bidi-*-font-scale vars Close: #7687 --- modules/input/bidi/README.org | 12 ++++++++++ modules/input/bidi/config.el | 41 +++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/modules/input/bidi/README.org b/modules/input/bidi/README.org index 1cea6aeb5..572f017ea 100644 --- a/modules/input/bidi/README.org +++ b/modules/input/bidi/README.org @@ -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 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 ** Using ~+bidi-mode~ ~+bidi-mode~ is a local minor mode, meaning it has to be turned on a per-buffer diff --git a/modules/input/bidi/config.el b/modules/input/bidi/config.el index 1b91819a2..8673ac5ed 100644 --- a/modules/input/bidi/config.el +++ b/modules/input/bidi/config.el @@ -1,14 +1,16 @@ ;;; 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") "Overriding font for hebrew script. 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 -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)) "") @@ -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. 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)) "") @@ -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 "Dynamic, according to paragraph text" nil))) -;;;###autoload + +(defvar +bidi-mode-map (make-sparse-keymap) + "Keymap for `+bidi-mode'.") + (define-minor-mode +bidi-mode "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) + (add-hook! 'after-setting-font-hook - (defun +bidi-set-fonts-h () - (set-fontset-font t 'hebrew +bidi-hebrew-font) - (set-fontset-font t 'arabic +bidi-arabic-font) - (set-face-font '+bidi-arabic-face +bidi-arabic-font) - (set-face-font '+bidi-hebrew-face +bidi-hebrew-font))) + (defun +bidi-init-fonts-h () + (when +bidi-hebrew-font + (set-fontset-font t 'hebrew +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)))))