Coloured Emojis

edited January 2017 in Programming Questions

Hello I try to render coloured emojis using this line here:

String emoji = new String(Character.toChars(unhex("1F32F"))); text(emoji, width/2, height/2);

Code is fine, to show this I have this example using that line:

  • Arial has letter A, but neither of this emojis, and writes [] for these.
  • Universalia+ har no letter A-glyph, writes [NUL] for this, but has the Cookie. Burrito, is strangely empty.
  • AppleColorEmojis doesn't contain letter "A" and writes an [] for missing glyph, but has both the cookie and burrito glyph, but they doesn't show. This is my issue.

Only answer I possibly find is this: https://www.mail-archive.com/i18n-dev@openjdk.java.net/msg01334.html Which doesn't help.

This question has been asked before, here: http://forum.processing.org/two/discussion/896 without an useful answer.

Is it Java that is the problem?

Any help greatly appreciated! Hampus

Answers

  • did you try PhiLhos last answer

    https://forum.processing.org/two/discussion/896

    use a hex value

  • edited November 2015

    @Chrisir: unhex() converts a hex String to an int so he is basically using a hex value (with some unnecessary overhead of course).

    @hampus: The TTF file format specification does not define tables/data blocks for multicolored glyphs. The colored emoticons in Apple's Apple Color Emoji font are actually just a bunch of PNG files in a custom data block of the TTF. It's a proprietary file format extension that is not very well supported. If I remember correctly Java's standard Font libraries don't support this extension and I'm pretty sure Processing is relying on those to create the glyph images.

    So yeah, this is kind of a "Java problem", although you can't really blame them for not supporting such proprietary extensions.

  • edited January 2016

    I'm relatively new to processing (I've downloaded 3.0.1 on my Mac). I have been trying to use emojis in a sketch and I think the issue is a lack of support for unicode characters not on the Basic Multilingual Plane. From what I understand, Java uses UTF-16 for characters in strings. From the Java String documentation I found (http://docs.oracle.com/javase/7/docs/api/index.html?java/lang/String.html):

    "A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information). Index values refer to char code units, so a supplementary character uses two positions in a String."

    Everything in the BMP uses 1 position in a String. It seems to me that the problem is that supplementary characters (surrogate pairs) are not correctly identified. The "Cookie" emoji has the code point 1F36A, which is represented in UTF-16 Hex as D83C, DF6A (http://www.fileformat.info/info/unicode/char/1f36a/index.htm)

    Here is the sketch that I've written:

    PFont f;
    
    void setup() {
      // test codepoint for cookie
      println("Checking codepoint for \"cookie\" emoji:");
      if (Character.isValidCodePoint(0x1F36A))
        println("Cookie (", 0x1F36A, ") is a valid codepoint.");
      if (Character.isSupplementaryCodePoint(0x1F36A))
        println("Cookie (", 0x1F36A, ") is a valid supplementary codepoint.");
      if (Character.isSurrogatePair((char)0xD83C,(char)0xDF6A))
        println("Cookie (", 0xD83C, ", ", 0xDF6A, ") is a valid surrogate pair.");
      println(" ");
    
      // put it in a String
      println("Checking String containing \"cookie\" emoji codepoint:");
      String cookie = "\uD83C\uDF6A";
      println("Length of String \"cookie\":", cookie.length());
      println("Codepoints in \"cookie\":", cookie.codePointCount(0,2));
      println("Result of printing Java String containing codepoint: ",cookie);
      println(" ");
    
    
      size(400, 400);
      background(255);
      fill(0);
    
      // display it -- without setting font
      text(cookie, width/4, height/4);
      println("Without textFont set, empty box is displayed for codepoint");
      println(" ");
    
      f = loadFont("AppleColorEmoji-48.vlw");
      println("Checking with Pfont (AppleColorEmoji) loaded:");
      println("Cannot pass codepoint for \"cookie\" (in String) to Pfont.getGlyph");
      println("Glyph for character at position 0: ", f.getGlyph(cookie.charAt(0)));
      println("Glyph for character at position 1: ", f.getGlyph(cookie.charAt(1)));
      println(" ");
    
      textFont(f,48);
      text(cookie, width/2, height/2);
    
      println("With textFont set, warning messages for both surrogates (unpaired)");
      println("are generated from textCharImpl routine in source, it appears");
    }
    

    Have I missed something?

Sign In or Register to comment.