Using Emoji's on OSX

#1

Is it possible to make something like this work:

void setup() {
  size(200, 200);
  char[] chars = Character.toChars(128149);
  textFont(createFont("AppleColorEmoji", 32, true, chars));
  textAlign(CENTER, CENTER);
  text(""+chars[0], width/2, height/2);
}
0 Likes

#2

I recall a recent related discussion on getting OpenSansEmoji to work:

I can see that AppleColorEmoji is there, is full of unicode, and has different codepoint contents than the default font. I just don’t know which specific codepoints you are looking for, and if they are representable (esp. if they are color).

Here is a sketch that scans through character indexes – on the default font and a loaded font.

PFont defaultFont;
PFont emoji;
int index=0;
int index2=0;
char[] chars;

void setup() {
  size(680, 340);
  chars = Character.toChars(128149);
  emoji = createFont("AppleColorEmoji", 32, true, chars);
  textSize(32);
  textAlign(CENTER, CENTER);
  defaultFont = g.textFont;
  frameRate(2);
}

void draw() {
  background(0);
  translate(32,32);
  textFont(defaultFont);
  charGrid(index, 10, 10, 32);
  translate(320,0);
  textFont(emoji);
  charGrid(index, 10, 10, 32);
  index+=100;
}

void charGrid(int index, int w, int h, float step){
  for (int j=0; j<h; j++) {
    for (int i=0; i<w; i++) {
      text(char(index), i*step, j*step);
      index++;
    }
  }
}
0 Likes

#3

Yeah I need the colors as well, so it seems I should use something else then processing.

0 Likes

#4

So, according to this,


there are four different recent standards that allow color emoji in font files – I suspect that none existed when Processing font support was developed.

SVG-in-Opentype
COLR/CPAL
SBIX
CBDT/CBLC

If you could get the svg from opentype then you could get the color image – assuming the svg could be read by PShape. But you might still need to handle text size and kerning / leading.

Possible that emoji4j could help with that? Haven’t looked at it, but it seems like an external library that makes svg retrieval easy would be the first step. Or updating Processing core font components.

0 Likes

#5

The processing core font could use some love anyway. TextWidth is so slow. I made a test sometime ago where I replaced it with just a float array for a lookup based on the char number and my sketch was running 10% faster.

0 Likes

#6

Maybe pull request that!

0 Likes