r17727 - gnucash/trunk/src/gnome-utils - Bug #350408: Fix incorrect fonts in reports and their print preview

Christian Stimming cstim at cvs.gnucash.org
Wed Nov 26 16:41:04 EST 2008


Author: cstim
Date: 2008-11-26 16:41:04 -0500 (Wed, 26 Nov 2008)
New Revision: 17727
Trac: http://svn.gnucash.org/trac/changeset/17727

Modified:
   gnucash/trunk/src/gnome-utils/gnc-html.c
   gnucash/trunk/src/gnome-utils/print-session.c
   gnucash/trunk/src/gnome-utils/print-session.h
Log:
Bug #350408: Fix incorrect fonts in reports and their print preview

Patch originally provided by Paul Andreassen, in bugzilla by Paul Gear.

Modified: gnucash/trunk/src/gnome-utils/gnc-html.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html.c	2008-11-26 21:23:30 UTC (rev 17726)
+++ gnucash/trunk/src/gnome-utils/gnc-html.c	2008-11-26 21:41:04 UTC (rev 17727)
@@ -1216,6 +1216,15 @@
   return TRUE;
 }
 
+static GtkHTML *
+gnc_html_get_top_html (GtkHTML *html)
+{
+  while (html->iframe_parent)
+    html = GTK_HTML (html->iframe_parent);
+
+  return html;
+}
+
 #ifdef GTKHTML_USES_GTKPRINT
 static void
 draw_page_cb(GtkPrintOperation *operation, GtkPrintContext *context,
@@ -1254,6 +1263,8 @@
 gnc_html_print(gnc_html * html)
 {
   PrintSession *ps;
+  GtkWidget *top_level;
+  PangoFontDescription *fontdesc;
 
   ps = gnc_print_session_create(FALSE);
   if (ps == NULL) {
@@ -1261,7 +1272,21 @@
     return;
   }
 
+  top_level = GTK_WIDGET (gnc_html_get_top_html (GTK_HTML(html->html)));
+
+  if (ps->pango_font_string != NULL) {
+    fontdesc = pango_font_description_from_string(ps->pango_font_string);
+    gtk_widget_modify_font(top_level, fontdesc);
+    pango_font_description_free(fontdesc);
+  }
+
+  gtk_html_print_set_master(GTK_HTML(html->html), ps->job);
   gtk_html_print(GTK_HTML(html->html), ps->context);
+
+  if (ps->pango_font_string != NULL) {
+    gtk_widget_modify_font(top_level, NULL);
+  }
+
   gnc_print_session_done(ps);
 }
 #endif /* GTKHTML_USES_GTKPRINT */

Modified: gnucash/trunk/src/gnome-utils/print-session.c
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.c	2008-11-26 21:23:30 UTC (rev 17726)
+++ gnucash/trunk/src/gnome-utils/print-session.c	2008-11-26 21:41:04 UTC (rev 17727)
@@ -34,6 +34,7 @@
 #endif
 
 #include "print-session.h"
+#include "gnc-gconf-utils.h" /* for gnc_gconf_set_string() */
 
 #undef G_LOG_DOMAIN
 #define G_LOG_DOMAIN "gnc.printing"
@@ -53,7 +54,36 @@
 G_LOCK_DEFINE_STATIC(page_setup);
 #endif
 
+static void gnc_print_session_fontsel_cb(GtkButton *widget, gpointer user_data)
+{
+  PrintSession *ps = (PrintSession *)user_data;
+  GtkWidget *dialog;
+  gint response;
 
+  dialog = gtk_font_selection_dialog_new("GnuCash Print Font");
+  if (ps->pango_font_string == NULL) {
+    GtkStyle *style = gtk_style_new();
+    ps->pango_font_string = pango_font_description_to_string(style->font_desc);
+    g_object_unref(style);
+  }
+  if (ps->pango_font_string != NULL)
+      gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)dialog, ps->pango_font_string);
+
+  response = gtk_dialog_run(GTK_DIALOG(dialog));
+  gtk_widget_destroy(dialog);
+
+  switch (response) {
+    case GTK_RESPONSE_OK:
+      g_free(ps->pango_font_string);
+      ps->pango_font_string = gtk_font_selection_dialog_get_font_name((GtkFontSelectionDialog *)dialog);
+      gnc_gconf_set_string(NULL, "pango_font_string", ps->pango_font_string, NULL);
+      break;
+
+    default:
+      break;
+  }
+}
+
 #ifdef HAVE_GTK_2_10
 void
 gnc_print_operation_save_print_settings(GtkPrintOperation *op)
@@ -132,30 +162,40 @@
   PrintSession * ps = g_new0(PrintSession, 1);
   GnomePrintConfig *config;
   GtkWidget *dialog;
+  GtkWidget *button;
   gint response;
 
+  ps->default_font = NULL;
+  ps->pango_font_string = gnc_gconf_get_string (NULL, "pango_font_string", NULL);
+
   /* 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);
+
+  button = gtk_button_new_from_stock(GTK_STOCK_SELECT_FONT);
+  g_signal_connect(button, "clicked", G_CALLBACK(gnc_print_session_fontsel_cb), ps);
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), button);
+  gtk_button_box_set_child_secondary((GtkButtonBox *)GTK_DIALOG(dialog)->action_area, button, TRUE);
+  gtk_widget_show(button); /* shouldn't be needed but is */
+
   response = gtk_dialog_run(GTK_DIALOG(dialog));
+  gtk_widget_destroy(dialog);
+
   switch (response) {
     case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
     case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
-      gtk_widget_destroy(dialog);
-      ps->context = gnome_print_job_get_context(ps->job);
       break;
-    
+
     default:
-      gtk_widget_destroy(dialog);
-      g_object_unref(ps->job);
-      g_free(ps);
+      gnc_print_session_destroy(ps);
       return NULL;
   }
 
   ps->hand_built_pages = hand_built_pages;
   ps->print_type = response;
+  ps->context = gnome_print_job_get_context(ps->job);
 
   ps->default_font = gnome_font_find_closest((guchar *)"Sans Regular", 12);
 
@@ -171,7 +211,9 @@
 gnc_print_session_destroy(PrintSession * ps)
 {
   g_object_unref(ps->job);
-  g_object_unref(ps->default_font);
+  if (ps->default_font != NULL)
+    g_object_unref(ps->default_font);
+  g_free(ps->pango_font_string);
 
   g_free(ps);
 }
@@ -200,5 +242,6 @@
     default:
       break;
   }
+  gnc_print_session_destroy(ps);
 }
 #endif  /* !GTKHTML_USES_GTKPRINT */

Modified: gnucash/trunk/src/gnome-utils/print-session.h
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.h	2008-11-26 21:23:30 UTC (rev 17726)
+++ gnucash/trunk/src/gnome-utils/print-session.h	2008-11-26 21:41:04 UTC (rev 17727)
@@ -80,6 +80,7 @@
   GnomePrintJob      * job;
   GnomePrintContext  * context;		/* Convenience only. Owned by the job */
   GnomeFont          * default_font;
+  guchar             * pango_font_string;
 } PrintSession;
 
 



More information about the gnucash-changes mailing list