No subject
Thu Feb 18 01:58:27 EST 2010
"The PDF in comment 2 is about 8 times smaller than it should be. One possible cause of this bug is if gtk_print_operation_set_unit (op, GTK_UNIT_POINTS) is not called. gtkprint defaults to GTK_UNIT_PIXEL - a useless unit to be using with printers.
On Linux GTK_UNIT_PIXEL units are 1 unit = 1/72 inch (the same as GTK_UNIT_POINTS as well as PostScript and PDF units). On Windows GTK_UNIT_PIXEL units are the GDI device units which for printers is the dpi resolution. So for a 600dpi printer 1 unit is 1/600".
If the application was developed on Linux and assumes the default gtkprint units are always 1/72" inch the output on Windows using a 600dpi printer will be 72/600 = 0.12 of the size (or approximately 1/8 of the size)."
Solution was to use webkit_web_frame_print_full() which allows us to provide our own GtkPrintOperation object with units set to GTK_UNIT_POINTS. Tested on both Linux and Windows.
Modified: gnucash/trunk/src/html/gnc-html-webkit.c
===================================================================
--- gnucash/trunk/src/html/gnc-html-webkit.c 2010-02-24 19:14:02 UTC (rev 18719)
+++ gnucash/trunk/src/html/gnc-html-webkit.c 2010-02-24 19:44:11 UTC (rev 18720)
@@ -1,5 +1,5 @@
/********************************************************************
- * gnc-html_webkit.c -- display HTML with some special gnucash tags.*
+ * gnc-html-webkit.c -- gnucash report renderer using webkit *
* *
* Copyright (C) 2000 Bill Gribble <grib at billgribble.com> *
* Copyright (C) 2001 Linas Vepstas <linas at linas.org> *
@@ -986,30 +986,45 @@
}
}
+#define PRINT_WITH_OP 1
+
static void
impl_webkit_print( GncHtml* self )
{
+ extern void webkit_web_frame_print( WebKitWebFrame* frame );
+ extern GtkPrintOperationResult webkit_web_frame_print_full( WebKitWebFrame* frame,
+ GtkPrintOperation* op, GtkPrintOperationAction action, GError** error );
+
GncHtmlWebkitPrivate* priv;
-// static void (*webkit_web_frame_print)( WebKitWebFrame* frame ) = NULL;
WebKitWebFrame* frame;
- extern void webkit_web_frame_print( WebKitWebFrame * frame );
-
- /* HACK ALERT
- *
- * The api to print isn't exported, but exists and works, so let's dig for it.
- */
-#if 0
- if ( webkit_web_frame_print == NULL )
- {
- void* handle = dlopen( "/usr/lib/libwebkit-1.0.so", RTLD_LAZY );
- webkit_web_frame_print = dlsym( handle, "webkit_web_frame_print" );
- dlclose( handle );
- }
+#if PRINT_WITH_OP
+ GtkPrintOperation* op = gtk_print_operation_new();
+ GError* error = NULL;
#endif
priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
frame = webkit_web_view_get_main_frame( priv->web_view );
+
+#if PRINT_WITH_OP
+ gtk_print_operation_set_unit( op, GTK_UNIT_POINTS );
+ webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error );
+ g_object_unref( op );
+
+ if( error != NULL ) {
+ GtkWidget* window = gtk_widget_get_toplevel( GTK_WIDGET(priv->web_view) );
+ GtkWidget* dialog = gtk_message_dialog_new( GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", error->message );
+ g_error_free( error );
+
+ g_signal_connect( dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
+ gtk_widget_show( dialog );
+ }
+#else
webkit_web_frame_print( frame );
+#endif
}
static void
More information about the gnucash-changes
mailing list