OpenSansEmoji.ttf not working in P3D?

So this has been driving me nuts all day. I was using OpenSansEmoji.ttf in a project and the emojis weren't showing up. Fast forward 6 hours later... I couldn't figure out why it was working in another test project until I saw that my main project needs the P3D in order to be able to use Syphon. My test project was not using the P3D renderer and it works there.

So now that I figured out why it wouldn't work, does anyone have any ideas on how to use this font AND Syphon? Or why this font won't render the emojis in P3D?

Answers

  • edited April 2018

    I don't have the "OpenSansEmoji.ttf" font on either my Mac or my Windows machines. I went looking for it and found something with the same name here (https://github.com/MorbZ/OpenSansEmoji/blob/master/OpenSansEmoji.ttf).

    The font itself appears to be small and only has the alphabet (upper and lower case) and the digits 0 to 9.

    Are you trying to access characters/glyphs in the font that it does not have?

    EDIT: My mistake I looked in the wrong section :\"> ... it does have a lot of characters.

  • They definitely do exist as they work in a 2D project.

  • Can you please provide an example sketch that shows the problem?

  • Sure.

    `String str ="::: astronaut

  • Ugh. Looks like I can't post the Unicode string here so... unfortunately I'd have to use a screenshot.

    Screenshot 2018-04-24 08.04.07 Screenshot 2018-04-24 07.57.48

    Screenshot 2018-04-24 08.05.06 Screenshot 2018-04-24 07.59.04

    Only difference: size(400, 400); vs size(400, 400, P3D);

  • Answer ✓

    If you really need renderer P3D (or P2D) for your sketch, a workaround is to createGraphics() w/ renderer JAVA2D, and use text() & textFont() there. *-:)

  • edited April 2018 Answer ✓

    So something like this (the chevron encapsulated text is the only way to get the rest of the code to appear ;) ):

    String str = "::: astronaut <unicode chars here> Testing. ";
    PFont myFont;
    PGraphics pg;
    
    void setup() {
      size(400, 400, P3D);
      background(200);
    
      pg = createGraphics(width, height, JAVA2D);
    
      myFont = createFont("OpenSansEmoji", 24, true);
    
      pg.beginDraw();
      pg.fill(0);
      pg.textFont(myFont, 24);
      pg.text(str, 10, 10, 400, 400);
      pg.endDraw();
    
      image(pg, 0, 0);
    
      noLoop();
    }
    
  • Now why didn't I think of that...? :)) Thanks guys! That did the trick!

  • edited April 2018

    Just an addendum, it bothered me that it was challenging to represent unicode characters in code (and on this forum).

    This is especially true when you want to represent supplementary characters, e.g. U+10000 to U+10FFFF. You can not simple type \u10FFFF (or \U10FFFF as you can in Java).

    I finally found an answer in an old Sun Microsystems article, titled "Supplementary Characters in the Java Platform" by Norbert Lindenberg and Masayoshi Okutsu (circa May 2004), see: oracle.com/us/technologies/java/supplementary-142654.html

    The revised example sketch looks like this:

    String rocketChar = newString(0x1F680);
    String womanChar = newString(0x1F469);
    
    String str = "::: astronaut " + womanChar + rocketChar + " Testing. Moon phases ";
    PFont myFont;
    PGraphics pg;
    
    void setup() {
      size(800, 400, P3D);
      background(200);
    
      // Moon phases
      for( int i = 0x1F311; i <= 0x1F318; i++ ) str += newString(i);
    
      pg = createGraphics(width, height, JAVA2D);
    
      myFont = createFont("OpenSansEmoji", 24, true);
    
      pg.beginDraw();
      pg.fill(0);
      pg.textFont(myFont, 24);
      pg.text(str, 10, 10, 800, 400);
      pg.endDraw();
    
      image(pg, 0, 0);
    
      noLoop();
    }
    
    // Creates new String that contains just the given code point
    // (this version that optimizes for BMP characters).
    //
    // Note: Supplementary characters are characters with code points in
    // the range U+10000 to U+10FFFF, that is, those characters that
    // could not be represented in the original 16-bit design of Unicode.
    // The set of characters from U+0000 to U+FFFF is sometimes referred
    // to as the Basic Multilingual Plane (BMP).
    // Thus, each Unicode character is either in the BMP or a
    // supplementary character.
    //
    // See: www.oracle.com/us/technologies/java/supplementary-142654.html
    
    String newString(int codePoint) {
        if (Character.charCount(codePoint) == 1) {
            return String.valueOf((char) codePoint);
        } else {
            return new String(Character.toChars(codePoint));
        }
    }
    
Sign In or Register to comment.