[gnumeric] Fixed more RTL text alignment issues.



commit d75c3792d44e2a9d330bcd798ef1aa592636e502
Author: Jean Brefort <jean brefort normalesup org>
Date:   Tue Jul 13 17:46:33 2010 +0200

    Fixed more RTL text alignment issues.

 ChangeLog            |   11 ++++++-
 src/cell-draw.c      |   13 +++++++-
 src/cellspan.c       |    4 ++
 src/item-edit.c      |    2 +-
 src/item-grid.c      |    8 +++-
 src/rendered-value.c |   86 +++++++++++++++++++++++++++++---------------------
 6 files changed, 83 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e993e37..44f00f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-07-13  Jean Brefort  <jean brefort normalesup org>
+
+	* src/cell-draw.c (cell_calc_layout): fixed alignment in cells with rtl
+	text and rtl sheets. [see #623241]
+	* src/cellspan.c (cell_calc_span): ditto.
+	* src/item-edit.c (get_top_left): ditto.
+	* src/item-grid.c (item_grid_draw_region): ditto.
+	* src/rendered-value.c (gnm_rendered_value_new): ditto.
+
 2010-07-12  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* component/Gnumeric-embed.xml.in: add submenu to Insert menu
@@ -15,7 +24,7 @@
 
 	* src/item-edit.c (item_edit_draw), (item_edit_button_pressed),
 	(item_edit_motion), (item_edit_update_bounds): fix ItemEdit
-	alignment for RTL text. [see #623241] 
+	alignment for RTL text. [see #623241]
 
 2010-07-10  Jean Brefort  <jean brefort normalesup org>
 
diff --git a/src/cell-draw.c b/src/cell-draw.c
index 9f1fb6e..3c80dc8 100644
--- a/src/cell-draw.c
+++ b/src/cell-draw.c
@@ -133,7 +133,8 @@ cell_calc_layout (GnmCell const *cell, GnmRenderedValue *rv, int y_direction,
 		case HALIGN_CENTER_ACROSS_SELECTION:
 			hoffset += ((width - indent) - rv->layout_natural_width) / 2;
 			break;
-		case HALIGN_FILL:
+		case HALIGN_FILL: {
+			PangoDirection dir = PANGO_DIRECTION_LTR;
 			if (!rv->hfilled &&
 			    rv->layout_natural_width > 0 &&
 			    width - indent >= 2 * rv->layout_natural_width) {
@@ -148,6 +149,7 @@ cell_calc_layout (GnmCell const *cell, GnmRenderedValue *rv, int y_direction,
 				int i;
 				PangoAttrList *attr = pango_layout_get_attributes (layout);
 
+				dir = pango_find_base_dir (copy1, -1);
 				for (i = 0; i < copies; i++) {
 					if (i)
 						g_string_append_unichar (multi, UNICODE_ZERO_WIDTH_SPACE_C);
@@ -164,9 +166,18 @@ cell_calc_layout (GnmCell const *cell, GnmRenderedValue *rv, int y_direction,
 						pango_attr_list_splice (attr, attr_c, len, len1);
 					pango_attr_list_unref (attr_c);
 				}
+			} else
+				dir = pango_find_base_dir (pango_layout_get_text (layout), -1);
+			/* right align if text is RTL */
+			if (dir == PANGO_DIRECTION_RTL) {
+				PangoRectangle r;
+				pango_layout_get_extents (layout, NULL, &r);
+				hoffset += (width - indent) - r.width;
 			}
+			
 			rv->hfilled = TRUE;
 			break;
+		}
 
 #ifndef DEBUG_SWITCH_ENUM
 		default:
diff --git a/src/cellspan.c b/src/cellspan.c
index f2e126b..611af76 100644
--- a/src/cellspan.c
+++ b/src/cellspan.c
@@ -234,6 +234,10 @@ cell_calc_span (GnmCell const *cell, int *col1, int *col2)
 	row   = cell->pos.row;
 	indented_w = cell_width_pixel = gnm_cell_rendered_width (cell);
 	if (h_align == HALIGN_LEFT || h_align == HALIGN_RIGHT) {
+		GnmRenderedValue *rv = gnm_cell_get_rendered_value (cell);
+		PangoDirection dir = pango_find_base_dir (pango_layout_get_text (rv->layout), -1);
+		if (gnm_style_get_align_h (style) == HALIGN_GENERAL && dir == PANGO_DIRECTION_RTL)
+			h_align = HALIGN_RIGHT;
 		indented_w += gnm_cell_rendered_offset (cell);
 		if (sheet->text_is_rtl)
 			h_align = (h_align == HALIGN_LEFT) ? HALIGN_RIGHT : HALIGN_LEFT;
diff --git a/src/item-edit.c b/src/item-edit.c
index b005957..3210907 100644
--- a/src/item-edit.c
+++ b/src/item-edit.c
@@ -76,7 +76,7 @@ get_top_left (ItemEdit const *ie, int *top, int *left, PangoDirection dir)
 	GocItem *item = GOC_ITEM (ie);
 	GocCanvas *canvas = item->canvas;
 	double l = ((goc_canvas_get_direction (canvas) == GOC_DIRECTION_LTR && dir == PANGO_DIRECTION_RTL)
-	            || (goc_canvas_get_direction (canvas) == GOC_DIRECTION_RTL && dir == PANGO_DIRECTION_LTR))?
+	            || (goc_canvas_get_direction (canvas) == GOC_DIRECTION_RTL && dir != PANGO_DIRECTION_RTL))?
 			item->x1 - 1: item->x0;
 
 	goc_canvas_c2w (canvas, l, item->y0, left, top);
diff --git a/src/item-grid.c b/src/item-grid.c
index 70aff6e..a45066e 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -668,10 +668,14 @@ plain_draw : /* a quick hack to deal with 142267 */
 				/* x, y are relative to this cell origin, but the cell
 				 * might be using columns to the left (if it is set to right
 				 * justify or center justify) compute the pixel difference */
-				if (start_span_col != cell->pos.col)
+				if (dir > 0 && start_span_col != cell->pos.col)
 					center_offset += scg_colrow_distance_get (
 						pane->simple.scg, TRUE,
 						start_span_col, cell->pos.col);
+				else if (dir < 0 && end_span_col != cell->pos.col)
+					center_offset += scg_colrow_distance_get (
+						pane->simple.scg, TRUE,
+						cell->pos.col, end_span_col);
 
 				if (start_span_col != col) {
 					offset = scg_colrow_distance_get (
@@ -738,7 +742,7 @@ plain_draw : /* a quick hack to deal with 142267 */
 			ig_cairo_draw_bound (cr, x, start_y, x, y);
 		} else if (canvas->direction == GOC_DIRECTION_LTR && start_x < 1)
 			ig_cairo_draw_bound (cr, 1, start_y, 1, y);
-	    }
+	}
 
 	g_slist_free (merged_used);	   /* merges with bottom in view */
 	g_slist_free (merged_active_seen); /* merges with bottom the view */
diff --git a/src/rendered-value.c b/src/rendered-value.c
index 1a89a28..aad915b 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -193,6 +193,8 @@ gnm_rendered_value_new (GnmCell const *cell,
 	Sheet const     *sheet;
 	gboolean         displayed_formula;
 	GnmStyle const *mstyle;
+	PangoDirection dir;
+	char const *text;
 
 	g_return_val_if_fail (cell != NULL, NULL);
 
@@ -296,44 +298,10 @@ gnm_rendered_value_new (GnmCell const *cell,
 	res->effective_valign = gnm_style_get_align_v (mstyle);
 	res->effective_halign = gnm_style_default_halign (mstyle, cell);
 	res->indent_left = res->indent_right = 0;
-	switch (res->effective_halign) {
-	case HALIGN_LEFT:
-		res->indent_left = calc_indent (context, mstyle);
-		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
-		break;
-
-	case HALIGN_JUSTIFY:
-		/*
-		 * The code here should work, but pango doesn't:
-		 * http://bugzilla.gnome.org/show_bug.cgi?id=64538
-		 */
-		pango_layout_set_justify (layout, TRUE);
-		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
-		break;
-
-	case HALIGN_FILL:
-		/*
-		 * A bit weird, but seems to match XL.  The effect is to
-		 * render newlines as visible characters.
-		 */
+	
+	if (res->effective_halign == HALIGN_FILL) {
 		pango_layout_set_single_paragraph_mode (layout, TRUE);
-		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
 		res->variable_width = TRUE;
-		break;
-
-	case HALIGN_RIGHT:
-		res->indent_right = calc_indent (context, mstyle);
-		pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
-		break;
-
-	case HALIGN_DISTRIBUTED:
-	case HALIGN_CENTER:
-	case HALIGN_CENTER_ACROSS_SELECTION:
-		pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
-		break;
-
-	default:
-		g_warning ("Line justification style not supported.");
 	}
 
 	/* ---------------------------------------- */
@@ -422,6 +390,52 @@ gnm_rendered_value_new (GnmCell const *cell,
 
 	/* ---------------------------------------- */
 
+	text = pango_layout_get_text (layout);
+	dir = (text && *text)? pango_find_base_dir (text, -1): PANGO_DIRECTION_LTR;
+	if (gnm_style_get_align_h (mstyle) == HALIGN_GENERAL && dir == PANGO_DIRECTION_RTL) {
+		switch (res->effective_halign) {
+		case HALIGN_LEFT:
+			res->effective_halign = HALIGN_RIGHT;
+			break;
+		case HALIGN_RIGHT:
+			res->effective_halign = HALIGN_LEFT;
+			break;
+		}
+	}
+	switch (res->effective_halign) {
+	case HALIGN_LEFT:
+		res->indent_left = calc_indent (context, mstyle);
+		pango_layout_set_alignment (layout, (dir == PANGO_DIRECTION_RTL)? PANGO_ALIGN_RIGHT: PANGO_ALIGN_LEFT);
+		break;
+
+	case HALIGN_JUSTIFY:
+		/*
+		 * The code here should work, but pango doesn't:
+		 * http://bugzilla.gnome.org/show_bug.cgi?id=64538
+		 */
+		pango_layout_set_justify (layout, TRUE);
+		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+		break;
+
+	case HALIGN_FILL:
+		break;
+
+	case HALIGN_RIGHT:
+		res->indent_right = calc_indent (context, mstyle);
+		pango_layout_set_alignment (layout, (dir == PANGO_DIRECTION_RTL)? PANGO_ALIGN_LEFT: PANGO_ALIGN_RIGHT);
+		break;
+
+	case HALIGN_DISTRIBUTED:
+	case HALIGN_CENTER:
+	case HALIGN_CENTER_ACROSS_SELECTION:
+		pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+		break;
+
+	default:
+		g_warning ("Line justification style not supported.");
+	}
+			 /* ---------------------------------------- */
+
 	/*
 	 * We store the foreground color separately because
 	 * 1. It is [used to be?] slow to store it as an attribute, see



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]