Re: [PATCH][RFC] Improve icon view line breaks



Am Montag, den 19.12.2005, 10:29 +0100 schrieb Alexander Larsson:
> On Sun, 2005-12-11 at 22:11 +0100, Christian Neumair wrote:
> > The attached patch is meant to improve icon view line breaks by looking
> > for '.', '_' and CamelCase characters, and inserting pango hints that it
> > may preferably break at a particular position (i.e. treat it as end of
> > word). It is meant to fix bug 300790 [1], while the more interesting
> > discussion was going on in bug 323711 [2] between Behdad and myself.
> > caveats:
> >  - Some developers might not like breaking after CamelCase. It looks
> > more aesthetically, but makes FooFooBar indistinguishable from FooFoo
> > Bar if we break between the two words. Comments appreciated
> >  - The code tries to be smart by only breaking after '.' and '_' if no
> > digit follows to not break version information. It seems to work quiet
> > well, but needs some testing
> >  - The layout is changed when editing a filename that had a manually
> > inserted line break. This won't be fixed until [2] is properly resolved
> > 
> > [1] http://bugzilla.gnome.org/show_bug.cgi?id=300790
> > [2] http://bugzilla.gnome.org/show_bug.cgi?id=323711
> 
> I like the idea a lot. 
> 
> I'm not sure handling CamelCase is right. It may be somewhat surprising
> to people. What do other people think about that?

No other comments were given, and I'd really like to get this into
Nautilus. I second your CamelCase concerns, so let's leave them out for
now.

> The layout change on rename is unfortunate, but I think this is still
> worth it, until we get better support in pango.
> 
> About the patch. Could you break out the conversion code to a separate
> function, and:
> +               zeroified_text = g_malloc ((1 + strlen (ZERO_WIDTH_SPACE)) * (strlen (text) + 1));
> looks pretty wasteful to me. Maybe use GString instead (which makes it
> easier to read too)?

Proposed patch attached, which also uses more sophisticated match
patterns. Now three or more subsequent digits are also treated as normal
text for wrapping, which fixed the wrapping of IPs and a test folder
that was named like "test 42.93749237" on my desktop.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-icon-canvas-item.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.c,v
retrieving revision 1.195
diff -u -p -r1.195 nautilus-icon-canvas-item.c
--- libnautilus-private/nautilus-icon-canvas-item.c	14 Nov 2005 15:49:58 -0000	1.195
+++ libnautilus-private/nautilus-icon-canvas-item.c	25 Feb 2006 21:42:46 -0000
@@ -1588,6 +1588,13 @@ nautilus_icon_canvas_item_draw (EelCanva
 	draw_label_text (icon_item, drawable, FALSE, icon_rect);
 }
 
+#define ZERO_WIDTH_SPACE "\xE2\x80\x8B"
+
+#define ZERO_OR_THREE_DIGITS(p) \
+	(!g_ascii_isdigit (*p) || \
+	 (g_ascii_isdigit (*(p+1)) && \
+	  g_ascii_isdigit (*(p+2))))
+
 static PangoLayout *
 create_label_layout (NautilusIconCanvasItem *item,
 		     const char *text)
@@ -1597,6 +1604,9 @@ create_label_layout (NautilusIconCanvasI
 	PangoFontDescription *desc;
 	NautilusIconContainer *container;
 	EelCanvasItem *canvas_item;
+	GString *str;
+	char *zeroified_text;
+	const char *p;
 
 	canvas_item = EEL_CANVAS_ITEM (item);
 
@@ -1604,7 +1614,27 @@ create_label_layout (NautilusIconCanvasI
 	context = gtk_widget_get_pango_context (GTK_WIDGET (canvas_item->canvas));
 	layout = pango_layout_new (context);
 
-	pango_layout_set_text (layout, text, -1);
+	zeroified_text = NULL;
+
+	if (text != NULL) {
+		str = g_string_new (NULL);
+
+		for (p = text; *p != '\0'; p++) {
+			str = g_string_append_c (str, *p);
+
+			if ((*p == '_' || *p == '.') && ZERO_OR_THREE_DIGITS (p+1)) {
+				/* Ensure that we allow to break after '_' or '.' characters,
+				 * if they are not likely to be part of a version information, to
+				 * not break wrapping of foobar-0.0.1.
+				 * Wrap before IPs and long numbers, though. */
+				str = g_string_append (str, ZERO_WIDTH_SPACE);
+			}
+		}
+
+		zeroified_text = g_string_free (str, FALSE);
+	}
+
+	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);
 			
 	if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
@@ -1627,6 +1657,7 @@ create_label_layout (NautilusIconCanvasI
 	}
 	pango_layout_set_font_description (layout, desc);
 	pango_font_description_free (desc);
+	g_free (zeroified_text);
 	
 	return layout;
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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