[Gnucash-changes] Patch by Didier Vidal: Implement real right justify in the register.

Christian Stimming cstim at cvs.gnucash.org
Mon Oct 10 15:45:56 EDT 2005


Log Message:
-----------
Patch by Didier Vidal: Implement real right justify in the register.

2005-10-10  Christian Stimming  <stimming at tuhh.de>

	* src/register/register-gnome/gnucash-grid.c: Patch by Didier
	Vidal: Implement real right justify in the register.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/register/register-gnome:
        gnucash-grid.c

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.322
retrieving revision 1.1487.2.323
diff -LChangeLog -LChangeLog -u -r1.1487.2.322 -r1.1487.2.323
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,8 @@
+2005-10-10  Christian Stimming  <stimming at tuhh.de>
+
+	* src/register/register-gnome/gnucash-grid.c: Patch by Didier
+	Vidal: Implement real right justify in the register.
+
 2005-10-09  Christian Stimming  <stimming at tuhh.de>
 
 	* src/import-export/hbci/hbci-interaction.c: Further gnome2
Index: gnucash-grid.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/register/register-gnome/gnucash-grid.c,v
retrieving revision 1.2.6.8
retrieving revision 1.2.6.9
diff -Lsrc/register/register-gnome/gnucash-grid.c -Lsrc/register/register-gnome/gnucash-grid.c -u -r1.2.6.8 -r1.2.6.9
--- src/register/register-gnome/gnucash-grid.c
+++ src/register/register-gnome/gnucash-grid.c
@@ -364,12 +364,14 @@
 	PangoLayout *layout;
 	PangoContext *context;
 	PangoFontDescription *font;
+	PangoRectangle ink_rect;
         GdkColor *bg_color;
         GdkColor *fg_color;
 /*        gint x_offset, y_offset;*/
         GdkRectangle rect;
         gboolean hatching;
         guint32 argb, color_type;
+        int x_offset;
 
         gdk_gc_set_background (grid->gc, &gn_white);
 
@@ -454,7 +456,8 @@
         text = gnc_table_get_entry (table, virt_loc);
 
 	layout = gtk_widget_create_pango_layout (GTK_WIDGET (grid->sheet), text);
-	pango_layout_set_width (layout, (width - 2 * CELL_HPADDING) * PANGO_SCALE);
+	// We don't need word wrap or line wrap
+	pango_layout_set_width (layout, -1);
         context = pango_layout_get_context (layout);
 	font = pango_font_description_copy (pango_context_get_font_description (context));
 
@@ -485,32 +488,43 @@
                     (((font->ascent + font->descent) / 2) - font->descent));
         y_offset++;*/
 
+	pango_layout_get_pixel_extents(layout,
+				       &ink_rect,
+				       NULL);
+
+        rect.x      = x + CELL_HPADDING;
+        rect.y      = y + CELL_VPADDING;
+        rect.width  = MAX (0, width - (2 * CELL_HPADDING));
+        rect.height = height - 2;
+
+        gdk_gc_set_clip_rectangle (grid->gc, &rect);
+
+
         switch (gnc_table_get_align (table, virt_loc))
         {
                 default:
                 case CELL_ALIGN_LEFT:
-			pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+			x_offset = 0;
                         break;
 
                 case CELL_ALIGN_RIGHT:
-			pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
+			x_offset = width - 2 * CELL_HPADDING - ink_rect.width;
                         break;
 
                 case CELL_ALIGN_CENTER:
-			pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+			if (ink_rect.width > width - 2 * CELL_HPADDING)
+				x_offset = 0;
+			else
+				x_offset = (width - 2 * CELL_HPADDING - 
+					    ink_rect.width) / 2;
                         break;
-                }
+	}
 
-        rect.x      = x + CELL_HPADDING;
-        rect.y      = y + CELL_VPADDING;
-        rect.width  = MAX (0, width - (2 * CELL_HPADDING));
-        rect.height = height - 2;
 
-        gdk_gc_set_clip_rectangle (grid->gc, &rect);
 
         gdk_draw_layout (drawable,
                          grid->gc,
-                         x + CELL_HPADDING,
+                         x + CELL_HPADDING + x_offset,
                          y + 1,
                          layout);
 


More information about the gnucash-changes mailing list