r15753 - gnucash/trunk/src - Add preferences support for printing the date format immediately below

David Hampton hampton at cvs.gnucash.org
Sat Mar 24 14:17:42 EDT 2007


Author: hampton
Date: 2007-03-24 14:17:38 -0400 (Sat, 24 Mar 2007)
New Revision: 15753
Trac: http://svn.gnucash.org/trac/changeset/15753

Modified:
   gnucash/trunk/src/gnome-utils/glade/preferences.glade
   gnucash/trunk/src/gnome/dialog-print-check.c
Log:
Add preferences support for printing the date format immediately below
the date (GtkPrint only), and for setting the font used by the check
printing code (GnomePrint and GtkPrint).  The fonts actually used by
GnomePrint seem very limited compared to those used by GtkPrint, but
the font size specification always seems to be honored.


Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2007-03-24 18:14:08 UTC (rev 15752)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2007-03-24 18:17:38 UTC (rev 15753)
@@ -67,7 +67,8 @@
 #define KEY_CUSTOM_TRANSLATION "custom_translation"
 #define KEY_CUSTOM_ROTATION    "custom_rotation"
 #define KEY_CUSTOM_UNITS       "custom_units"
-#define KEY_SHOW_DATE_FMT      "show_date_format"
+#define KEY_PRINT_DATE_FMT     "print_date_format"
+#define KEY_DEFAULT_FONT       "default_font"
 
 
 #define DEFAULT_FONT            "sans 12"
@@ -248,7 +249,7 @@
 
   GtkWidget * date_format;
 
-  gchar *format_string;
+  gchar *default_font;
 
   check_format_t *selected_format;
 };
@@ -929,7 +930,6 @@
               && (error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND)))
             g_warning("Check file %s, group %s, key %s, error: %s",
                       file, KF_GROUP_TOP, KF_KEY_FONT, error->message);
-        format->font = g_strdup(DEFAULT_FONT);
         g_clear_error(&error);
     }
 
@@ -1135,6 +1135,7 @@
   GtkWindow *window;
   GtkListStore *store;
   GtkTreeIter iter;
+  gchar *font;
 
   pcd = g_new0(PrintCheckDialog, 1);
   pcd->plugin_page = plugin_page;
@@ -1181,6 +1182,10 @@
   pcd->date_format = gnc_date_format_new_without_label();
   gtk_table_attach_defaults(GTK_TABLE(table), pcd->date_format, 1, 3, 2, 7);
 
+  /* Default font (set in preferences) */
+  font = gnc_gconf_get_string(GCONF_SECTION, KEY_DEFAULT_FONT, NULL);
+  pcd->default_font = font ? font : g_strdup(DEFAULT_FONT);
+
   /* Update the combo boxes bases on the available check formats */
   store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
   read_formats(pcd, store);
@@ -1211,7 +1216,7 @@
 /** Draw a grid pattern on the page to be printed.  This grid is helpful when
  *  figuring out the offsets for where to print various items on the page. */
 static void
-draw_grid(GncPrintContext * context, gint width, gint height)
+draw_grid(GncPrintContext * context, gint width, gint height, const gchar *font)
 {
     const double dash_pattern[2] = { 1.0, 5.0 };
 #if USE_GTKPRINT
@@ -1225,7 +1230,7 @@
 #if USE_GTKPRINT
     /* Initialize for printing text */
     layout = gtk_print_context_create_pango_layout(context);
-    desc = pango_font_description_from_string("sans 12");
+    desc = pango_font_description_from_string(font);
     pango_layout_set_font_description(layout, desc);
     pango_font_description_free(desc);
     pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
@@ -1508,7 +1513,7 @@
     GString *cdn_fmt;
 
     thislocale = setlocale(LC_ALL, NULL);
-    if (!gnc_gconf_get_bool(GCONF_SECTION, KEY_SHOW_DATE_FMT, NULL))
+    if (!gnc_gconf_get_bool(GCONF_SECTION, KEY_PRINT_DATE_FMT, NULL))
         return;
 
     date_desc = pango_font_description_copy_static(default_desc);
@@ -1589,7 +1594,10 @@
     g_return_if_fail(trans);
     amount = gnc_numeric_abs(xaccSplitGetAmount(pcd->split));
 
-    default_desc = pango_font_description_from_string(format->font);
+    if (format->font)
+        default_desc = pango_font_description_from_string(format->font);
+    else
+        default_desc = pango_font_description_from_string(pcd->default_font);
 
     /* Now put the actual data onto the page. */
     for (elem = format->items; elem; elem = g_slist_next(elem)) {
@@ -1712,7 +1720,8 @@
     if (format->show_grid) {
         draw_grid(context,
                   gtk_print_context_get_width(context),
-                  gtk_print_context_get_height(context));
+                  gtk_print_context_get_height(context),
+                  pcd->default_font);
     }
 
     /* Translate all subsequent check items if requested. */
@@ -1761,7 +1770,7 @@
 
     /* The grid is useful when determining check layouts */
     if (format->show_grid) {
-        draw_grid(ps->context, width, height);
+        draw_grid(ps->context, width, height, pcd->default_font);
     }
 
     /* Translate all subsequent check items if requested. */
@@ -1815,7 +1824,7 @@
     /* This was valid when the check printing dialog was instantiated. */
     g_return_if_fail(trans);
 
-    desc = pango_font_description_from_string("sans 12");
+    desc = pango_font_description_from_string(pcd->default_font);
 
     multip = pcd_get_custom_multip(pcd);
     degrees = gtk_spin_button_get_value(pcd->check_rotation);
@@ -1945,9 +1954,14 @@
 gnc_ui_print_check_dialog_ok_cb(PrintCheckDialog * pcd)
 {
   PrintSession *ps;
+  GnomeFont *oldfont;
   check_format_t *format;
 
   ps = gnc_print_session_create(TRUE);
+  oldfont = ps->default_font;
+  ps->default_font = gnome_font_find_closest_from_full_name(pcd->default_font);
+  gnome_print_setfont(ps->context, ps->default_font);
+  g_object_unref(oldfont);
 
   format = pcd->selected_format;
   if (format) {
@@ -2068,5 +2082,6 @@
 
   gtk_widget_destroy(pcd->dialog);
   g_object_unref(pcd->xml);
+  g_free(pcd->default_font);
   g_free(pcd);
 }

Modified: gnucash/trunk/src/gnome-utils/glade/preferences.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/glade/preferences.glade	2007-03-24 18:14:08 UTC (rev 15752)
+++ gnucash/trunk/src/gnome-utils/glade/preferences.glade	2007-03-24 18:17:38 UTC (rev 15753)
@@ -2237,6 +2237,172 @@
 	  </child>
 
 	  <child>
+	    <widget class="GtkTable" id="table11">
+	      <property name="visible">True</property>
+	      <property name="n_rows">10</property>
+	      <property name="n_columns">4</property>
+	      <property name="homogeneous">False</property>
+	      <property name="row_spacing">0</property>
+	      <property name="column_spacing">12</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label115">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;b&gt;Checks&lt;/b&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xpad">0</property>
+		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
+		</widget>
+		<packing>
+		  <property name="left_attach">0</property>
+		  <property name="right_attach">4</property>
+		  <property name="top_attach">0</property>
+		  <property name="bottom_attach">1</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options"></property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkFontButton" id="gconf/dialogs/print_checks/default_font">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="show_style">True</property>
+		  <property name="show_size">True</property>
+		  <property name="use_font">False</property>
+		  <property name="use_size">False</property>
+		  <property name="focus_on_click">True</property>
+		</widget>
+		<packing>
+		  <property name="left_attach">1</property>
+		  <property name="right_attach">4</property>
+		  <property name="top_attach">2</property>
+		  <property name="bottom_attach">3</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options"></property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkAlignment" id="alignment6">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkLabel" id="label116">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Default _Font:</property>
+		      <property name="use_underline">True</property>
+		      <property name="use_markup">True</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0.5</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		      <property name="mnemonic_widget">gconf/dialogs/print_checks/default_font</property>
+		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		      <property name="width_chars">-1</property>
+		      <property name="single_line_mode">False</property>
+		      <property name="angle">0</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="left_attach">0</property>
+		  <property name="right_attach">1</property>
+		  <property name="top_attach">2</property>
+		  <property name="bottom_attach">3</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options">fill</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkAlignment" id="alignment7">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkCheckButton" id="gconf/dialogs/print_checks/print_date_format">
+		      <property name="visible">True</property>
+		      <property name="tooltip" translatable="yes">Below the actual date, print the format of that date in 8 point type.</property>
+		      <property name="can_focus">True</property>
+		      <property name="label" translatable="yes">Print _Date Format</property>
+		      <property name="use_underline">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		      <property name="active">False</property>
+		      <property name="inconsistent">False</property>
+		      <property name="draw_indicator">True</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="left_attach">0</property>
+		  <property name="right_attach">4</property>
+		  <property name="top_attach">1</property>
+		  <property name="bottom_attach">2</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options">fill</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="tab_expand">False</property>
+	      <property name="tab_fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="label114">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Printing</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="type">tab</property>
+	    </packing>
+	  </child>
+
+	  <child>
 	    <widget class="GtkTable" id="table3">
 	      <property name="border_width">6</property>
 	      <property name="visible">True</property>



More information about the gnucash-changes mailing list