Re: [PATCH] Icon view RTL layout



On Sat, 2006-03-04 at 11:04 +0100, Christian Neumair wrote:
> > Can you give an example string in this "language" where this method
> > would not work?
> 
> When you consider multiple paragraphs, they can independently be either
> RTL or LTR, so a layout like
> 
> [      LTRLTRLTR ]
> [ RTL            ]
> 
> is possible, i.e. there is one base directions for each of the
> paragraphs. This could only be relevant if there are paragraph
> separation characters in the layout - I don't know the RTL semantics.

That shouldn't be possible. Its not a form of orientation we want. If
the base orientation is RTL we always want the text to be right-aligned
(right now this looks silly, but you have to think of it with the icon
being on the right side of the text). The same way we'd like RTL text to
be left-aligned with a LTR base orientation.

The reason pango is creating layouts like the one above is because its
trying to auto-guess the orientation. I just turned off this with
pango_layout_set_auto_dir(). Also, the whole (max-width - width) thing
is just because we're using the wrong "width" from the layout extents.

I commited the attached patch instead of yours.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a war-weary arachnophobic romance novelist who hangs with the wrong 
crowd. She's a vivacious renegade fairy princess on the trail of a serial 
killer. They fight crime! 
Index: libnautilus-private/nautilus-icon-canvas-item.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.c,v
retrieving revision 1.197
diff -u -p -r1.197 nautilus-icon-canvas-item.c
--- libnautilus-private/nautilus-icon-canvas-item.c	3 Mar 2006 13:34:54 -0000	1.197
+++ libnautilus-private/nautilus-icon-canvas-item.c	6 Mar 2006 10:16:05 -0000
@@ -925,6 +925,23 @@ draw_frame (NautilusIconCanvasItem *item
   #define PERFORMANCE_TEST_MEASURE_DISABLE
 */
 
+/* This gets the size of the layout from the position of the layout.
+ * This means that if the layout is right aligned we get the full width
+ * of the layout, not just the width of the text snippet on the right side
+ */
+static void
+layout_get_full_size (PangoLayout *layout,
+		      int         *width,
+		      int         *height)
+{
+	PangoRectangle logical_rect;
+	
+	pango_layout_get_extents (layout, NULL, &logical_rect);
+	*width = (logical_rect.x + logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE;
+	*height = (logical_rect.y + logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE;
+}
+
+
 static void
 draw_or_measure_label_text (NautilusIconCanvasItem *item,
 			    GdkDrawable *drawable,
@@ -1003,18 +1020,12 @@ draw_or_measure_label_text (NautilusIcon
 
 	if (have_editable) {
 		editable_layout = get_label_layout (&details->editable_text_layout, item, details->editable_text);
-		
-		pango_layout_get_pixel_size (editable_layout, 
-					     &editable_width,
-					     &editable_height);
+		layout_get_full_size (editable_layout, &editable_width, &editable_height);
 	}
 
 	if (have_additional) {
 		additional_layout = get_label_layout (&details->additional_text_layout, item, details->additional_text);
-
-		pango_layout_get_pixel_size (additional_layout, 
-					     &additional_width,
-					     &additional_height);
+		layout_get_full_size (additional_layout, &additional_width, &additional_height);
 	}
 
 	details->text_width = MAX (editable_width, additional_width);
@@ -1613,7 +1624,7 @@ create_label_layout (NautilusIconCanvasI
 	container = NAUTILUS_ICON_CONTAINER (canvas_item->canvas);
 	context = gtk_widget_get_pango_context (GTK_WIDGET (canvas_item->canvas));
 	layout = pango_layout_new (context);
-
+	
 	zeroified_text = NULL;
 
 	if (text != NULL) {
@@ -1637,8 +1648,14 @@ create_label_layout (NautilusIconCanvasI
 	pango_layout_set_text (layout, zeroified_text, -1);
 	pango_layout_set_width (layout, floor (nautilus_icon_canvas_item_get_max_text_width (item)) * PANGO_SCALE);
 			
+	pango_layout_set_auto_dir (layout, FALSE);
+	
 	if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+		if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_LTR) {
+			pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+		} else {
+			pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
+		}
 	} else {
 		pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
 	}


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