[Monodevelop-patches-list] r2284 - trunk/MonoDevelop/Unused/Gdl

John Luke <jluke@cfl.rr.com> jluke at mono-cvs.ximian.com
Tue Mar 1 21:20:07 EST 2005


Author: jluke
Date: 2005-03-01 21:20:07 -0500 (Tue, 01 Mar 2005)
New Revision: 2284

Modified:
   trunk/MonoDevelop/Unused/Gdl/DockItemGrip.cs
Log:
workaround crash on utf8 chars


Modified: trunk/MonoDevelop/Unused/Gdl/DockItemGrip.cs
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/DockItemGrip.cs	2005-03-02 00:24:55 UTC (rev 2283)
+++ trunk/MonoDevelop/Unused/Gdl/DockItemGrip.cs	2005-03-02 02:20:07 UTC (rev 2284)
@@ -348,15 +348,20 @@
 		
 		private void EllipsizeLayout (int width)
 		{
-			if (width <= 0) {
+			// no room to draw anything
+			if (width < 1) {
 				layout.SetText ("");
 				return;
 			}
 			
-			int w, h, ell_w, ell_h, x, empty;
-			layout.GetPixelSize (out w, out h);
-			if (w <= width) return;
+			// plenty of room
+			int lw, lh;
+			layout.GetPixelSize (out lw, out lh);
+			if (width > lw)
+				return;
 			
+			// not enough room for ...
+			int ell_w, ell_h;
 			Pango.Layout ell = layout.Copy ();
 			ell.SetText ("...");
 			ell.GetPixelSize (out ell_w, out ell_h);
@@ -365,11 +370,16 @@
 				return;
 			}
 			
+			// subtract ellipses width
 			width -= ell_w;
+
+			int index, trailing;
 			Pango.LayoutLine line = layout.GetLine (0);
-			string text = layout.Text;
-			if (line.XToIndex (width * 1024, out x, out empty)) {
-				layout.SetText (text.Substring (0, x) + "...");
+			if (line.XToIndex (width * 1024, out index, out trailing)) {
+				// Console.WriteLine ("length: {0} index: {1} trailing: {2}", layout.Text.Length, index, trailing);
+				// FIXME: breaks on accented chars
+				if (index < layout.Text.Length)
+					layout.SetText (layout.Text.Substring (0, index) + "...");
 			}
 		}
 		




More information about the Monodevelop-patches-list mailing list