After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 488833 - Use cairo_win32_printing_surface_t for printing on win32
Use cairo_win32_printing_surface_t for printing on win32
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Windows
: Normal blocker
: ---
Assigned To: gtk-bugs
Depends on:
Blocks: 518052 521178
 
 
Reported: 2007-10-21 16:42 UTC by Behdad Esfahbod
Modified: 2008-04-01 20:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
untested patch (1.35 KB, patch)
2007-11-28 05:08 UTC, Behdad Esfahbod
none Details | Review
gtk-demo print output without patch (48.92 KB, application/pdf)
2008-03-31 13:20 UTC, Cody Russell
  Details
gtk-demo print output WITH patch (2.16 KB, application/pdf)
2008-03-31 13:22 UTC, Cody Russell
  Details
Fixed patch (3.13 KB, patch)
2008-03-31 20:46 UTC, Cody Russell
none Details | Review
Updated comment (3.25 KB, patch)
2008-03-31 21:09 UTC, Cody Russell
none Details | Review
Removed some debugging output (2.46 KB, patch)
2008-03-31 21:46 UTC, Cody Russell
committed Details | Review

Description Behdad Esfahbod 2007-10-21 16:42:48 UTC
It will be in cairo 1.6.
Comment 1 Behdad Esfahbod 2007-11-28 05:08:22 UTC
Created attachment 99752 [details] [review]
untested patch

I'm not sure if both instances of cairo_win32_surface_create() need to be changed.  Alex should know.

Tor, can you check too?
Comment 2 Alexander Larsson 2007-11-28 08:08:27 UTC
The second one is for generating a EMF file when doing print preview. I think its right to use a printing surface there too, as we should do the same ops in both print and print preview.
Comment 3 Adrian Johnson 2008-02-22 08:41:15 UTC
You definitely want to use the win32_printing surface when generating EMF files. Using the win32 surface to create EMF files has the same issues as using the win32 surface for printing.

However I'm not sure what the benefit of using EMF for print previews is when using cairo. Cairo is designed to provide identical output on all surfaces. Using the win32 surface to display a preview on the display will provide more optimal results since playing back the EMF is not going to give you any antialising except for text (win32 fonts only).
Comment 4 Behdad Esfahbod 2008-02-22 08:49:03 UTC
(In reply to comment #3)
> Cairo is designed to provide identical output on all surfaces.

Sans the different default font options on different surfaces.
Gtk-printing does turn off metrics hinting though, so should be safe.
Comment 5 Rygle 2008-03-18 13:52:21 UTC
Behdad: Can I ask for some clarification. Does your comment "It will be in cairo 1.6" mean;

* the function cairo_win32_printing_surface() will be in Cairo 1.6 and should be made use of?
OR
* The fix for this bug will be in Cairo 1.6, which will force GTK to make use of the cairo_win32_printing_surface() function, and therefore GTK doesn't need to be patched, but just to wait for Cairo 1.6?

Cheers,

Rygle.
Comment 6 Behdad Esfahbod 2008-03-18 13:56:58 UTC
(In reply to comment #5)
> Behdad: Can I ask for some clarification. Does your comment "It will be in
> cairo 1.6" mean;
> 
> * the function cairo_win32_printing_surface() will be in Cairo 1.6 and should
> be made use of?
> OR
> * The fix for this bug will be in Cairo 1.6, which will force GTK to make use
> of the cairo_win32_printing_surface() function, and therefore GTK doesn't need
> to be patched, but just to wait for Cairo 1.6?
> 
> Cheers,
> 
> Rygle.

The former.
Comment 7 Rygle 2008-03-18 22:51:52 UTC
Thanks Behdad.

Are you aware of anyone who has tested your patch? Or a build of gtk for windows that uses it?

It's a bit over my head to patch it myself, but I am willing to test a windows build against Inkscape 0.46 dev. Since starting to use the Gnome common print dialog, Inkscape 0.46dev for windows (not linux) has a bug which seems to link to this one, where it outputs print with blocks of white or black (see https://bugs.launchpad.net/inkscape/+bug/179988). Some of this may be in the Inkscape code (cairo_win32_printing_surface_create() needs a non-null HDC?), but if possible I am keen to try a build of GTK with your patch to test it.

Thanks. Rygle.
Comment 8 Behdad Esfahbod 2008-03-19 12:27:50 UTC
No I'm not.  I was hoping that Tor or Adrian can test it so this can be committed.
Comment 9 Cody Russell 2008-03-21 01:17:13 UTC
I'll try to test tonight or tomorrow since I have an interest in this one as well.
Comment 10 Rygle 2008-03-22 01:52:46 UTC
Cody, I would love to test any GTK dll's if you're able to build them. The build process looks pretty scary for mingw newbs!

Thanks, Rygle.
Comment 11 Rygle 2008-03-22 02:01:37 UTC
I should have also said that in Inkscape, we've currently got a hack that directly uses the cairo_win32_printing_surface by bypassing GTK, but it is a hack and not ideal. Adrian has stated that he thinks this patch will fix the problem properly, but is unable to build a patched GTK at present.

If anyone is able to build patched binaries and you're stuck for a temporary place to put them, mediafire.com would be a great spot.

Thanks again for any help. Rygle.
Comment 12 Rygle 2008-03-27 06:18:31 UTC
Hi guys,

Looks like this won't get fixed for a while, but for Inkscape 0.46 Win32, we're using some code like the following to bypass GTK if it doesn't use the win32 printing surface.

This code is called on printing, and checks if the surface returned by gtkprint is of type CAIRO_SURFACE_TYPE_WIN32 before substituting it with win32_printing_surface. The code will work correctly if gtkprint returns some other surface like pdf. It will also ensure that when gtkprint is fixed to use the surface of type CAIRO_SURFACE_TYPE_WIN32_PRINTING, the workaround will be bypassed.

=========
#ifdef WIN32
 if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_WIN32) {
        HDC dc = cairo_win32_surface_get_dc (surface);
        surface = _cairo_win32_printing_surface_create (dc);
 }
#endif
=========

That goes on to directly call cairo_win32_printing_surface_t, but will default back to the GTK print routines if GTK says it's already using that surface.

Hopefully you guys can fix this soon, but until then hopefully this code helps someone else.
Comment 13 Cody Russell 2008-03-31 13:19:21 UTC
I just tried applying Behdad's patch as-is (to gtk-2-12 branch, since that's what I've been building--is that a problem do you think?), and it doesn't seem to be working as expected.

I'll attach two PDFs below to show the output I'm getting.  I've got my printer driver set to use PDFCreator, so I suppose maybe it's at fault.  I can try plugging a real printer into this machine if you want.
Comment 14 Cody Russell 2008-03-31 13:20:43 UTC
Created attachment 108333 [details]
gtk-demo print output without patch

This is what I got from gtk-demo's print demo using gtk-2-12 branch without Behdad's patch.
Comment 15 Cody Russell 2008-03-31 13:22:40 UTC
Created attachment 108334 [details]
gtk-demo print output WITH patch

This is what I got from gtk-demo's print demo using gtk-2-12 branch WITH Behdad's patch.  It seems to be empty.

I'm using Cairo 1.5.14 for this.. gtk-2-12 branch (if you think it's important, I can build trunk to test).
Comment 16 Cody Russell 2008-03-31 20:46:21 UTC
Created attachment 108366 [details] [review]
Fixed patch

This appears to fix the issues with the previous patch.  Can I commit this one?
Comment 17 Cody Russell 2008-03-31 21:09:49 UTC
Created attachment 108369 [details] [review]
Updated comment

Dom asked me to change this comment as well, so here's a revised patch.
Comment 18 Cody Russell 2008-03-31 21:46:44 UTC
Created attachment 108373 [details] [review]
Removed some debugging output
Comment 19 Cody Russell 2008-04-01 16:29:04 UTC
I think this is ready to commit.  Tor said it was okay with him.  Can Behdad or Alex or someone approve it first?

Should I only commit this to trunk?  I'm assuming because of the change in Cairo version that it can't be committed to stable branches right?
Comment 20 Cody Russell 2008-04-01 20:46:46 UTC
2008-04-01  Cody Russell  <bratsche@gnome.org>

        * configure.in: Bump required Cairo to 1.5.2.

        * gtk/gtkprintoperation-win32.c: Add support for using the new
        cairo_win32_printing_surface for printing. (#488833)