[Gnucash-changes] r13504 - gnucash/trunk - Add printing support to graphs (depends on #332884). Remove paper from PrintSession.

Andreas Köhler andi5 at cvs.gnucash.org
Mon Mar 6 16:52:34 EST 2006


Author: andi5
Date: 2006-03-06 16:52:33 -0500 (Mon, 06 Mar 2006)
New Revision: 13504
Trac: http://svn.gnucash.org/trac/changeset/13504

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
   gnucash/trunk/src/gnome-utils/gnc-html.c
   gnucash/trunk/src/gnome-utils/gnc-html.h
   gnucash/trunk/src/gnome-utils/print-session.c
   gnucash/trunk/src/gnome-utils/print-session.h
Log:
Add printing support to graphs (depends on #332884). Remove paper from PrintSession.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/ChangeLog	2006-03-06 21:52:33 UTC (rev 13504)
@@ -1,3 +1,16 @@
+2006-03-06  Andreas Köhler  <andi5.py at gmx.net>
+
+	* src/gnome-utils/gnc-html-graph-gog.c: Save the go graph in the
+	  GtkHTMLEmbedded object. Add printing support for the graphs
+	  (depends on #332884). A bit of formatting.
+
+	* src/gnome-utils/gnc-html.[ch]: Correct prototype of
+	  GncHTMLObjectCB to return gboolean.
+
+	* src/gnome-utils/print-session.[ch]: Create a new job with a
+	  default config for the print dialog. Remove GnomePrintPaper
+	  *paper from the PrintSession.
+
 2006-03-06  Christian Stimming  <stimming at tuhh.de>
 
 	* src/import-export/ofx/gnc-ofx-import.c: Fix OFX import problem

Modified: gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c	2006-03-06 21:52:33 UTC (rev 13504)
@@ -36,6 +36,7 @@
 #include <goffice/graph/gog-graph.h>
 #include <goffice/graph/gog-object.h>
 #include <goffice/graph/gog-renderer-pixbuf.h>
+#include <goffice/graph/gog-renderer-gnome-print.h>
 #include <goffice/graph/gog-style.h>
 #include <goffice/graph/gog-styled-object.h>
 #include <goffice/graph/gog-plot.h>
@@ -52,10 +53,9 @@
 /**
  * TODO:
  * - scatter-plot marker selection
- * - series-color, all plots (or drop feature)
+ * - series-color, piecharts (hard, not really supported by GOG)
+ *   and scatters (or drop feature)
  * - title-string freeing (fixmes)
- * - string rotation on y-axis-label and x-axis-element lables.
- *   (not supported by GOG?)
  * - general graph cleanup
  **/
 
@@ -65,6 +65,8 @@
 static int handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
 static int handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d);
 
+static void draw_print_cb(GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer graph);
+
 static gboolean create_basic_plot_elements(const char *plot_type, GogObject **out_graph, GogObject **out_chart, GogPlot **out_plot);
 
 static double * read_doubles(const char * string, int nvalues);
@@ -155,18 +157,18 @@
 }
 
 static void
-addPixbufGraphWidget( GtkHTMLEmbedded *eb, GogObject *graph )
+add_pixbuf_graph_widget( GtkHTMLEmbedded *eb, GogObject *graph )
 {
   GtkWidget *widget;
-  GogRenderer *pixbufRend;
+  GogRendererPixbuf *pixbuf_renderer;
   GdkPixbuf *buf;
-  gboolean updateStatus;
+  gboolean update_status;
 
   // Note that this shouldn't be necessary as per discussion with Jody...
   // ... but it is because we don't embed in a control which passes the
   // update requests back to the graph widget, a-la the foo-canvas that
   // gnumeric uses.  We probably _should_ do something like that, though.
-  gog_object_update( GOG_OBJECT(graph) );
+  gog_object_update (GOG_OBJECT (graph));
 
 #if 0
   // example SVG use.  Also, nice for debugging.
@@ -180,18 +182,23 @@
   }
 #endif // 0
 
-  pixbufRend = g_object_new( GOG_RENDERER_PIXBUF_TYPE,
-                             "model", graph,
-                             NULL );
-  updateStatus = gog_renderer_pixbuf_update( GOG_RENDERER_PIXBUF(pixbufRend), eb->width, eb->height, 1. );
-  buf = gog_renderer_pixbuf_get(GOG_RENDERER_PIXBUF(pixbufRend));
-  widget = gtk_image_new_from_pixbuf( buf );
-  gtk_widget_set_size_request( widget, eb->width, eb->height );
-  gtk_widget_show_all( widget );
-  gtk_container_add( GTK_CONTAINER(eb), widget );
+  pixbuf_renderer = GOG_RENDERER_PIXBUF (g_object_new (GOG_RENDERER_PIXBUF_TYPE,
+						       "model", graph,
+						       NULL));
+  update_status = gog_renderer_pixbuf_update (pixbuf_renderer,
+					      eb->width, eb->height, 1.0);
+  buf = gog_renderer_pixbuf_get (pixbuf_renderer);
+  widget = gtk_image_new_from_pixbuf (buf);
+  gtk_widget_set_size_request (widget, eb->width, eb->height);
+  gtk_widget_show_all (widget);
+  gtk_container_add (GTK_CONTAINER (eb), widget);
 
   // blindly copied from gnc-html-guppi.c..
-  gtk_widget_set_size_request(GTK_WIDGET(eb), eb->width, eb->height);
+  gtk_widget_set_size_request (GTK_WIDGET (eb), eb->width, eb->height);
+
+  g_object_set_data_full (G_OBJECT (eb), "graph", graph, g_object_unref);
+  g_signal_connect (G_OBJECT (eb), "draw_print",
+		    G_CALLBACK (draw_print_cb), NULL);
 }
 
 static gboolean
@@ -297,7 +304,7 @@
  * slice_urls_[123]: ?
  * legend_urls_[123]: ?
  */
-static int
+static gboolean
 handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d)
 {
   GogObject *graph, *chart;
@@ -348,7 +355,7 @@
   // fixme: colors
   set_chart_titles_from_hash(chart, eb);
 
-  addPixbufGraphWidget(eb, graph);
+  add_pixbuf_graph_widget (eb, graph);
 
   return TRUE;
 }
@@ -365,7 +372,7 @@
  * rotate_row_labels:boolean
  * stacked:boolean
  **/
-static int
+static gboolean
 handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d)
 {
   GogObject *graph, *chart;
@@ -482,13 +489,13 @@
   // we need to do this twice for the barchart... :p
   gog_object_update (GOG_OBJECT (graph));
 
-  addPixbufGraphWidget (eb, graph);
+  add_pixbuf_graph_widget (eb, graph);
 
   PINFO("barchart rendered.");
   return TRUE;
 }
 
-static int
+static gboolean
 handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d)
 {
   GogObject *graph, *chart;
@@ -534,7 +541,19 @@
   // And twice for the scatter, too... :p
   gog_object_update(GOG_OBJECT(graph));
 
-  addPixbufGraphWidget(eb, graph);
+  add_pixbuf_graph_widget (eb, graph);
 
   return TRUE;
 }
+
+static void
+draw_print_cb (GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer d)
+{
+  GogGraph *graph = GOG_GRAPH (g_object_get_data (G_OBJECT (eb), "graph"));
+
+  /* assuming pixel size is 0.5, cf. gtkhtml/src/htmlprinter.c */
+  gnome_print_scale (context, 0.5, 0.5);
+
+  gnome_print_translate (context, 0, eb->height);
+  gog_graph_print_to_gnome_print (graph, context, eb->width, eb->height);
+}

Modified: gnucash/trunk/src/gnome-utils/gnc-html.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html.c	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/src/gnome-utils/gnc-html.c	2006-03-06 21:52:33 UTC (rev 13504)
@@ -686,7 +686,7 @@
  * loaded.  
  ********************************************************************/
 
-static int
+static gboolean
 gnc_html_object_requested_cb(GtkHTML * html, GtkHTMLEmbedded * eb,
                              gpointer data)
 {

Modified: gnucash/trunk/src/gnome-utils/gnc-html.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html.h	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/src/gnome-utils/gnc-html.h	2006-03-06 21:52:33 UTC (rev 13504)
@@ -78,10 +78,9 @@
                                gpointer data);
 typedef int  (* GncHTMLButtonCB)(gnc_html * html, GdkEventButton * event,
                                  gpointer data);
-//#if 0
-typedef int  (* GncHTMLObjectCB)(gnc_html * html, GtkHTMLEmbedded * eb,
+
+typedef gboolean (* GncHTMLObjectCB)(gnc_html * html, GtkHTMLEmbedded * eb,
                                  gpointer data); 
-//#endif
 typedef int  (* GncHTMLActionCB)(gnc_html * html, const char * method,
                                  const char * action, GHashTable * form_data);
 typedef gboolean (* GncHTMLStreamCB)(const char *location, char **data, int *datalen);

Modified: gnucash/trunk/src/gnome-utils/print-session.c
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.c	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/src/gnome-utils/print-session.c	2006-03-06 21:52:33 UTC (rev 13504)
@@ -28,9 +28,7 @@
 #include <glib/gi18n.h>
 #include <libgnomeprint/gnome-font.h>
 #include <libgnomeprintui/gnome-print-job-preview.h>
-#include <stdio.h>
 
-#include "gnc-ui.h"
 #include "print-session.h"
 
 
@@ -43,19 +41,21 @@
   gint response;
 
   /* Ask the user what to do with the output */
+  config = gnome_print_config_default();
+  ps->job = gnome_print_job_new(config);
+  g_object_unref(config);
   dialog = gnome_print_dialog_new(ps->job, (guchar *) _("Print GnuCash Document"), 0);
   response = gtk_dialog_run(GTK_DIALOG(dialog));
   switch (response) {
     case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
     case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
-      config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog));
       gtk_widget_destroy(dialog);
-      ps->job = gnome_print_job_new(config);
       ps->context = gnome_print_job_get_context(ps->job);
       break;
     
     default:
       gtk_widget_destroy(dialog);
+      g_object_unref(ps->job);
       g_free(ps);
       return NULL;
   }

Modified: gnucash/trunk/src/gnome-utils/print-session.h
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.h	2006-03-06 21:35:48 UTC (rev 13503)
+++ gnucash/trunk/src/gnome-utils/print-session.h	2006-03-06 21:52:33 UTC (rev 13504)
@@ -33,7 +33,6 @@
 
 #include <libgnomeprint/gnome-print.h>
 #include <libgnomeprint/gnome-print-job.h>
-#include <libgnomeprint/gnome-print-paper.h>
 #include <libgnomeprintui/gnome-print-dialog.h>
 #include <libgnomeprintui/gnome-print-preview.h>
 
@@ -44,7 +43,6 @@
   GnomePrintJob      * job;
   GnomePrintContext  * context;		/* Convenience only. Owned by the job */
   GnomeFont          * default_font;
-  GnomePrintPaper    * paper;
 } PrintSession;
 
 



More information about the gnucash-changes mailing list