[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pdf-tools bc2ba117e8 2/2: Change the default color inversi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pdf-tools bc2ba117e8 2/2: Change the default color inversion to maintain hue |
Date: |
Tue, 17 Jan 2023 01:59:35 -0500 (EST) |
branch: elpa/pdf-tools
commit bc2ba117e8c3196ff9adf0da4fa1e63a8da3d7c8
Author: Vedang Manerikar <ved.manerikar@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>
Change the default color inversion to maintain hue
This commit enables @smithzvk's work in #69 as the default in
`pdf-tools`. It works well for all the PDFs I have tested with.
The previous behaviour can be enabled by setting
`pdf-view-midnight-invert` to `nil`, if required.
---
NEWS | 3 +++
lisp/pdf-info.el | 9 +++------
lisp/pdf-view.el | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/NEWS b/NEWS
index 5abb81569b..5fbdb2316c 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@
- Track rotation of pages and add a command to make rotation of pages easy
@vizs #165
+ The new command is bound to =R= in `pdf-view-mode-map`.
+- Add support for maintaining hue in `pdf-view-midnight-minor-mode` using the
OKLab color space @smithzvk #69
+ + This inversion method is now enabled by default and can be controlled by
the `pdf-view-midnight-invert` variable. Check out the images in the PR for how
beautiful the colors look in midnight mode now.
+
** Functionality fixes and improvements
- Fix: Saving a PDF when ~buffer-file-name~ is missing will now prompt for a
filename (eg: in EWW) @akater #178
diff --git a/lisp/pdf-info.el b/lisp/pdf-info.el
index 7cc43882bc..db1dc7e9e8 100644
--- a/lisp/pdf-info.el
+++ b/lisp/pdf-info.el
@@ -575,9 +575,9 @@ interrupted."
((:render/usecolors)
(setq value (ignore-errors
(let ((int-val (cl-parse-integer value)))
- (if (> int-val 0)
+ (if (> 3 int-val 0)
int-val
- nil))))))
+ 0))))))
(push value options)
(push key options)))
options))
@@ -1740,10 +1740,7 @@ Returns a list \(LEFT TOP RIGHT BOT\)."
;; :render/foreground and white to :render/background
;; 2 -> recolor document by inverting the perceived lightness
;; preserving hue
- (push (cond ((integerp value) value)
- ;; Map nil -> 0 and t -> 1
- (value 1)
- (t 0))
+ (push (if (and (integerp value) (> 3 value 0)) value 0)
soptions))
(t (push value soptions)))
(push key soptions)))
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index 6197029c19..cb7c67b747 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -118,13 +118,13 @@ This should be a cons \(FOREGROUND . BACKGROUND\) of
colors."
:type '(cons (color :tag "Foreground")
(color :tag "Background")))
-(defcustom pdf-view-midnight-invert nil
+(defcustom pdf-view-midnight-invert t
"In midnight mode invert the image color lightness maintaining hue.
This is particularly useful if you are viewing documents with
color coded data in plots. This will maintain the colors such
-that 'blue' and 'red' will remain these colors in the inverted
-rendering. This inversion is non-trivial. This makes use of the
+that blue and red will remain these colors in the inverted
+rendering. This inversion is non-trivial. This makes use of the
OKLab color space which is well calibrated to have equal
perceptual brightness across hue, but not all colors are within
the RGB gamut after inversion, causing some colors to saturate.
@@ -1281,6 +1281,14 @@ The colors are determined by the variable
(pdf-cache-clear-images)
(pdf-view-redisplay t))
+(defun pdf-view-set-theme-background ()
+ "Set the buffer's color filter to correspond to the current Emacs theme."
+ (pdf-util-assert-pdf-buffer)
+ (pdf-info-setoptions
+ :render/foreground (face-foreground 'default nil)
+ :render/background (face-background 'default nil)
+ :render/usecolors 1))
+
(defun pdf-view-refresh-themed-buffer (&optional get-theme)
"Refresh the current buffer to activate applied colors.
@@ -1292,14 +1300,6 @@ current theme's colors."
(pdf-view-set-theme-background))
(pdf-view-redisplay t))
-(defun pdf-view-set-theme-background ()
- "Set the buffer's color filter to correspond to the current Emacs theme."
- (pdf-util-assert-pdf-buffer)
- (pdf-info-setoptions
- :render/foreground (face-foreground 'default nil)
- :render/background (face-background 'default nil)
- :render/usecolors t))
-
(define-minor-mode pdf-view-themed-minor-mode
"Synchronize color filter with the present Emacs theme.
@@ -1315,7 +1315,7 @@ The colors are determined by the `face-foreground' and
(t
(remove-hook 'after-save-hook #'pdf-view-set-theme-background t)
(remove-hook 'after-revert-hook #'pdf-view-set-theme-background t)
- (pdf-info-setoptions :render/usecolors nil)))
+ (pdf-info-setoptions :render/usecolors 0)))
(pdf-view-refresh-themed-buffer pdf-view-themed-minor-mode))
(when pdf-view-use-unicode-ligther