Index: src/cell-draw.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/cell-draw.c,v
retrieving revision 1.94
diff -u -r1.94 cell-draw.c
--- src/cell-draw.c	31 Mar 2004 01:32:50 -0000	1.94
+++ src/cell-draw.c	22 Sep 2004 09:16:13 -0000
@@ -49,10 +49,18 @@
  * @h_center : The number of pixels from x1 marking the logical center
  *             of the cell.  NOTE This can be asymetric.  Passing
  *             <= 0 will use width / 2
+ *
+ * @rv : the RenderedValue used to calculate positions
+ * @printing : is this call is for printing
+ *			for screen use y axis down and for printing up
+ *
  */
 
-static gboolean
-cell_calc_layout (GnmCell const *cell,
+/* this function will be used by print-call.c when 
+ * gnumeric require libgnomeprint 2.8*/
+
+gboolean
+cell_calc_layout (GnmCell const *cell, RenderedValue *rv, gboolean printing,
 		  int x1, int y1, int width, int height, int h_center,
 		  GdkRectangle  *rect, GdkColor **res_color, gint *res_x, gint *res_y,
 		  PangoLayout **res_layout)
@@ -60,11 +68,11 @@
 	ColRowInfo const * const ci = cell->col_info; /* DEPRECATED */
 	ColRowInfo const * const ri = cell->row_info; /* DEPRECATED */
 	int text_base;
-	RenderedValue *rv = cell->rendered_value;
-	PangoLayout *layout;
 	int indent;
 	int hoffset;
-
+	int y_direction; /* -1 up for printing, 1 down for screen */
+	PangoLayout *layout;
+	
 	if (rv == NULL) {
 		g_warning ("Serious cell error at '%s'.", cell_name (cell));
 		return FALSE;
@@ -73,23 +81,21 @@
 	layout = rv->layout;
 	indent = rv->indent_left + rv->indent_right;
 
-	/* Get the sizes exclusive of margins and grids */
+	/* get the y axis direction for printing/screen*/
+	y_direction = printing ? -1 : 1;
+	
 	/* FIXME : all callers will eventually pass in their cell size */
-	if (width < 0) /* DEPRECATED */
-		width  = ci->size_pixels - (ci->margin_b + ci->margin_a + 1);
-	if (height < 0) /* DEPRECATED */
-		height = ri->size_pixels - (ri->margin_b + ri->margin_a + 1);
 	if (width <= 0 || height <= 0)
 		return FALSE;
-
+				
 	hoffset = rv->indent_left;
 	
 	/* This rectangle has the whole area used by this cell
 	 * excluding the surrounding grid lines and margins */
 	rect->x = x1 + 1 + ci->margin_a;
-	rect->y = y1 + 1 + ri->margin_a;
+	rect->y = y1 + y_direction * ( 1 + ri->margin_a);
+	rect->height = height - y_direction * 1;
 	rect->width = width + 1;
-	rect->height = height + 1;
 
 	/* if a number overflows, do special drawing */
 	if (rv->layout_natural_width > width - indent &&
@@ -110,7 +116,7 @@
 		int wanted_width = MAX (0, (width - indent) * PANGO_SCALE);
 		if (wanted_width != pango_layout_get_width (layout)) {
 			pango_layout_set_width (layout, wanted_width);
-			pango_layout_get_pixel_size (layout,
+			pango_layout_get_size (layout,
 						     &rv->layout_natural_width,
 						     &rv->layout_natural_height);
 		}
@@ -172,11 +178,13 @@
 		break;
 
 	case VALIGN_BOTTOM:
-		text_base = rect->y + MAX (0, height - rv->layout_natural_height);
+		text_base = rect->y + 
+				y_direction * MAX (0, height - rv->layout_natural_height);
 		break;
 
 	case VALIGN_CENTER:
-		text_base = rect->y + MAX (0, (height - rv->layout_natural_height) / 2);
+		text_base = rect->y + 
+				y_direction * MAX (0, (height - rv->layout_natural_height) / 2);
 		break;
 
 	case VALIGN_JUSTIFY:
@@ -187,7 +195,7 @@
 				int spacing = PANGO_SCALE * (height - rv->layout_natural_height) /
 					(line_count - 1);
 				pango_layout_set_spacing (layout, spacing);
-				pango_layout_get_pixel_size (layout,
+				pango_layout_get_size (layout,
 							     &rv->layout_natural_width,
 							     &rv->layout_natural_height);
 			}
@@ -220,12 +228,20 @@
 	gint x;
 	gint y;
 	PangoLayout *layout;
-
+	ColRowInfo const * const ci = cell->col_info; /* DEPRECATED */
+	ColRowInfo const * const ri = cell->row_info; /* DEPRECATED */
+	
 #ifdef QUANTIFYING
 	quantify_start_recording_data ();
 #endif
-
-	if (cell_calc_layout (cell, x1, y1, width, height, h_center,
+	
+	/* Get the sizes exclusive of margins and grids in screen context units (pixels) */
+	if (width < 0) /* DEPRECATED */
+		width  = ci->size_pixels - (ci->margin_b + ci->margin_a + 1);
+	if (height < 0) /* DEPRECATED */
+		height = ri->size_pixels - (ri->margin_b + ri->margin_a + 1);
+		
+	if (cell_calc_layout (cell, cell->rendered_value, FALSE, x1, y1, width, height, h_center,
 			      &rect, &color, &x, &y, &layout)) {
 		gdk_gc_set_clip_rectangle (gc, &rect);
 		
Index: src/cell-draw.h
===================================================================
RCS file: /cvs/gnome/gnumeric/src/cell-draw.h,v
retrieving revision 1.14
diff -u -r1.14 cell-draw.h
--- src/cell-draw.h	11 Oct 2003 05:41:29 -0000	1.14
+++ src/cell-draw.h	22 Sep 2004 09:16:13 -0000
@@ -3,8 +3,14 @@
 
 #include "gnumeric.h"
 #include <gdk/gdk.h>
+#include <libgnomeprint/gnome-print-pango.h> /* FIXME: include just pango ? */
 
 void cell_draw (GnmCell const *cell, GdkGC *gc, GdkDrawable *drawable,
 		int x, int y, int height, int width, int h_center);
 
+gboolean cell_calc_layout (GnmCell const *cell, RenderedValue *rv, 
+		gboolean printing, int x1, int y1, int width, int height, int h_center,
+		GdkRectangle  *rect, GdkColor **res_color, gint *res_x, gint *res_y,
+		PangoLayout **res_layout);
+		  
 #endif /* GNUMERIC_CELL_DRAW_H */
Index: src/print-cell.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/print-cell.c,v
retrieving revision 1.118
diff -u -r1.118 print-cell.c
--- src/print-cell.c	23 Jun 2004 02:42:04 -0000	1.118
+++ src/print-cell.c	22 Sep 2004 09:16:15 -0000
@@ -25,6 +25,9 @@
 #include "sheet-merge.h"
 #include "rendered-value.h"
 #include "str.h"
+#ifndef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
+#include "cell-draw.h" /* for the gnome_print_pango_XXX layout calculations */
+#endif
 
 #include <string.h>
 #include <locale.h>
@@ -35,6 +38,15 @@
 #define MERGE_DEBUG(range, str)
 #endif
 
+#ifndef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
+/*
+ * This code will die when gnumeric require libgnomeprint 2.8
+ *
+ * This code duplicate the functionality of libgnomeprint's >= 2.8
+ * pango functions and will be replaced by call to the
+ * gnome_print_pango_XXX functions when gnumeric will require 
+ * libgnomeprint 2.8
+ */ 
 static inline void
 print_hline (GnomePrintContext *context,
 	     float x1, float x2, float y)
@@ -182,6 +194,11 @@
 }
 
 /*
+ * End of code that will die when we require libgnomeprint 2.8
+ */ 
+#endif
+
+/*
  * print_make_rectangle_path
  * @pc      print context
  * @left    left side x coordinate
@@ -220,6 +237,71 @@
 print_cell (GnmCell const *cell, GnmStyle const *mstyle, GnomePrintContext *context,
 	    double x1, double y1, double width, double height, double h_center)
 {
+#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
+	GdkRectangle  rect;
+	GdkColor *color; 
+	gint x;
+	gint y;
+	PangoLayout *res_layout;
+	PangoLayout *layout;
+	RenderedValue *rv;
+	RenderedValue *cell_rv = cell->rendered_value;
+	PangoLayout *cell_layout = cell_rv->layout;
+	ColRowInfo const * const ci = cell->col_info; /* DEPRECATED */
+	ColRowInfo const * const ri = cell->row_info; /* DEPRECATED */
+	
+#ifdef QUANTIFYING
+	quantify_start_recording_data ();
+#endif
+	
+	/* Create a print layout and copy attributes from the screen layout */
+	layout = gnome_print_pango_create_layout (context);
+	pango_layout_set_text (layout, 
+				pango_layout_get_text (cell_layout), -1);
+	pango_layout_set_attributes (layout, 
+				pango_layout_get_attributes(cell_layout));
+	
+	/* Create a rendered value for printing */
+	rv = rendered_value_new (cell, mstyle, TRUE,
+				pango_layout_get_context (layout));
+	
+	/* Get the sizes exclusive of margins and grids in priter context units (points) */
+	if (width < 0) /* DEPRECATED */
+		width  = ci->size_pts - (ci->margin_b + ci->margin_a + 1);
+	if (height < 0) /* DEPRECATED */
+		height = ri->size_pts - (ri->margin_b + ri->margin_a + 1);
+	
+	if (cell_calc_layout (cell, rv, TRUE, (int)x1, (int)y1, (int)width, (int)height, (int)h_center,
+				&rect, &color, &x, &y, &res_layout)) {
+		
+		/* Clip the printed rectangle */
+		gnome_print_gsave (context);
+		print_make_rectangle_path (context,
+				   rect.x - 1,
+				   rect.y - rect.height - 1,
+				   rect.x + rect.width + 1,
+				   rect.y + 1);
+		gnome_print_clip (context);
+		
+		/* Set the font colour */
+		gnome_print_setrgbcolor (context,
+				 color->red   / (double) 0xffff,
+				 color->green / (double) 0xffff,
+				 color->blue  / (double) 0xffff);
+						
+		gnome_print_moveto (context, x, y);
+		gnome_print_pango_layout (context, layout);
+	}
+
+#ifdef QUANTIFYING
+	quantify_stop_recording_data ();
+#endif
+
+	/* free the print layout and rendered_value */
+	g_object_unref (layout);
+	rendered_value_destroy (rv);					
+#else
+	/* This code will die when we require libgnomeprint 2.8  */
 	Sheet const * const sheet = cell->base.sheet;
 	GnmFont *style_font = mstyle_get_font (mstyle, sheet->context, 1.0);
 	GnomeFont *print_font = style_font->gnome_print_font;
@@ -492,7 +574,7 @@
 		g_list_free (lines);
 	}
 	style_font_unref (style_font);
-
+#endif
 	gnome_print_grestore (context);
 }
 
