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-current


Attached file "fl_font_xft.diff"...


Link: http://www.fltk.org/str.php?L2505
Version: 1.3-current
Index: src/fl_font_xft.cxx
===================================================================
--- src/fl_font_xft.cxx (revision 8126)
+++ src/fl_font_xft.cxx (working copy)
@@ -358,6 +358,33 @@
 //  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 unsigned *utf8reformat(const char *str, int& n)
+{
+  static unsigned *buffer;
+  static int lbuf = 0;
+  int newn;
+  if (n == 0) return NULL;
+  newn = fl_utf8towc(str, n, (wchar_t*)buffer, lbuf);
+  if (newn >= lbuf) {
+    lbuf = newn + 100;
+    if (buffer) free(buffer);
+    buffer = (unsigned*)malloc(lbuf * sizeof(unsigned));
+    }
+  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 unsigned *buffer = utf8reformat(str, n);
+  XftTextExtents32(fl_display, current_font, (XftChar32 *)buffer, n, extents);
+}
+
 int fl_height() {
   if (current_font) return current_font->ascent + current_font->descent;
   else return -1;
@@ -371,7 +398,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 +424,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 +612,9 @@
   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 unsigned *buffer = utf8reformat(str, n);
+  XftDrawString32(draw_, &color, current_font, x, y, (XftChar32 *)buffer, n);
 }
 
 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