Displaying Emoji with Core Text

510 views
Skip to first unread message

Hwee-Boon Yar

unread,
Jan 24, 2012, 6:52:40 AM1/24/12
to cocoa-unbound
Hi,

Does anyone know of a workaround to get Core Text to display Emoji on
iOS? As of iOS 5.0, it still replaces Emoji characters with glyph=7

I have a short snippet that I used to verify it, but not sure how I
can work around it.

CFArrayRef lines = CTFrameGetLines(_textFrame);
CTLineRef line = CFArrayGetValueAtIndex(lines, 0);
CFArrayRef glyphRuns = CTLineGetGlyphRuns(line);
CTRunRef run = CFArrayGetValueAtIndex(glyphRuns, 0); //loop
CGGlyph* buff = malloc(100*sizeof(CGGlyph)); //get size instead of 100
CTRunGetGlyphs(run, CFRangeMake(0, 0), buff);
if (buff[0] == 7) { // should loop buffer
//goes here if character is Emoji.
}


See: http://openradar.appspot.com/8234470


Thanks.

---
Hwee-Boon

Jesse Compo

unread,
Apr 15, 2012, 1:46:02 AM4/15/12
to cocoa-...@googlegroups.com
I'm facing the same issue, did you find a workaround?

If you are only displaying a single line of text, CTLineDraw will work:

   CTLineRef line = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)string); 

    CGContextSetTextPosition(context, x,  y);

    CTLineDraw(line, context);

Have you found a way to display emojis with the CTFrameSetter?


Jesse

Eric Vitiello

unread,
Apr 16, 2012, 7:38:04 PM4/16/12
to cocoa-...@googlegroups.com

This may be a silly question...

Are you sure you're using a typeface that includes the emoji characters?

--Eric

Jesse Compo

unread,
Apr 18, 2012, 12:25:27 PM4/18/12
to cocoa-...@googlegroups.com
I am using Helvetica, and I tried AppleColorEmoji with no luck.

Jesse Compo

unread,
Apr 18, 2012, 12:27:57 PM4/18/12
to cocoa-...@googlegroups.com

"\u2764\ud83d\udca1\ud83d\udc80\"

This is an example of the string I am using.  I am unfamiliar with string encoding, should this be decoded somehow?

Reply all
Reply to author
Forward
0 new messages