DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2505
Version: 1.3.0


Manolo, unfortunately your patch doesn't work on Windows with Cygwin/X11
(configure --enable-x11).

fl_utf8towc() does /not/ convert to an array of unsigned, but wchar_t, and
this is only 2 bytes on Windows. Therefore we need the 16-bit variants of
the Xft-specific functions. I modified your patch (see attached file
fl_font_xft_as.diff), so that it takes care of this (I used wchar_t
instead of unsigned). Instead of the OP's sizeof() check I used
__CYGWIN__, because this is the only platform that (currently?) supports
X11 on Windows (and we can't use WIN32 here).

There's another case in utf8reformat() where your patch returns NULL, if
n==0. I don't think that we should return NULL here, because the returned
pointer would be used later (although this might never happen, but
anyway). My patch returns a pointer to an empty wchar_t string instead.

I tested my patch both on Windows (Cygwin with --enable-x11) and Linux,
and it worked for me. Please check if this is okay (at least it's better
than before).


Link: http://www.fltk.org/str.php?L2505
Version: 1.3.0
Index: src/fl_font_xft.cxx
===================================================================
--- src/fl_font_xft.cxx (revision 8203)
+++ src/fl_font_xft.cxx (working copy)
@@ -358,6 +358,38 @@
 //  XftFontClose(fl_display, font);
 }
 
+/* returns the string decoded into a series of Unicode characters.
+ n is set to the number of characters upon return.
+ Don't deallocate the returned memory.
+ */
+static const wchar_t *utf8reformat(const char *str, int& n)
+{
+  static const wchar_t empty[] = {0};
+  static wchar_t *buffer;
+  static int lbuf = 0;
+  int newn;
+  if (n == 0) return empty;
+  newn = fl_utf8towc(str, n, (wchar_t*)buffer, lbuf);
+  if (newn >= lbuf) {
+    lbuf = newn + 100;
+    if (buffer) free(buffer);
+    buffer = (wchar_t*)malloc(lbuf * sizeof(wchar_t));
+    }
+  n = fl_utf8towc(str, n, (wchar_t*)buffer, lbuf);
+  return buffer;
+}
+
+static void utf8extents(const char *str, int n, XGlyphInfo *extents)
+{
+  memset(extents, 0, sizeof(XGlyphInfo));
+  const wchar_t *buffer = utf8reformat(str, n);
+#ifdef __CYGWIN__
+    XftTextExtents16(fl_display, current_font, (XftChar16 *)buffer, n, 
extents);
+#else
+    XftTextExtents32(fl_display, current_font, (XftChar32 *)buffer, n, 
extents);
+#endif
+}
+
 int fl_height() {
   if (current_font) return current_font->ascent + current_font->descent;
   else return -1;
@@ -371,7 +403,7 @@
 double fl_width(const char *str, int n) {
   if (!current_font) return -1.0;
   XGlyphInfo i;
-  XftTextExtentsUtf8(fl_display, current_font, (XftChar8 *)str, n, &i);
+  utf8extents(str, n, &i);
   return i.xOff;
 }
 
@@ -397,7 +429,7 @@
     return;
   }
   XGlyphInfo gi;
-  XftTextExtentsUtf8(fl_display, current_font, (XftChar8 *)c, n, &gi);
+  utf8extents(c, n, &gi);
 
   w = gi.width;
   h = gi.height;
@@ -585,8 +617,13 @@
   color.color.green = ((int)g)*0x101;
   color.color.blue  = ((int)b)*0x101;
   color.color.alpha = 0xffff;
-
-  XftDrawStringUtf8(draw_, &color, current_font, x, y, (XftChar8 *)str, n);
+  
+  const wchar_t *buffer = utf8reformat(str, n);
+#ifdef __CYGWIN__
+  XftDrawString16(draw_, &color, current_font, x, y, (XftChar16 *)buffer, n);
+#else
+  XftDrawString32(draw_, &color, current_font, x, y, (XftChar32 *)buffer, n);
+#endif
 }
 
 void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, 
int y) {
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to