r15733 - gnucash/trunk - Add support for printing reports with GtkPrint.
Andreas Köhler
andi5 at cvs.gnucash.org
Sat Mar 17 13:29:40 EDT 2007
Author: andi5
Date: 2007-03-17 13:29:35 -0400 (Sat, 17 Mar 2007)
New Revision: 15733
Trac: http://svn.gnucash.org/trac/changeset/15733
Modified:
gnucash/trunk/configure.in
gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
gnucash/trunk/src/gnome-utils/gnc-html.c
gnucash/trunk/src/gnome-utils/print-session.c
gnucash/trunk/src/gnome-utils/print-session.h
gnucash/trunk/src/gnome/dialog-print-check.c
Log:
Add support for printing reports with GtkPrint.
Also add gnc_{save,restore}_print_settings so that those are shared
between report and check prints.
Modified: gnucash/trunk/configure.in
===================================================================
--- gnucash/trunk/configure.in 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/configure.in 2007-03-17 17:29:35 UTC (rev 15733)
@@ -1127,6 +1127,7 @@
AC_MSG_NOTICE([Found libgtkhtml-3.14, but goffice lacks a cairo renderer])
else
gtkhtml=1
+ AC_DEFINE(GTKHTML_USES_GTKPRINT,1,[GtkHTML uses GtkPrint for printing operations])
fi
], [gtkhtml=0])
if test x$gtkhtml = x0
Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/src/gnome/dialog-print-check.c 2007-03-17 17:29:35 UTC (rev 15733)
@@ -94,7 +94,6 @@
#if USE_GTKPRINT
# define GncPrintContext GtkPrintContext
-static GtkPrintSettings *settings = NULL;
#else
# define GncPrintContext GnomePrintContext
#endif
@@ -1744,8 +1743,7 @@
print = gtk_print_operation_new();
- if (settings != NULL)
- gtk_print_operation_set_print_settings(print, settings);
+ gnc_restore_print_settings(print);
gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
gtk_print_operation_set_use_full_page(print, TRUE);
g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
@@ -1755,11 +1753,8 @@
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
pcd->caller_window, NULL);
- if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
- if (settings != NULL)
- g_object_unref(settings);
- settings = g_object_ref(gtk_print_operation_get_print_settings(print));
- }
+ if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
+ gnc_save_print_settings(print);
g_object_unref(print);
}
Modified: gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c 2007-03-17 17:29:35 UTC (rev 15733)
@@ -67,7 +67,11 @@
static int handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
static int handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
+#ifdef GTKHTML_USES_GTKPRINT
+static void draw_print_cb(GtkHTMLEmbedded *eb, cairo_t *cr, gpointer graph);
+#else
static void draw_print_cb(GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer graph);
+#endif
static gboolean create_basic_plot_elements(const char *plot_type, GogObject **out_graph, GogObject **out_chart, GogPlot **out_plot);
@@ -552,7 +556,24 @@
return TRUE;
}
+#ifdef GTKHTML_USES_GTKPRINT
static void
+draw_print_cb(GtkHTMLEmbedded *eb, cairo_t *cr, gpointer unused)
+{
+ GogGraph *graph = GOG_GRAPH(g_object_get_data(G_OBJECT(eb), "graph"));
+ GogRendererCairo *rend = g_object_new(GOG_RENDERER_CAIRO_TYPE, "model", graph,
+ "cairo", cr, "is-vector", TRUE, NULL);
+
+ /* assuming pixel size is 0.5, cf. gtkhtml/src/htmlprinter.c */
+ cairo_scale(cr, 0.5, 0.5);
+
+ cairo_translate(cr, 0, -eb->height);
+ gog_renderer_cairo_update(rend, eb->width, eb->height, 1.0);
+ g_object_unref(rend);
+}
+
+#else /* !GTKHTML_USES_GTKPRINT */
+static void
draw_print_cb(GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer unused)
{
GogGraph *graph = GOG_GRAPH (g_object_get_data (G_OBJECT (eb), "graph"));
@@ -563,3 +584,4 @@
gnome_print_translate (context, 0, eb->height);
gog_graph_print_to_gnome_print (graph, context, eb->width, eb->height);
}
+#endif /* GTKHTML_USES_GTKPRINT */
Modified: gnucash/trunk/src/gnome-utils/gnc-html.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html.c 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/src/gnome-utils/gnc-html.c 2007-03-17 17:29:35 UTC (rev 15733)
@@ -1210,7 +1210,39 @@
return TRUE;
}
+#if GTKHTML_USES_GTKPRINT
+
+static void
+draw_page_cb(GtkPrintOperation *operation, GtkPrintContext *context,
+ gint page_nr, gpointer user_data)
+{
+ gnc_html *html = user_data;
+
+ gtk_html_print_page((GtkHTML*) html->html, context);
+}
+
void
+gnc_html_print(gnc_html *html)
+{
+ GtkPrintOperation *print;
+ GtkPrintOperationResult res;
+
+ print = gtk_print_operation_new();
+ gnc_restore_print_settings(print);
+ gtk_print_operation_set_n_pages(print, 1);
+ g_signal_connect(print, "draw_page", G_CALLBACK(draw_page_cb), html);
+
+ res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ GTK_WINDOW(html->window), NULL);
+
+ if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
+ gnc_save_print_settings(print);
+
+ g_object_unref(print);
+}
+
+#else /* !GTKHTML_USES_GTKPRINT */
+void
gnc_html_print(gnc_html * html)
{
PrintSession *ps;
@@ -1224,6 +1256,7 @@
gtk_html_print(GTK_HTML(html->html), ps->context);
gnc_print_session_done(ps);
}
+#endif /* GTKHTML_USES_GTKPRINT */
gnc_html_history *
gnc_html_get_history(gnc_html * html)
Modified: gnucash/trunk/src/gnome-utils/print-session.c
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.c 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/src/gnome-utils/print-session.c 2007-03-17 17:29:35 UTC (rev 15733)
@@ -105,3 +105,35 @@
break;
}
}
+
+#ifdef HAVE_GTK_2_10
+
+static GtkPrintSettings *print_settings = NULL;
+G_LOCK_DEFINE_STATIC(print_settings);
+
+void
+gnc_save_print_settings(GtkPrintOperation *print)
+{
+ g_return_if_fail(print);
+
+ G_LOCK(print_settings);
+ if (print_settings)
+ g_object_unref(print_settings);
+
+ print_settings = g_object_ref(gtk_print_operation_get_print_settings(print));
+ G_UNLOCK(print_settings);
+}
+
+void
+gnc_restore_print_settings(GtkPrintOperation *print)
+{
+ g_return_if_fail(print);
+
+ G_LOCK(print_settings);
+ if (print_settings)
+ gtk_print_operation_set_print_settings(print, print_settings);
+
+ G_UNLOCK(print_settings);
+}
+
+#endif /* HAVE_GTK_2_10 */
Modified: gnucash/trunk/src/gnome-utils/print-session.h
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.h 2007-03-17 17:29:30 UTC (rev 15732)
+++ gnucash/trunk/src/gnome-utils/print-session.h 2007-03-17 17:29:35 UTC (rev 15733)
@@ -82,6 +82,23 @@
*/
void gnc_print_session_done(PrintSession * ps);
+
+#if HAVE_GTK_2_10
+/** Get the print settings of a given GtkPrintOperation and store them in a
+ * static variable. Previous values will be overwritten.
+ *
+ * @param print A pointer to a print operation.
+ */
+void gnc_save_print_settings(GtkPrintOperation *print);
+
+/** After a previous call to gnc_save_print_settings, set the print settings of a
+ * given GtkPrintOperation to the stored value. Otherwise, do nothing.
+ *
+ * @param print A pointer to a print operation.
+ */
+void gnc_restore_print_settings(GtkPrintOperation *print);
+#endif
+
/** @} */
/** @} */
More information about the gnucash-changes
mailing list