diff options
| author | Nathaniel Nicandro <nathanielnicandro@gmail.com> | 2019-02-06 12:16:13 -0600 |
|---|---|---|
| committer | Andreas Politz <politza@hochschule-trier.de> | 2019-02-19 20:19:40 +0100 |
| commit | b5f51269422ff9852b1ef61d868d1adf5ebc82ad (patch) | |
| tree | 35ea083d79497474064f44b8159d34bf8b997e70 | |
| parent | 25faca4a279b13ae7c94a66b8c387fa8407300c9 (diff) | |
Support high-resolution displays
| -rw-r--r-- | lisp/pdf-info.el | 2 | ||||
| -rw-r--r-- | lisp/pdf-util.el | 31 | ||||
| -rw-r--r-- | lisp/pdf-view.el | 9 |
3 files changed, 39 insertions, 3 deletions
diff --git a/lisp/pdf-info.el b/lisp/pdf-info.el index 3eeacf8..6dd7ff6 100644 --- a/lisp/pdf-info.el +++ b/lisp/pdf-info.el @@ -1594,7 +1594,7 @@ Return the data of the corresponding PNG image." 'renderpage (pdf-info--normalize-file-or-buffer file-or-buffer) page - width + (* width (pdf-util-frame-scale-factor)) (let (transformed) (while (cdr commands) (let ((kw (pop commands)) diff --git a/lisp/pdf-util.el b/lisp/pdf-util.el index a521ec6..3955fb6 100644 --- a/lisp/pdf-util.el +++ b/lisp/pdf-util.el @@ -37,6 +37,8 @@ (declare-function pdf-view-current-overlay "pdf-view") (declare-function pdf-cache-pagesize "pdf-cache") +(declare-function pdf-view-image-type "pdf-view") + ;; * ================================================================== * @@ -918,6 +920,35 @@ See also `regexp-quote'." (push ch escaped)) (apply 'string (nreverse escaped)))) +(defun pdf-util-frame-ppi () + "Return the PPI of the current frame." + (let* ((props (frame-monitor-attributes)) + (px (nthcdr 2 (alist-get 'geometry props))) + (mm (alist-get 'mm-size props)) + (dp (sqrt (+ (expt (nth 0 px) 2) + (expt (nth 1 px) 2)))) + (di (sqrt (+ (expt (/ (nth 0 mm) 25.4) 2) + (expt (/ (nth 1 mm) 25.4) 2))))) + (/ dp di))) + +(defvar pdf-view-use-scaling) + +(defun pdf-util-frame-scale-factor () + "Return the frame scale factor depending on the image type used for display. +When `pdf-view-use-scaling' is non-nil and imagemagick or +image-io are used as the image type for display, return the +backing-scale-factor of the frame if available. If a +backing-scale-factor attribute isn't available, return 2 if the +frame's PPI is larger than 180. Otherwise, return 1." + (if (and pdf-view-use-scaling + (memq (pdf-view-image-type) '(imagemagick image-io)) + (fboundp 'frame-monitor-attributes)) + (or (cdr (assq 'backing-scale-factor (frame-monitor-attributes))) + (if (>= (pdf-util-frame-ppi) 180) + 2 + 1)) + 1)) + ;; * ================================================================== * ;; * Imagemagick's convert diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index cc85c05..d4367fd 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -903,6 +903,8 @@ See also `pdf-view-use-imagemagick'." (cond ((and pdf-view-use-imagemagick (fboundp 'imagemagick-types)) 'imagemagick) + ((image-type-available-p 'image-io) + 'image-io) ((image-type-available-p 'png) 'png) ((fboundp 'imagemagick-types) @@ -912,8 +914,8 @@ See also `pdf-view-use-imagemagick'." (defun pdf-view-use-scaling-p () "Return t if scaling should be used." - (and (eq 'imagemagick - (pdf-view-image-type)) + (and (memq (pdf-view-image-type) + '(imagemagick image-io)) pdf-view-use-scaling)) (defmacro pdf-view-create-image (data &rest props) @@ -933,6 +935,9 @@ See also `pdf-view-use-imagemagick'." (* 2 (car size))))) (hotspots (pdf-view-apply-hotspot-functions window page size))) + (when (and (eq (framep-on-display) 'mac) + (= (pdf-util-frame-scale-factor) 2)) + (put-text-property 0 1 :data-2x data data)) (pdf-view-create-image data :width (car size) :map hotspots |
