Author: ianmacarthur
Date: 2011-04-17 06:18:55 -0700 (Sun, 17 Apr 2011)
New Revision: 8597
Log:
I've extended Manolo's excellent tweaks that handle surrogate pairs.
I found some kind of weird interaction with some symbol fonts that
covered the supplementary planes that meant we could not measure
the width correctly (although we did measure the text extents correctly.)

This mod mirrors what we do for non-surrogate-pair glyphs more
closely and appears to do the Righ Thing now, at least for the test fonts that 
I have, and which were exhibiting the aberrant behaviour before.

I don't think I have broken anything else in the meantime!

 


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

Modified: branches/branch-1.3/src/fl_font_mac.cxx
===================================================================
--- branches/branch-1.3/src/fl_font_mac.cxx     2011-04-17 11:19:41 UTC (rev 
8596)
+++ branches/branch-1.3/src/fl_font_mac.cxx     2011-04-17 13:18:55 UTC (rev 
8597)
@@ -274,15 +274,22 @@
 // returns width of a pair of UniChar's in the surrogate range
 static CGFloat surrogate_width(const UniChar *txt, Fl_Font_Descriptor 
*fl_fontsize)
 {
-  CFStringRef str = CFStringCreateWithCharactersNoCopy(NULL, txt, 2, 
kCFAllocatorNull);
-  CTFontRef font2 = CTFontCreateForString(fl_fontsize->fontref, str, 
CFRangeMake(0,2));
-  CFRelease(str);
+  CTFontRef font2 = fl_fontsize->fontref;
+  bool must_release = false;
   CGGlyph glyphs[2];
   bool b = CTFontGetGlyphsForCharacters(font2, txt, glyphs, 2);
   CGSize a;
+  if(!b) { // the current font doesn't contain this char
+    CFStringRef str = CFStringCreateWithCharactersNoCopy(NULL, txt, 2, 
kCFAllocatorNull);
+    // find a font that contains it
+    font2 = CTFontCreateForString(font2, str, CFRangeMake(0,2));
+    must_release = true;
+    CFRelease(str);
+    b = CTFontGetGlyphsForCharacters(font2, txt, glyphs, 2);
+  }
   if (b) CTFontGetAdvancesForGlyphs(font2, kCTFontHorizontalOrientation, 
glyphs, &a, 1);
   else a.width = fl_fontsize->q_width;
-  CFRelease(font2);
+  if(must_release) CFRelease(font2);
   return a.width;
 }
 #endif
@@ -296,10 +303,10 @@
   for (i = 0; i < n; i++) { // loop over txt
     uni = txt[i];
     if (uni >= 0xD800 && uni <= 0xDBFF) { // handles the surrogate range
-      retval += surrogate_width(txt + i, fl_fontsize);
+      retval += surrogate_width(&txt[i], fl_fontsize);
       i++; // because a pair of UniChar's represent a single character
       continue;
-      }
+    }
     const int block = 0x10000 / (sizeof(fl_fontsize->width)/sizeof(float*)); 
// block size
     // r: index of the character block containing uni
     unsigned int r = uni >> 7; // change 7 if sizeof(width) is changed
@@ -380,12 +387,13 @@
   int l = 1;
   if (wc <= 0xFFFF) {
     *utf16 = wc;
-    }
+  }
   else {
-    char buf[4];
-    l = fl_utf8encode(wc, buf);
-    l = (int)fl_utf8toUtf16(buf, l, utf16, 3);
-    }
+//    char buf[4];
+//    l = fl_utf8encode(wc, buf);
+//    l = (int)fl_utf8toUtf16(buf, l, utf16, 3);
+    l = (int)fl_ucs_to_Utf16(wc, utf16, 3);
+  }
   return fl_mac_width(utf16, l, font_descriptor());
 }
 

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

Reply via email to