diff --git a/modules/tools/pdf/autoload/pdf.el b/modules/tools/pdf/autoload/pdf.el deleted file mode 100644 index 29818bc36..000000000 --- a/modules/tools/pdf/autoload/pdf.el +++ /dev/null @@ -1,30 +0,0 @@ -;;; tools/pdf/autoload/pdf.el -*- lexical-binding: t; -*- - -;;;###autoload -(defun +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args) - (cl-letf* ((old-create-image (symbol-function #'create-image)) - ((symbol-function #'create-image) - (lambda (file-or-data &optional type data-p &rest props) - (apply old-create-image file-or-data type data-p - :width (car (pdf-view-image-size)) - props)))) - (apply orig-fn args))) - -;;;###autoload -(defun +pdf--util-frame-scale-factor-a (orig-fn) - (if (and pdf-view-use-scaling - (memq (pdf-view-image-type) '(imagemagick image-io)) - (fboundp 'frame-monitor-attributes)) - (funcall orig-fn) - ;; Add special support for retina displays on MacOS - (if (and (eq (framep-on-display) 'ns) - EMACS27+) - 2 - 1))) - -;;;###autoload -(defun +pdf--view-use-scaling-p-a () - "Returns t if on ns window-system on Emacs 27+." - (and (eq (framep-on-display) 'ns) - EMACS27+ - pdf-view-use-scaling)) diff --git a/modules/tools/pdf/config.el b/modules/tools/pdf/config.el index 0664dcab3..91adab6e9 100644 --- a/modules/tools/pdf/config.el +++ b/modules/tools/pdf/config.el @@ -39,20 +39,6 @@ (pdf-view-goto-page page) (setq-local +pdf--page-restored-p t))))) - ;; Add retina support for MacOS users - (when IS-MAC - (advice-add #'pdf-util-frame-scale-factor :around #'+pdf--util-frame-scale-factor-a) - (advice-add #'pdf-view-use-scaling-p :before-until #'+pdf--view-use-scaling-p-a) - (defadvice! +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args) - :around '(pdf-annot-show-annotation - pdf-isearch-hl-matches - pdf-view-display-region) - (letf! (defun create-image (file-or-data &optional type data-p &rest props) - (apply create-image file-or-data type data-p - :width (car (pdf-view-image-size)) - props)) - (apply orig-fn args)))) - ;; Handle PDF-tools related popups better (set-popup-rules! '(("^\\*Outline*" :side right :size 40 :select nil) @@ -91,4 +77,39 @@ ;; Sets up `pdf-tools-enable-minor-modes', `pdf-occur-global-minor-mode' and ;; `pdf-virtual-global-minor-mode'. - (pdf-tools-install-noverify))) + (pdf-tools-install-noverify)) + + ;; Add retina support for MacOS users + (eval-when! IS-MAC + (defvar +pdf--scaled-p nil) + + (defadvice! +pdf--scale-up-on-retina-display-a (orig-fn &rest args) + "Scale up the PDF on retina displays." + :around #'pdf-util-frame-scale-factor + (cond ((not pdf-view-use-scaling) 1) + ((and (memq (pdf-view-image-type) '(imagemagick image-io)) + (fboundp 'frame-monitor-attributes)) + (funcall orig-fn)) + ;; Add special support for retina displays on MacOS + ((and (eq (framep-on-display) 'ns) + (not +pdf--scaled-p) + EMACS27+) + (setq-local +pdf--scaled-p t) + 2) + (1))) + + (defadvice! +pdf--use-scaling-on-ns-a () + :before-until #'pdf-view-use-scaling-p + (and (eq (framep-on-display) 'ns) + EMACS27+ + pdf-view-use-scaling)) + + (defadvice! +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args) + :around '(pdf-annot-show-annotation + pdf-isearch-hl-matches + pdf-view-display-region) + (letf! (defun create-image (file-or-data &optional type data-p &rest props) + (apply create-image file-or-data type data-p + :width (car (pdf-view-image-size)) + props)) + (apply orig-fn args)))))