Giter Site home page Giter Site logo

Comments (6)

fakedrake avatar fakedrake commented on August 15, 2024 4

Have you tried (defun pdf-util-frame-scale-factor () 2)? In case that works, what is (frame-scale-factor) returning? And (pdf-util-frame-scale-factor)? And pdf-view-use-scaling?

Yes that works! Turns out I hadn't properly set pdf-view-use-scaling to t correctly and I should have RTFM more carefully. Thanks a lot!

from pdf-tools.

memeplex avatar memeplex commented on August 15, 2024 2

Ok, I'm closing this because it has indeed been fixed in emacs 28. There is a lot of confusion around this issue so for other ones in the same boat: the ns/cocoa/official port does work but you require the latest dev version of it. You probably are using org mode and write LaTeX so you also want svg rendering. Just install emacs 28 from brew with a few extensions pre-enabled: brew install emacs-plus@28.

from pdf-tools.

memeplex avatar memeplex commented on August 15, 2024

Just to be clear, the documentation for pdf-view-use-scaling states:

Whether images should be allowed to be scaled for rendering.

But it's all the document that is rendered blurry, not just images.

from pdf-tools.

memeplex avatar memeplex commented on August 15, 2024
(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, 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 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))
    1))

Here both (fboundp 'frame-scale-factor) and (assq 'backing-scale-factor (frame-monitor-attributes)) are nil, so there's a fallback to the last clause.

Now:

(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)))

Here frame-monitor-attributes reports 1280px x 800px, so ppi < 180 and ultimately pdf-util-frame-scale-factor is returning 1.

I think this is ignoring the fact that the reported pixels are not physical ones.

Now, if I force pdf-util-frame-scale-factor to return 2, then the resolution of the output is the right one. Comparing the output to the one of Preview, there surely is room for improvement, since pdf-view rendering is a bit too thin in comparison, but it's clear that's not a matter of resolution anymore.

So my horrible workaround was (defun pdf-util-frame-scale-factor () 2).

from pdf-tools.

fakedrake avatar fakedrake commented on August 15, 2024

I am on emacs 28 and I still see the image blurry, and what you describe in your previous comment is almost exactly what is going on (only my resolution is 1440x900). Is there some setting that I need to adjust to fix it?

from pdf-tools.

memeplex avatar memeplex commented on August 15, 2024

only my resolution is 1440x900

This is MacBook's default as per late, they changed the default scaling factor from 2 to 1.75 a few years ago and I always scale up to 2 again first thing. But it shouldn't be the issue, since emacs will be rendering at 2x and the system is in charge to downscale that to 1.75, the downscaled version might be a little blurry but then it's the same for the rest of the system because that's what macOS does in general.

Have you tried (defun pdf-util-frame-scale-factor () 2)? In case that works, what is (frame-scale-factor) returning? And (pdf-util-frame-scale-factor)? And pdf-view-use-scaling?

from pdf-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.