Export to GitHub

phantomjs - issue #659

Ensure a consistent 72 dpi for Linux headless


Posted on Jul 13, 2012 by Quick Rabbit

Apparently the screen resolution is not set to 72 dpi on every platform we support.

Comment #1

Posted on Jul 13, 2012 by Quick Rabbit

Discussion: https://groups.google.com/forum/?fromgroups#!topic/phantomjs/YQIyxLWhmr0.

Comment #2

Posted on Jul 13, 2012 by Quick Rabbit

Related pull request: https://github.com/ariya/phantomjs/pull/286.

Comment #3

Posted on Sep 19, 2012 by Quick Rabbit

Rescheduled to 1.8.

Comment #4

Posted on Oct 15, 2012 by Happy Horse

I agree that we should provide a consistent default value of 72 for resolution (DPI) fonts, PDFs, etc. across all supported platforms. However, I also think we should provide the user with a mechanism to set their own choice DPI, as mentioned by other users in comments on the Pull Request and in forum discussions, e.g. https://groups.google.com/forum/m/?fromgroups#!topic/phantomjs/V9EU0UdT1cg

Comment #5

Posted on Dec 23, 2012 by Quick Rabbit

Rescheduled to 1.9.

Comment #6

Posted on Dec 23, 2012 by Quick Rabbit

I found that all we need is to implement physicalSize() for our minimalistic QPlatformScreen implementation. Because it was not implemented, the default 100 dpi was used and that causes the inconsistency.

Comment #7

Posted on Dec 23, 2012 by Quick Rabbit

It's more complicated on Windows because Qt just uses the values from GetDeviceCaps and LOGPIXELSX/LOGPIXELSY. According to http://stackoverflow.com/questions/645352/is-the-number-of-pixels-per-inch-standard-on-all-windows-pc-displays-logpixels, the return values could be anything from 88, 96, 120, and maybe even more variations on the future Windows version.

I think nothing we can do about Windows for the near future. Hence, I plan to change the issue title to only cover OS X and Linux.

Comment #8

Posted on Dec 23, 2012 by Quick Rabbit

Linux: Ensure we use 72 dpi. https://github.com/ariya/phantomjs/commit/3f42fb230f

Comment #9

Posted on Dec 23, 2012 by Quick Rabbit

(No comment was entered for this change.)

Comment #10

Posted on Dec 23, 2012 by Quick Rabbit

(No comment was entered for this change.)

Comment #11

Posted on Dec 23, 2012 by Happy Horse

(No comment was entered for this change.)

Comment #12

Posted on Dec 23, 2012 by Happy Horse

Filed Issue #934 to pursue fixing this for Windows in the future.

Comment #13

Posted on Dec 23, 2012 by Happy Wombat

Still not fixed for me :( For some reason I still have different pdf outputs from mac os x version and from linux version

Comment #14

Posted on Dec 23, 2012 by Quick Rabbit

What about PNG output? The PDF output relies on the print engine which may have some slight differences.

Comment #15

Posted on Dec 23, 2012 by Quick Rabbit

With the 72 dpi change I have committed, QWebFrame::print gives zoomFactorX and zoomFactorY both to 1.

Comment #16

Posted on Dec 24, 2012 by Quick Rabbit

Here is a test script I used:;

var page = require('webpage').create(); page.content = '

Hello

'; page.render('dpi.pdf'); phantom.exit();

The PDF results can be seen in the attachment, as well as the comparison screenshot.

Attachments

Comment #17

Posted on Dec 24, 2012 by Happy Wombat

try this:

var page = require('webpage').create();

page.paperSize = { format: 'A4', margin: "1cm", };

page.content = "Test"; page.render("out.pdf"); phantom.exit();

out.1.6-linux-mypatch obtained with the force dpi=72 patch added to phantomjs 1.6 (https://github.com/ariya/phantomjs/pull/286)

Attachments

Comment #18

Posted on Dec 24, 2012 by Quick Rabbit

Did you try with version 1.8? Unfortunately, this one did not make it to 1.8. It will be part of 1.9, meanwhile you need to build it yourself.

Attachments

Comment #19

Posted on Jan 5, 2013 by Quick Rabbit

Issue 750 has been merged into this issue.

Comment #20

Posted on Mar 16, 2013 by Happy Horse

This issue has been moved to GitHub: https://github.com/ariya/phantomjs/issues/10659

Status: Fixed

Labels:
Type-Defect Priority-Medium Milestone-Release1.9 Component-Logic Module-WebPage Domain-Qt