From db6b98e4f74433cdc7ac20c9ea41dc4e13ed51cb Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 15 Jul 2015 21:56:34 +0000 Subject: Mac OS: The 'variation selectors' of Unicode change the glyph associated to the preceding unicode character. This defeats the procedure FLTK uses to compute text widths (precomputing the width of each used character) because the width of character n is not unique and potentially depends on character n+1. Therefore, we now remove variation selectors from the input string before drawing it. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10791 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/fl_font_mac.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index 1b2eba1ae..597b16087 100644 --- a/src/fl_font_mac.cxx +++ b/src/fl_font_mac.cxx @@ -492,12 +492,18 @@ static CGColorRef flcolortocgcolor(Fl_Color i) #endif static void fl_mac_draw(const char *str, int n, float x, float y, Fl_Graphics_Driver *driver) { + // the range [0xFE00-0xFE0F] corresponds to Unicode's 'variation selectors' + static CFCharacterSetRef set = CFCharacterSetCreateWithCharactersInRange(NULL, CFRangeMake(0xFE00, 16)); + CFRange res; // convert to UTF-16 first UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n); #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if (fl_mac_os_version >= Fl_X::CoreText_threshold) { - CFStringRef str16 = CFStringCreateWithCharactersNoCopy(NULL, uniStr, n, kCFAllocatorNull); + CFMutableStringRef str16 = CFStringCreateMutableWithExternalCharactersNoCopy(NULL, uniStr, n, n, kCFAllocatorNull); if (str16 == NULL) return; // shd not happen + while (CFStringFindCharacterFromSet(str16, set, CFRangeMake(0, CFStringGetLength(str16)), 0, &res)) { + CFStringReplace(str16, res, CFSTR("")); // remove all variation selectors from the input string + } CGColorRef color = flcolortocgcolor(driver->color()); CFDictionarySetValue (attributes, kCTFontAttributeName, driver->font_descriptor()->fontref); CFDictionarySetValue (attributes, kCTForegroundColorAttributeName, color); -- cgit v1.2.3