Author: ianmacarthur
Date: 2011-04-06 14:37:13 -0700 (Wed, 06 Apr 2011)
New Revision: 8568
Log:
Further work to fix win32 handling of surrogate pairs for "high" Unicode 
points... Now fixed handling of rotated text version of win32 draw method.
Fixes to the various ::width() methods for win32 and OSX still TBD.

Modified:
   branches/branch-1.3/src/fl_font_win32.cxx

Modified: branches/branch-1.3/src/fl_font_win32.cxx
===================================================================
--- branches/branch-1.3/src/fl_font_win32.cxx   2011-04-06 21:02:35 UTC (rev 
8567)
+++ branches/branch-1.3/src/fl_font_win32.cxx   2011-04-06 21:37:13 UTC (rev 
8568)
@@ -373,22 +373,17 @@
 
 void Fl_GDI_Graphics_Driver::draw(int angle, const char* str, int n, int x, 
int y) {
   fl_font(this, Fl_Graphics_Driver::font(), size(), angle);
-  int i = 0, i2=0;
-  char *end = (char *)&str[n];
+  int wc_count = 0; // count of UTF16 cells to render full string
   COLORREF oldColor = SetTextColor(fl_gc, fl_RGB());
   SelectObject(fl_gc, font_descriptor()->fid);
-  //unsigned short ucs[n]; //only GCC, but not MSVC
-  unsigned short* ucs = new unsigned short[n];
-  while (i < n) {
-    unsigned int u;
-    int l;
-    u = fl_utf8decode((const char*)(str + i), end, &l);
-    ucs[i2] = u;
-    if (l < 1) l = 1;
-    i += l;
-    ++i2;
+  unsigned short* ucs = new unsigned short[n]; // alloc an array for the UTF16 
string
+  wc_count = fl_utf8toUtf16(str, n, ucs, n);
+  if(wc_count > n) { // Array too small - this should never happen...
+    delete[] ucs; // free up the initial allocation
+    ucs = new unsigned short[wc_count + 4]; // make a "big enough" array
+    wc_count = fl_utf8toUtf16(str, n, ucs, wc_count); // respin the translation
   }
-  TextOutW(fl_gc, x, y, (WCHAR*)ucs, i2);
+  TextOutW(fl_gc, x, y, (WCHAR*)ucs, wc_count);
   delete[] ucs;
   SetTextColor(fl_gc, oldColor);
   fl_font(this, Fl_Graphics_Driver::font(), size(), 0);

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to