GNOME Bugzilla – Bug 140203
Win32 GDI printer support
Last modified: 2006-03-28 04:24:41 UTC
Attached is a hack to enable printing through the Windows gdi. I don't think it should be applied as is because it abuses the gdk_pixmap_foreign_new function and isn't that clean -- you can probably crash it by trying to render a pixmp. Rather, I want some feedback on whether this could go in. I realize there is talk of using cairo for printing, but I'm interested in something that works now. With this patch, the scintilla widget can print using it methods that were designed to work natively on win32. The patch works by modifying gdk_pixmap_foreign_new to accept a device context handle and using that handle in subsequent drawing calls. A gdk_pango_context_get_for_drawable function is also added that will return a pango context appropriate for printing; which works by using new pango functions defined the pango patch attached in http://bugzilla.gnome.org/show_bug.cgi?id=140199 Code that wants to use this printing support is responsible for setting up the hdc (usually via the PrintDlg win32 api call) and starting / ending each page via win32 api calls. If there is interest, the direction I'd probably take this is to create a new drawable subclass for the printer support and add functions to it to support starting and ending pages, starting and ending jobs, and expicitly closing the printer DC.
Created attachment 26702 [details] [review] Initial hack for printing
I don't think this should be added like this. We do want cross-platform printing support in GTK+ eventually, but it will be based on Cairo (http://www.cairographics.org) not the current GDK API.
The advantage of exposing printing through the GDK api is that code that is already writteen to use it can be modified to support printing. As I said before the scintilla widget currently works with this patch and I could envision modifying GtkTextView to work in much the same way. I know that the gdk api has its limitations, but it's good enough for a lot of purposes. I guess I'm making the case for implementing an imperfect solution now rather than waiting for better tools to be available later.
I don't want to add code and API (and the code would be a lot bigger and more complicated for X11) that is going to be abandoned in a 1 year timeframe.
Okay, I'll attempt to do this as outside gdk by creating a drawable subclass in my code and passing it in. It would be nice, though, to be able to use the gdk api even when cairo is available (perhaps via calldowns to the cairo layer) so that widgets like scintilla that don't require advanced rendering don't need to target yet another drawing api. I'd like to leave this bug open for patches to gdk that may be required so that an external drawable can work.
John, now that GTK+ and Cairo integration largely works, and GTK+ printing has been merged onto the gtk-print branch, do you think that this bug should be open? Thanks.