Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support retina display on OSX #51

Open
brabalan opened this Issue Feb 14, 2015 · 30 comments

Comments

Projects
None yet
10 participants

Documents viewed with pdf-view are much fuzzier than when viewed with doc-view (I have set doc-view-resolution to 300). How can I increase the resolution for pfd-view? (I looked at the pdf-tools and pdf-view customize group but could not find a relevant option.)

Owner

politza commented Feb 14, 2015

Alan Schmitt notifications@github.com writes:

Documents viewed with pdf-view are much fuzzier than when viewed with
doc-view (I have set doc-view-resolution to 300).

Please post a comparison screenshot ?

doc-view:
screen shot 2015-02-14 at 10 31 55
pfd-view:
screen shot 2015-02-14 at 10 31 12

Owner

politza commented Feb 14, 2015

Alan Schmitt notifications@github.com writes:

doc-view:
screen s
pfd-view:
screen s

Could this be some bad anti-aliasing ?

As far as I know there is no need for a resolution in poppler, since all
PDF objects (images unless embedded, fonts) are vector-based, i.e. can
be, and are, rendered arbitrary large. Anyway, there are no knobs for
this. The resolution in doc-view simply determines the size of image,
but this is done automatically in pdf-view.

Would you mind uploading the PDF page ?

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=17 -dLastPage=17 -sOutputFile=page_17.pdf file.pdf

-ap

Here is the page: https://transfert.inria.fr/fichiers/038db3f7d96457232984b2f9ccae2355/page_17.pdf

This may be an emacs + retina macbook issue. I use this emacs https://github.com/railwaycat/emacs-mac-port which may do something special to display png. I'll open an issue there.

Edit: this probably explains why docview is not blury: https://github.com/railwaycat/emacs-mac-port/blob/7be6d9e8dbd122b060b058c0a345091debc52975/doc/emacs/macport.texi#L401

Owner

politza commented Feb 14, 2015

Alan Schmitt notifications@github.com writes:

Here is the page:

They look the same to me in doc-view and pdf-view.

-ap

Owner

politza commented Feb 14, 2015

Does this advice do the trick ?

(defadvice pdf-info-renderpage (before double-width-arg activate)
  (ad-set-arg 1 (* 2 (ad-get-arg 1))))

Unfortunately, no. (It also breaks the function that deal with resizing: fit to page is broken, and shrink-pdf and enlarge-pdf both enlarge it.)

PS: I don't think the blurry aspect is a bug on your side, it's more of a feature missing of emacs for OS X on Macs with retina display. I just tried increasing the resolution, and the picture becomes sharper. Unfortunately I don't know how to get pixel resolution to do a conclusive test.

I received an answer from YAMAMOTO Mitsuharu and he suggests an approach:

Multiple-resolution bitmap feature is only provided for files (i.e.,
"@2x" convention) or via TIFF format that can contain multiple
bitmaps. So, it is not directly applicable to the pdf-tools case
where PNG data is read from memory.

I skimmed over the pdf-tools source code, and I thought another
solution would be possible. The Mac port can render PDF data natively
in a resolution-independent way as described in the "Mac Images and
Colors" node in Emacs info:

The image-io image type also provides rasterization of several
document formats such as PDF, RTF, HTML, WEBARCHIVE, DOC, etc. The list
of supported formats can be obtained by evaluating (image-io-types).
Because the image-io image type accepts the same image descriptor
properties as the imagemagick image type does (*note
(elisp)ImageMagick Images::), you can specify the page number (0 for the
first page) of the document by the :index property and get the number
of pages by the image-metadata function.

So, it would be possible to make epdfinfo generate "distilled" PDF
data using cairo PDF surface (rather than rasterized PNG data using
cairo image surface), and then let the Mac port rasterize the PDF data
using the image-io image type. This way, the Mac port can
automatically re-render the generated PDF data even on resolution
changes.

As SVG images are inherently resolution-independent, the images are
automatically rendered with appropriate scaling for high-resolution
environment. Rasterization of documents by the image-io image type
mentioned above also takes account of resolution. Note that resolution
can change dynamically on Mac OS X 10.7 and later even for the same
frame, when it is moved from one monitor to another for example. The
Mac port detects such a resolution change and re-render images or reload
files automatically.

Do you think this could work?

Owner

politza commented Mar 3, 2015

I might (w/o to much trouble) if image-io behaves like an image, e.g. works with image-mode.

brabalan commented Mar 3, 2015

My understanding is that it works like imagemagick. Don't you already have support for it?

Owner

politza commented Mar 3, 2015

Alan Schmitt notifications@github.com writes:

My understanding is that it works like imagemagick. Don't you already
have support for it?

Yes...

@politza politza closed this Mar 15, 2015

Thank you for doing it. I'll test it as soon as it's propagated on Melpa.

I gave it a test and I do not see any change. Is there something special I need to do to activate it?

Owner

politza commented Mar 26, 2015

Alan Schmitt notifications@github.com writes:

I gave it a test and I do not see any change. Is there something
special I need to do to activate it?

I closed the issue because in my view it was resolved. I'm not going to
implement anything Mac specific.

@brabalan brabalan changed the title from Option to change resolution? to [WONTFIX] Option to change resolution? Mar 26, 2015

OK, I updated the issue title to reflect this.

I know the issue is closed, but I also would like retina resolution on pdf's on my mac. Putting this message here in case someone has an alternate solution/setup for those looking at this issue. (I don't get retina inside docview, either though).

@politza politza changed the title from [WONTFIX] Option to change resolution? to Support retina display on OSX Apr 21, 2015

@politza politza reopened this Apr 21, 2015

@dbrumley To get retina support in docview, you need to use this emacs version: https://github.com/railwaycat/emacs-mac-port.

In the meantime, I have found a workaround: I run at full retina resolution (and not half resolution by default). I have to increase the font size in emacs of course, but everything is super sharp.

dbrumley commented May 7, 2015

I'm sure this is a dumb question, but I couldn't find the answer googling. How do you run it at full resolution? Do you mean you run your mac itself at a non-default resolution, or there is an emacs setting?

It's a mac thing: you need an utility that gives you access to a "scaled" resolution that is actually not scaled (the preference panel does not let you use the full resolution of the screen).

I went back to the normal "double" resolution because the interface is really not meant to run at such a high resolution. So I'm back to square 1.

I'm posting here for posterity. If you are using macports, you can port install emacs-mac-app which installs a version with retina support. Now to view a pdf in retina mode you should name the file "foo@2x.pdf". I picked this up from https://github.com/railwaycat/emacs-mac-port/blob/7be6d9e8dbd122b060b058c0a345091debc52975/doc/emacs/macport.texi#L401

@dbrumley In PDFView mode, too?

@politza politza added the enhancement label Oct 20, 2015

I'm using 'emacs-mac-port', DocView renders pdfs in retina resolution. 'pdf-tools' does not. I prefer 'pdf-tools' becasue of many pdf tools it offers (outline mode etc) and hope that it will be possible to render in retina resolution with 'pdf-tools'.

kwf commented Apr 28, 2016

This issue is really important to me, and I suspect to other users as well. I'm willing to work on providing a fix, if given a pointer in the right direction. Where in the codebase should I start poking about?

On OSX:

$ sudo port install emacs-mac-app -imagemagick -rsvg

I believe, but do not know, that this is a fork of https://github.com/railwaycat/emacs-mac-port.git

  • I did notice that when I added +imagemagick +rsvg I no longer had retina support inside docview.
  • You don't really need the -imagemagick -rsvg options as they are the default. They are listed here to be explicit.
  • pdf-view-mode does not seem to offer retina support; it's only doc-view. Not sure why, and I have other emacs customizations to attend to.
Owner

politza commented May 23, 2016

Try to look into the image-io imagetype as suggested here:

#51 (comment)

Just wanted to chime in that this would be really, really nice to have. I was hoping @kwf made some progress to see if I could help but couldn't find any.

Also, @dbrumley, I'm one of the maintainers of the emacs-mac-app in MacPorts. The default variants shouldn't have affected retina support. If it's still a problem for you, feel free to open a bug with MacPorts.

kwf commented Aug 8, 2016

@seanfarley, I haven't had much time to take a look at this, but I'll certainly let you know if I get a chance to make any progress.

I'd just like to point out that there is a very ugly workaround to this issue, which certainly is not a good fix, but works for me until someone implements a patch.

The workaround is to use a utility that enables running the display at full Retina resolution, and then ensure that the full Retina resolution is only used when emacs is focused. The resolution transition is ugly, but if, like me, you primarily use emacs in fullscreen mode, it is bearable. Note that in order to enable full resolution on El Capitan and newer versions of OS X, you will need to disable system integrity protection (SIP). You only need to do this once; once the setting is enabled, you can switch to and from that resolution dynamically with system integrity protection on.

You will need to increase the default font height to keep emacs readable. I find that 256 works well on my 15" 2880x1800 display. I am using a paid, closed source piece of software because I figured I just needed something that worked and it wasn't worth an hour or three right then to find another piece of software.

I imagine that it would not be too difficult to write an open-source script to do a similar operation, and perhaps to improve on it by only changing the resolution only when emacs is fullscreen, if you only work with pdfs in fullscreen windows). I am not about to write one because I don't have time.

The closed-source tool I am currently using is SwitchResX. It has a trial version that works for 10 days, then costs $16. You'd want to create two "display sets," one called Full Resolution that is set to the native resolution of your monitor, and one called Native Resolution to the resolution you prefer to work in for other applications. In SetResX Preferences > Applications, set All Applications to Normal Resolution and Emacs to Full Resolution, checking the boxes Reset Display Settings when Application Ends and Apply again display settings when application comes to front. Before it will actually work, you'll need to disable SIP and move into full resolution. You can then reenable SIP. More details on SIP here: http://www.madrau.com/support/support/srx_1011.html

hisnawi commented Sep 11, 2017

Any update on this?

It has been a while, but @politza can you develop a bit more on how one could implement the suggestion in Yamamoto comment above? I.e. how to make epdfinfo produce a pdf and then raster it with image-io?

Alternatively, is someone already working on a different fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment