Merge pull request #350 from HollowMan6/pdf-follow-theme

PDF Viewer: Make PDF background and annotate color follow emacs theme
master
Andy Stewart 6 years ago committed by GitHub
commit 45e2fd9713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/pdf-viewer/buffer.py
  2. 18
      eaf.el

@ -256,8 +256,10 @@ class PdfViewerWidget(QWidget):
self.page_annotate_height = 22
self.page_annotate_padding_right = 10
self.page_annotate_padding_bottom = 10
self.page_annotate_light_color = QColor("#333333")
self.page_annotate_dark_color = QColor("#999999")
self.page_annotate_light_color = QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"])
self.page_annotate_dark_color = QColor(1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).redF(),\
1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).greenF(),\
1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).blueF())
self.font = QFont()
self.font.setPointSize(12)
@ -273,6 +275,16 @@ class PdfViewerWidget(QWidget):
self.remember_offset = None
def handle_color(self,color,inverted=False):
r = float(color.redF())
g = float(color.greenF())
b = float(color.blueF())
if inverted:
r = 1.0-r
g = 1.0-g
b = 1.0-b
return (r,g,b)
def repeat_to_length(self, string_to_expand, length):
return (string_to_expand * (int(length/len(string_to_expand))+1))[:length]
@ -316,6 +328,10 @@ class PdfViewerWidget(QWidget):
self.char_dict[index] = self.get_page_char_rect_list(index)
self.select_area_annot_cache_dict[index] = None
if self.emacs_var_dict["eaf-pdf-dark-mode"] == "follow":
col = self.handle_color(QColor(self.emacs_var_dict["eaf-emacs-theme-background-color"]), self.inverted_mode)
page.drawRect(page.rect, color=col, fill=col, overlay=False)
trans = self.page_cache_trans if self.page_cache_trans is not None else fitz.Matrix(scale, scale)
pixmap = page.getPixmap(matrix=trans, alpha=False)

@ -275,7 +275,9 @@ It must defined at `eaf-browser-search-engines'."
(eaf-mindmap-dark-mode . "follow")
(eaf-mindmap-save-path . "~/Documents")
(eaf-marker-letters . "ASDFHJKLWEOPCNM")
(eaf-emacs-theme-mode . ""))
(eaf-emacs-theme-mode . "")
(eaf-emacs-theme-background-color . "")
(eaf-emacs-theme-foreground-color . ""))
"The alist storing user-defined variables that's shared with EAF Python side.
Try not to modify this alist directly. Use `eaf-setq' to modify instead."
@ -2088,13 +2090,25 @@ Make sure that your smartphone is connected to the same WiFi network as this com
(defun eaf-get-theme-mode ()
(format "%s"(frame-parameter nil 'background-mode)))
(defun eaf-get-theme-background-color ()
(format "%s"(frame-parameter nil 'background-color)))
(defun eaf-get-theme-foreground-color ()
(format "%s"(frame-parameter nil 'foreground-color)))
(eaf-setq eaf-emacs-theme-mode (eaf-get-theme-mode))
(eaf-setq eaf-emacs-theme-background-color (eaf-get-theme-background-color))
(eaf-setq eaf-emacs-theme-foreground-color (eaf-get-theme-foreground-color))
(advice-add 'load-theme :around #'eaf-monitor-load-theme)
(defun eaf-monitor-load-theme (orig-fun &optional arg &rest args)
"Update `eaf-emacs-theme-mode' after execute `load-theme'."
(apply orig-fun arg args)
(eaf-setq eaf-emacs-theme-mode (eaf-get-theme-mode)))
(eaf-setq eaf-emacs-theme-mode (eaf-get-theme-mode))
(eaf-setq eaf-emacs-theme-background-color (eaf-get-theme-background-color))
(eaf-setq eaf-emacs-theme-foreground-color (eaf-get-theme-foreground-color)))
(define-minor-mode eaf-pdf-outline-mode
"EAF pdf outline mode."

Loading…
Cancel
Save