Unicode (specifically Apple Emoji) in Processing

edited October 2015 in How To...

Hey all,

What support is available for integrating Emoji into Processing, specifically with draw methods?

Answers

  • Answer ✓

    If they are regular images, just use loadImage(), then image().

    If they are defined in a font, use createFont() with the name of the font (works only if the font is installed in the computer running the sketch, or if the TTF file is in the data folder of the sketch), then use text() after setting up the font.

  • edited November 2013

    Hey PhiLho,

    I had implemented your suggestion before, but without any luck (Emoji is Unicode, so I figured id try two approaches; referencing it from source path / adding to data folder). No luck, just a blank output.

    PFont myFont;
    
    void setup() {
      size(200, 200);
      //background(255);
      // Uncomment the following two lines to see the available fonts 
      //String[] fontList = PFont.list();
      //println(fontList);
     // fill(0);
      myFont = createFont("Apple Color Emoji.ttf", 24);
      textFont(myFont);
      textAlign(CENTER, CENTER);
      text("
    
  • Ah, I missed the Unicode part from your subject (I search info in the body of messages, in general...).

    Do you have a file named "Apple Color Emoji.ttf" in the data folder of your sketch?

    If that's the name displayed in the PFont.list(), it probably doesn't have a .ttf extension, so you should try and remove this part from your code.

  • oops, the "text" portion i posted but was cut off was an inserted character emoji.

  • edited November 2013

    Hey PhiLho,

    a few things:

    Do you have a file named "Apple Color Emoji.ttf" in the data folder of your sketch?

    I have. I had also printed out the String of fonts available. the Emoji font is listed as "AppleColorEmoji" which I had adjusted (Also deleted the .ttf file from the data folder since the font appeared in the string list)

    I also referenced this chart to convert to unicode characters:

    apps.timwhitlock.info/emoji/tables/unicode

    I also ensured that the size font was what was available to the emoji font list.

    Here is my revision, but without anything displayed in the window:

    PFont myFont;
    
    void setup() {
      size(200, 200);
    
      //background(255);
      // Uncomment the following two lines to see the available fonts 
      String[] fontList = PFont.list();
     println(fontList);
     // fill(0);
      myFont = createFont("AppleColorEmoji", 24);
      textFont(myFont);
      textAlign(CENTER, CENTER);
      text("",width/2, height/2); // I pasted the character between string quotes
      // text("U+1F30D",width/2, height/2);
    
    }
    
  • Also to verify, the web/wingding emoji's work, but Apples Color Emoji still giving me grief.

  • edited November 2013 Answer ✓

    When you see U+1F601, try something like:

    text("\u1F601", width/2, height/2);
    

    Ah, but actually, only four hexa digits are allowed after \u!

    See http://docs.oracle.com/javase/tutorial/i18n/text/unicode.html

    Perhaps you can try:

    text(Character.toChars(0x1F601), width/2, height/2);
    

    [EDIT] Tested with a char (Chinese) I have on my system, you need to convert to string:

    text(new String(Character.toChars(0x201D2)), width/2, height/2);
    
Sign In or Register to comment.