Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 150870 - GTK+ Printer getDPI returns 72 x 72
Summary: GTK+ Printer getDPI returns 72 x 72
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux-GTK
: P3 normal with 6 votes (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Carolyn MacLeod CLA
QA Contact: Carolyn MacLeod CLA
URL:
Whiteboard:
Keywords:
: 260661 (view as bug list)
Depends on:
Blocks: 362999
  Show dependency tree
 
Reported: 2006-07-17 16:49 EDT by Carolyn MacLeod CLA
Modified: 2011-11-06 14:15 EST (History)
16 users (show)

See Also:


Attachments
a patch to test (6.39 KB, patch)
2010-01-18 11:27 EST, Mariot Chauvin CLA
no flags Details | Diff
Patch v01 (5.39 KB, patch)
2010-03-31 10:05 EDT, Praveen CLA
no flags Details | Diff
patch for the fix (10.98 KB, patch)
2010-10-25 13:00 EDT, Carolyn MacLeod CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2006-07-17 16:49:31 EDT
20060717

Printer.getDPI() currently returns a constant: 72 x 72.
This is even for printers that can print 300 x 300 or 600 x 600 DPI.

This may be the reason that fonts print large and lines print 'fat' on GTK+, but I needed to do this because when I return the correct DPI, 'pixel' coordinates passed to draw routines are not correct for printer. (And I do not want to change every draw routine in GC at this time).

There is some kind of 'resolution' problem that needs to be fixed. This is partly (but not completely) because of http://bugzilla.gnome.org/show_bug.cgi?id=346245

Still need to figure out the problem here.
Comment 1 Carolyn MacLeod CLA 2006-07-17 17:20:00 EDT
Note that even the GTK+ Printing Demo prints using a large font.
Comment 2 Marcos César de Oliveira CLA 2007-05-07 18:22:42 EDT
I made some tests and seems that if the Printer.getDPI() method returns same value than the Display.getDPI() method, the fonts are printed in the correct size.
Comment 3 trevor campbell CLA 2007-05-26 23:03:42 EDT
Using gtk+-2.10.12

On my system, using debug in eclipse, at a breakpoint in Printer.getDPI() I get:
OS.gtk_print_settings_get_resolution(settings) returns  (int) 300

This seems to imply gtk_print_settings_get_resolution(settings) has been fixed, but the method OS.gtk_page_setup_get_paper_width (pageSetup, OS.GTK_UNIT_PIXEL) still returns a bogus value (actually points).

Looks like possible hack may now be available to use OS.gtk_page_setup_get_paper_width (pageSetup, OS.GTK_UNIT_INCH) * OS.gtk_print_settings_get_resolution(settings) to get the true page size in pixels and 

OS.gtk_print_settings_get_resolution(settings) to get the DPI.

Comment 4 trevor campbell CLA 2009-07-07 02:13:22 EDT
Actually I think to get the DPI you need:
int jobSettings = OS._gtk_print_job_get_settings(printJob);
int resolution = OS.gtk_print_settings_get_resolution(jobSettings);

But this only seems to work for real printers and not print to file.
Comment 5 Paul Webster CLA 2009-07-07 05:37:04 EDT
*** Bug 260661 has been marked as a duplicate of this bug. ***
Comment 6 Mariot Chauvin CLA 2010-01-18 11:27:03 EST
Created attachment 156403 [details]
a patch to test

If the OS.gtk_print_settings_get_resolution returns 0, I try to get the dpi from cairo surface (http://www.cairographics.org/manual/cairo-surface.html#cairo-surface-get-fallback-resolution) which should work even when printing to file.
Comment 7 Carolyn MacLeod CLA 2010-01-18 12:06:03 EST
Praveen, can you have a look at this, please? Consider the patch, and also read all comments, including in the dup. Thanks!
Comment 8 Patrik Dufresne CLA 2010-03-24 09:54:28 EDT
(In reply to comment #7)
> Praveen, can you have a look at this, please? Consider the patch, and also read
> all comments, including in the dup. Thanks!

Any progress on this bug ?
Comment 9 Matthew Hall CLA 2010-03-26 02:21:04 EDT
Ping.  This is a real problem on Linux.  I'd really appreciate it if anybody on the SWT team could devote some time to fixing this.

I'll buy a curry for whoever fixes this!
Comment 10 Praveen CLA 2010-03-31 10:05:30 EDT
Created attachment 163532 [details]
Patch v01

For unknown reason, the patch submitted by Mariot Chauvin (in comment#6) doesn't work on my machine, though the way problem fixed appears to be fair enough.
I tried various ways of fixing this problem and then, realized that having DPI set to 96 (Cairo default resolution) make the printer to correctly print the data with the appropriate font size. So, I have modified patch from comment#6 to make the printer working on both Printer and PrintToFile. Thanks Mariot for your patch !
I have tested Printer using these code changes on couple of machines and the Printing appears to be fine from a self-hosted Eclipse and snippets.
Carolyn, please review this patch and post your comments. Thanks.
Comment 11 mike CLA 2010-04-09 17:36:18 EDT
As an eclispse user (who is very gratified that you have fixed this bug!) how to apply the Patch?

Thanks
-Mike
Comment 12 Carolyn MacLeod CLA 2010-04-09 17:47:40 EDT
It's not fixed yet.  :)
Praveen, I think it's important to use cairo_surface_get_fallback_resolution.
Can you find out why it is not working on your machine? I suspect that it is because it is only available in Cairo 1.8. What version of Cairo do you have?
Comment 13 Praveen CLA 2010-05-10 10:28:54 EDT
(In reply to comment #12)
> It's not fixed yet.  :)
> Can you find out why it is not working on your machine? I suspect that it is
> because it is only available in Cairo 1.8. What version of Cairo do you have?

I have Cairo 1.8.2 installed already on my machine. Even in that case, fallback resolution is returned as '0'. If we use the resulotion as 300, then the font size printed on the paper is quite low and not clear. So, I don't think we can use higher resolution with the existing mechanism to render the printed paper correcly.
Why do you think that the problem is not fixed with the existing patch ? I can see the fonts are being rendered correctly as expected on the printed paper.
Comment 14 meisiman CLA 2010-09-16 05:40:28 EDT
Hello,

is someone still working on the patch ? It would be nice if I can use Eclipse for printing source code.

Best,
  Danny.
Comment 15 Carolyn MacLeod CLA 2010-10-25 13:00:37 EDT
Created attachment 181664 [details]
patch for the fix

Now that gtk bug https://bugzilla.gnome.org/show_bug.cgi?id=346252 is fixed
(since GTK 2.17.11) and I can accurately get the printer's resolution, I can do the correct scaling to fix this problem.
Comment 16 Carolyn MacLeod CLA 2010-10-25 13:01:30 EDT
fixed > 20101025.
This is now in HEAD, and it will be in Eclipse 3.7 M3.
Comment 17 Peter Severin CLA 2011-11-06 12:58:55 EST
The fix for this bug breaks scaling in GEF/Draw2d. I reported the issue in Bug 362999.