Am Dienstag, 17. Oktober 2006 13:51 schrieb Enrico Forestieri:

> The problem here is that a string iterator has type "pointer to char",
> which by default is signed on Cygwin. So, the ascent() functions was
> being passed an unresonably large (and wrong) value for nonascii chars.

Good detective work!

> The solution here is to convert to unsigned char before calling ascent()
> and descent().
> 
> With the attached patch I don't get crashes anymore. I will commit it
> shortly if nobody objects.

I don't think that this solution is the right one. The argument "s" of 
mathed_string_dim is in utf8 encoding (since all mathed stuff is read in 
uncahnged from the .lyx file). That means that we may not get the metrics 
by iterating through the bytes of s. We rather need to convert it first to 
ucs4, and then we can call ascent() for each character, see the attached 
patch.

That will probably slow down math quite a bit, but the long term solution 
is to convert mathed to docstring completely.


Georg
Index: src/mathed/MathSupport.C
===================================================================
--- src/mathed/MathSupport.C	(Revision 15338)
+++ src/mathed/MathSupport.C	(Arbeitskopie)
@@ -383,18 +383,14 @@ int mathed_char_width(LyXFont const & fo
 void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
 {
 	lyx::frontend::FontMetrics const & fm =	theFontMetrics(font);
-#if 1
+	// FIXME UNICODE
+	docstring const ds = lyx::from_utf8(s);
 	dim.asc = 0;
 	dim.des = 0;
-	for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
+	for (docstring::const_iterator it = s.begin(); it != s.end(); ++it) {
 		dim.asc = max(dim.asc, fm.ascent(*it));
 		dim.des = max(dim.des, fm.descent(*it));
 	}
-#else
-	dim.asc = fm.maxAscent();
-	dim.des = fm.maxDescent();
-#endif
-	docstring ds(s.begin(), s.end());
 	dim.wid = fm.width(ds);
 }
 

Reply via email to