summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIllia Ostapyshyn <ilya.ostapyshyn@gmail.com>2021-05-13 19:34:36 +0200
committerVedang Manerikar <ved.manerikar@gmail.com>2021-05-29 12:44:19 +0530
commitf771c93781b3135200cae6dbc8e45dbb887f77b1 (patch)
tree55145baaa8e76170a3a7c56c3e3d85033f2e32be
parentd06acb9aaa0cf74b2db79eef69b293a7476524ea (diff)
Support HiDPI displays on vanilla emacs
Fixes the long-standing issue of displaying pdf contents in proper resolution on retina Macs using vanilla (not a fork) emacs [1], [2] This commit squashes changes contributed by @iostapyshyn. It introduces the following changes: - Use `frame-scale-factor` to detect HiDPI displays in preference to other methods. `frame-scale-factor` is a new function introduced in Vanilla Emacs to return the scale factor of the backing store. - Allow scaling for `png` type images as well (if `pdf-view-use-scaling` is `t`), since this works well and I'm not sure why it was originally disabled. 1: politza/pdf-tools#51 2: hlissner/doom-emacs#4989 Closes #13
-rw-r--r--lisp/pdf-cache.el3
-rw-r--r--lisp/pdf-util.el15
-rw-r--r--lisp/pdf-view.el13
3 files changed, 11 insertions, 20 deletions
diff --git a/lisp/pdf-cache.el b/lisp/pdf-cache.el
index e9a7ca5..50d7688 100644
--- a/lisp/pdf-cache.el
+++ b/lisp/pdf-cache.el
@@ -380,6 +380,7 @@ See also `pdf-info-renderpage-highlight' and
(pdf-cache-pagelinks
(pdf-view-current-page)))))))))
+(defvar pdf-view-use-scaling)
(defun pdf-cache--prefetch-pages (window image-width)
(when (and (eq window (selected-window))
(pdf-util-pdf-buffer-p))
@@ -388,7 +389,7 @@ See also `pdf-info-renderpage-highlight' and
(pdf-cache-lookup-image
page
image-width
- (if (not (pdf-view-use-scaling-p))
+ (if (not pdf-view-use-scaling)
image-width
(* 2 image-width))))
(setq page (pop pdf-cache--prefetch-pages)))
diff --git a/lisp/pdf-util.el b/lisp/pdf-util.el
index 3c4d77b..c57f6ec 100644
--- a/lisp/pdf-util.el
+++ b/lisp/pdf-util.el
@@ -945,15 +945,14 @@ See also `regexp-quote'."
(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
+When `pdf-view-use-scaling' is non-nil, return the scale factor of the frame
+if available. If the scale factor 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-view-use-scaling
+ (or (and (fboundp 'frame-scale-factor)
+ (truncate (frame-scale-factor)))
+ (and (fboundp 'frame-monitor-attributes)
+ (cdr (assq 'backing-scale-factor (frame-monitor-attributes))))
(if (>= (pdf-util-frame-ppi) 180)
2
1))
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index 03ff716..bb42e45 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -92,10 +92,7 @@ FIXME: Explain dis-/advantages of imagemagick and png."
This variable affects both the reuse of higher-resolution images
as lower-resolution ones by down-scaling the image. As well as
the rendering of higher-resolution for high-resolution displays,
-if available.
-
-It has no effect, unless either the imagemagick or image-io
-image-format is available."
+if available."
:group 'pdf-view
:type 'boolean)
@@ -911,12 +908,6 @@ See also `pdf-view-use-imagemagick'."
(t
(error "PNG image supported not compiled into Emacs"))))
-(defun pdf-view-use-scaling-p ()
- "Return t if scaling should be used."
- (and (memq (pdf-view-image-type)
- '(imagemagick image-io))
- pdf-view-use-scaling))
-
(defmacro pdf-view-create-image (data &rest props)
;; TODO: add DATA and PROPS to docstring.
"Like `create-image', but with set DATA-P and TYPE arguments."
@@ -935,7 +926,7 @@ See also `pdf-view-use-imagemagick'."
(let* ((size (pdf-view-desired-image-size page window))
(data (pdf-cache-renderpage
page (car size)
- (if (not (pdf-view-use-scaling-p))
+ (if (not pdf-view-use-scaling)
(car size)
(* 2 (car size)))))
(hotspots (pdf-view-apply-hotspot-functions