diff options
| author | Ian MacArthur <imacarthur@gmail.com> | 2011-04-17 13:18:55 +0000 |
|---|---|---|
| committer | Ian MacArthur <imacarthur@gmail.com> | 2011-04-17 13:18:55 +0000 |
| commit | e67e6283179b05bc8a4feb5f3d4a544230bc5b57 (patch) | |
| tree | 704689ea47e7cce9bb143e8c181211de5891455e /src | |
| parent | f8d1e074edc644d960a78aaaefb9f7c0f856f67c (diff) | |
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!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8597 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/fl_font_mac.cxx | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index df23a495b..cc22747f2 100644 --- a/src/fl_font_mac.cxx +++ b/src/fl_font_mac.cxx @@ -274,15 +274,22 @@ int Fl_Quartz_Graphics_Driver::descent() { // 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 @@ if (fl_mac_os_version >= 100500) { 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 @@ double Fl_Quartz_Graphics_Driver::width(unsigned int wc) { 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()); } |
