From 659197c7b2518bbea7f8c8f20f8970e9fdaa218b Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 29 Jun 2026 22:07:45 -0400 Subject: feat(nov): reading-view theme layer with palettes and font sizing EPUB reading prefs were scattered: a hardcoded Merriweather/180 font-remap in calibredb-epub-config's nov hook, no color control (the old sepia foreground had been stripped), and a frame-global EBook fontaine preset as the only way to size up. That preset resized the font in every buffer in the frame, not just the book. I pulled the reading view into its own layer, modules/nov-reading.el, on top of stock nov (no fork). It owns three things, all buffer-local: a reading palette (sepia/dark/light, each a face the dupre theme owns, sepia the default), the serif typography (family plus a defcustom base height replacing the hardcoded 180), and page font sizing (+/- bump the size live, = resets to the base). Width moves to { }. calibredb-epub-config keeps the library and width/centering layout. Its nov hook now calls into the layer. The three palette faces register as a nov-reading app in theme-studio (face_data.py), so they're tunable there like any other app. I dropped the EBook fontaine preset, since reading size is buffer-local now. --- tests/test-calibredb-epub-config.el | 11 +++---- tests/test-nov-reading--palette.el | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 tests/test-nov-reading--palette.el (limited to 'tests') diff --git a/tests/test-calibredb-epub-config.el b/tests/test-calibredb-epub-config.el index cb3a9ba74..71581d4c9 100644 --- a/tests/test-calibredb-epub-config.el +++ b/tests/test-calibredb-epub-config.el @@ -173,12 +173,13 @@ re-render of the document." (should (commandp #'cj/nov-narrow-text))) (ert-deftest test-calibredb-epub-nov-width-commands-bound-in-nov-mode-map () - "Normal: +/= widen and -/_ narrow the text column in `nov-mode-map'." + "Normal: { } adjust the text column in `nov-mode-map' (+/-/= are font size)." (skip-unless (and (require 'nov nil t) (boundp 'nov-mode-map))) - (should (eq (keymap-lookup nov-mode-map "+") #'cj/nov-widen-text)) - (should (eq (keymap-lookup nov-mode-map "=") #'cj/nov-widen-text)) - (should (eq (keymap-lookup nov-mode-map "-") #'cj/nov-narrow-text)) - (should (eq (keymap-lookup nov-mode-map "_") #'cj/nov-narrow-text))) + (should (eq (keymap-lookup nov-mode-map "}") #'cj/nov-widen-text)) + (should (eq (keymap-lookup nov-mode-map "{") #'cj/nov-narrow-text)) + (should (eq (keymap-lookup nov-mode-map "+") #'cj/nov-reading-text-bigger)) + (should (eq (keymap-lookup nov-mode-map "-") #'cj/nov-reading-text-smaller)) + (should (eq (keymap-lookup nov-mode-map "=") #'cj/nov-reading-text-reset))) ;;; -------------------------- cj/nov-apply-preferences ------------------------ diff --git a/tests/test-nov-reading--palette.el b/tests/test-nov-reading--palette.el new file mode 100644 index 000000000..164ec75f4 --- /dev/null +++ b/tests/test-nov-reading--palette.el @@ -0,0 +1,60 @@ +;;; test-nov-reading--palette.el --- nov reading-palette tests -*- lexical-binding: t; -*- + +;;; Commentary: +;; Pure-logic tests for the nov-mode reading-palette selector: name->face +;; resolution and the cycle order (palettes, then the no-palette state, wrapping). +;; The buffer-local face-remap application is exercised live, not here. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'nov-reading) + +(declare-function cj/nov--reading-palette-face "nov-reading" (name)) +(declare-function cj/nov--next-reading-palette "nov-reading" (current names)) +(defvar cj/nov-reading-palettes) + +;;; ----------------------- cj/nov--reading-palette-face ----------------------- + +(ert-deftest test-nov-reading-palette-face-known () + "Normal: a known palette name resolves to its face." + (let ((cj/nov-reading-palettes '(("sepia" . cj/nov-reading-sepia) + ("dark" . cj/nov-reading-dark)))) + (should (eq (cj/nov--reading-palette-face "sepia") 'cj/nov-reading-sepia)) + (should (eq (cj/nov--reading-palette-face "dark") 'cj/nov-reading-dark)))) + +(ert-deftest test-nov-reading-palette-face-unknown () + "Error: an unknown name resolves to nil." + (let ((cj/nov-reading-palettes '(("sepia" . cj/nov-reading-sepia)))) + (should-not (cj/nov--reading-palette-face "nope")))) + +(ert-deftest test-nov-reading-palette-face-nil () + "Boundary: a nil name resolves to nil." + (let ((cj/nov-reading-palettes '(("sepia" . cj/nov-reading-sepia)))) + (should-not (cj/nov--reading-palette-face nil)))) + +;;; ----------------------- cj/nov--next-reading-palette ----------------------- + +(ert-deftest test-nov-reading-next-palette-advances () + "Normal: cycles to the next palette in order." + (should (equal (cj/nov--next-reading-palette "sepia" '("sepia" "dark" "light")) + "dark"))) + +(ert-deftest test-nov-reading-next-palette-last-to-none () + "Boundary: the last palette cycles to the no-palette state (nil)." + (should-not (cj/nov--next-reading-palette "light" '("sepia" "dark" "light")))) + +(ert-deftest test-nov-reading-next-palette-none-to-first () + "Boundary: the no-palette state (nil) cycles to the first palette." + (should (equal (cj/nov--next-reading-palette nil '("sepia" "dark" "light")) + "sepia"))) + +(ert-deftest test-nov-reading-next-palette-unknown-current-falls-to-first () + "Error: an unknown current palette falls back to the first." + (should (equal (cj/nov--next-reading-palette "gone" '("sepia" "dark" "light")) + "sepia"))) + +(provide 'test-nov-reading--palette) +;;; test-nov-reading--palette.el ends here -- cgit v1.2.3