summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2015-07-15 21:56:34 +0000
committerManolo Gouy <Manolo>2015-07-15 21:56:34 +0000
commitdb6b98e4f74433cdc7ac20c9ea41dc4e13ed51cb (patch)
tree36ed478e86080efec4c22b4e032de2598c91cbbd /src
parent7c0c17a45256953fd487865a6c5cd91e5b5f94d0 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/fl_font_mac.cxx8
1 files changed, 7 insertions, 1 deletions
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);