doomemacs / doomemacs

An Emacs framework for the stubborn martian hacker
MIT License
19.35k stars 3.05k forks source link

Searching PDFs causes it to scale up/zoom in #4299

Closed jeffalstott-iarpa closed 3 years ago

jeffalstott-iarpa commented 3 years ago

What did you expect to happen? Able to open a PDF and search within it.

What actually happened? Search "works", but each keystroke causes the PDF to zoom in, rendering it useless.

Additional details: Described on pdf-tools main repo here: https://github.com/politza/pdf-tools/issues/634

Just about to search image typed "b" image Oh, it started zooming. I...guess that makes sense? Let's type "a" image Uh, that's a bit much zoom. Let's type "c" image Uuuuh. "k" image

Steps to reproduce:

  1. Fresh install of Doom Emacs on OS X
  2. Uncomment pdf in init.el
  3. doom sync and restart
  4. Open a PDF
  5. Type / and start searching

System information:

SYSTEM  type       darwin
        config     x86_64-apple-darwin19.5.0
        shell      /bin/bash
        uname      Darwin 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
        path       (/opt/anaconda3/bin /opt/anaconda3/condabin /usr/local/bin /usr/bin /bin /usr/sbin /sbin ~/.emacs.d/bin /usr/local/Cellar/emacs-plus@27/27.1/libexec/emacs/27.1/x86_64-apple-darwin19.5.0/)
EMACS   dir        ~/.emacs.d/
        version    27.1
        build      Aug 27, 2020
        buildopts  --disable-dependency-tracking --disable-silent-rules --enable-locallisppath=/usr/local/share/emacs/site-lisp --infodir=/usr/local/Cellar/emacs-plus@27/27.1/share/info/emacs --prefix=/usr/local/Cellar/emacs-plus@27/27.1 --with-xml2 --with-gnutls --without-dbus --with-imagemagick --with-modules --with-rsvg --with-ns --disable-ns-self-contained
        features   RSVG IMAGEMAGICK GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS JSON PDUMPER LCMS2 GMP
        traits     (server-running envvar-file)
DOOM    dir        ~/.doom.d/
        version    2.0.9
        build      grafted, HEAD -> develop, origin/develop, origin/HEAD a835be1 2020-10-16 04:19:27 -0400
        elc-files  0
        modules    (:completion company ivy :ui deft doom doom-dashboard doom-quit hl-todo modeline ophints (popup +defaults) vc-gutter vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold snippets :emacs dired electric undo vc :checkers syntax :tools (eval +overlay) lookup magit pdf :os macos :lang emacs-lisp markdown (org +roam +journal +dragndrop +pomodoro +noter) sh :config (default +bindings +smartparens))
        packages   ((org-ref) (helm-bibtex) (org-roam-bibtex))
        unpin      (n/a)
        elpa       (request dash anki-editor)
hlissner commented 3 years ago

I cannot reproduce this, but I presume it has something to do with HiDPI support (since I don't have a hidpi display). Try disabling pdf-view-use-scaling

(after! pdf-view
  (setq pdf-view-use-scaling nil))

Or undo our retina hacks:

(after! pdf-view
  (advice-remove #'pdf-util-frame-scale-factor #'+pdf--util-frame-scale-factor-a)
  (advice-remove #'pdf-view-use-scaling-p #'+pdf--view-use-scaling-p-a)
  (dolist (fn '(pdf-annot-show-annotation
                pdf-isearch-hl-matches
                pdf-view-display-region))
    (advice-remove fn #'+pdf--supply-width-to-create-image-calls-a)))
jeffalstott-iarpa commented 3 years ago

The first suggestion didn't work but the second did! Unfortunately, it does leave the PDF looking quite blurry. What would you suggest for next steps to retain the bulk of the high-resolution functionality while still getting search?

hlissner commented 3 years ago

It's tricky, I'm afraid. I don't have a mac, much less a retina display to test this on, so I'll need your help to find the solution. Please remove the snippet I suggested earlier and try this instead:

(after! pdf-view
  (defvar +pdf--is-scaled-p nil)
  (defadvice! add-retina-support-a (orig-fn &rest args)
    :around #'pdf-util-frame-scale-factor
    (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)
               (not +pdf--is-scaled-p)
               EMACS27+)
          (progn
            (setq-local +pdf--is-scaled-p t)
            2)
        1)))
  (advice-remove #'pdf-util-frame-scale-factor  #'+pdf--util-frame-scale-factor-a))
hlissner commented 3 years ago

Side note: could you do M-: (pdf-util-frame-ppi) in that pdf buffer and tell me it return value?

jeffalstott-iarpa commented 3 years ago

With your latest modification:

image And search still works.

Without the modification: image And search has the zooming problem.

So, it looks like that fixed it!

could you do M-: (pdf-util-frame-ppi) in that pdf buffer and tell me it return value? Having difficulty with that: image I'm new to emacs, but hitting alt+: (which, for completeness, is alt+shift+the ;/: key) gives the above response. So I don't get to the point of being able to type pdf-util-frame-ppi

hlissner commented 3 years ago

I'm new to emacs, but hitting alt+: (which, for completeness, is alt+shift+the ;/: key) gives the above response. So I don't get to the point of being able to type pdf-util-frame-ppi

Then could you try M-x eval-expression RET (pdf-util-frame-ppi) (must be run from the pdf file).

jeffalstott-iarpa commented 3 years ago

That worked! 128.1596... Was that what you were expecting?

hlissner commented 3 years ago

As of 8914b7b this issue should be resolved. Let me know if that isn't the case and I'll reopen it. Thanks for bringing it to my attention!

That worked! 128.1596... Was that what you were expecting?

Yup, thanks!