Fix #4299: refactor retina support for pdfs
This commit is contained in:
parent
e4890f6ac9
commit
8914b7b8ab
2 changed files with 36 additions and 45 deletions
|
@ -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))
|
|
@ -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)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue