From 2a0b2429e242b91de4c2ae4f721b35e0826552c0 Mon Sep 17 00:00:00 2001 From: Eric Branlund Date: Sat, 21 Nov 2020 17:01:19 -0800 Subject: [PATCH] In drawWChar(), allow for the unlikely possibility that the character to be rendered requires two UniChars (as a surrogate pair). Previously had assumed that only one UniChar was needed and cast the whcar_t to a UniChar. --- src/main-cocoa.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main-cocoa.m b/src/main-cocoa.m index 7afde2281..d8ede500c 100644 --- a/src/main-cocoa.m +++ b/src/main-cocoa.m @@ -2445,13 +2445,21 @@ static int compare_advances(const void *ap, const void *bp) { CGFloat tileOffsetY = self.fontAscender; CGFloat tileOffsetX = 0.0; - UniChar unicharString[2] = {(UniChar)wchar, 0}; + UniChar unicharString[2]; + int nuni; + + if (CFStringGetSurrogatePairForLongCharacter(wchar, unicharString)) { + nuni = 2; + } else { + unicharString[0] = (UniChar) wchar; + nuni = 1; + } /* Get glyph and advance */ - CGGlyph thisGlyphArray[1] = { 0 }; - CGSize advances[1] = { { 0, 0 } }; + CGGlyph thisGlyphArray[2] = { 0, 0 }; + CGSize advances[2] = { { 0, 0 }, { 0, 0 } }; CTFontGetGlyphsForCharacters( - (CTFontRef)font, unicharString, thisGlyphArray, 1); + (CTFontRef)font, unicharString, thisGlyphArray, nuni); CGGlyph glyph = thisGlyphArray[0]; CTFontGetAdvancesForGlyphs( (CTFontRef)font, kCTFontHorizontalOrientation, thisGlyphArray, -- 2.11.0