Java Unicode Chars

Hello,

I have a problem with using unicode chars in java in processing. I am trying to display random Katakana chars, which this format:

this.value=Character.toString(char(0x30A0 +round(random(0,96))));
print(this.value);

problem is that processing does not identify the char and always prints “?”

Furthermore, using the built-in “text” function, results in similar ways as it outputs on the canvas the character for unrecognised char, instead of the one that I want.

Can somebody help please?

Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA

this is not working. Processing Desktop App does not recognise the Katakana chars for some reason

It’s showing katakana :japanese_castle: characters for me here: :thinking:

/** 
 * Unicode Katakana Test (v1.0.1)
 * GoToLoop (2021/Dec/26)
 *
 * https://Discourse.Processing.org/t/java-unicode-chars/34284/4
 *
 * http://Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA
 */

static final int FONT_SIZE = 22, CHARS = 30;
static final int START = 0x30A0, RANGE = 96;

static final String FONT_JAVA = "Serif";

void setup() {
  size(700, 150);
  noLoop();
  fill(#FFFF00);

  textAlign(CENTER, CENTER);
  textFont(createFont(FONT_JAVA, FONT_SIZE, true));
}

void draw() {
  String txt = "";
  for (int i = 0; i++ < CHARS; txt += (char) (START + (int) random(RANGE)));
  println(txt);

  background(#400000);
  text(txt, width >> 1, height >> 1);
}

void mousePressed() {
  redraw();
}

void keyPressed() {
  redraw();
}

P.S.: Console log depends if the PDE’s selected font can display that UNICODE range though. :grimacing:

Unrelated I show the Unicode Chars for Audioplayer, Play, Stop etc.



/**
 * Unicode Media control symbols Test for AudioPlayer
 Keywords: Soundplayer, Sound player, Audio Player, MP3
 https://en.wikipedia.org/wiki/Media_control_symbols
 
 * based on Unicode Katakana Test (v1.0.1) by GoToLoop (2021/Dec/26)
 * https://Discourse.Processing.org/t/java-unicode-chars/34284/4
 * https://discourse.processing.org/t/java-unicode-chars/34284/3
 * http://Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA
 */

static final int FONT_SIZE = 44;
static final String FONT_JAVA = "Serif";

// Unicode values for Media control symbols - cf. https://en.wikipedia.org/wiki/Media_control_symbols
static final int[] listOfMediaControlSymbols = {
  0x23F5, 0x23F8, // Play and Pause
  0x23EF, // toggles between the present state of playing or pause, to the other.
  0x23F4, // Arrow left (Play left)
  0x23F9, // Stop
  0x23EA, 0x23E9, // Fast back and Fast run
  0x23EE, 0x23ED, // Previous and Next
  0x23FA, 0x23CF, // Record and Eject
  0x1F500, 0x1F501, 0x1F502, // Shuffle and repeat / not working
  0x2139, // info sign
  0x1F503, 0x1F504, // not working
  0x5125A // Recapitulate / not working
};

String txt = "";

//---------------------------------------------------------------------

void setup() {
  size(1500, 250);
  fill(#FFFF00);

  textAlign(CENTER, CENTER);
  textFont(createFont(FONT_JAVA, FONT_SIZE, true));

  for (int intSymbol : listOfMediaControlSymbols) {
    txt +=  "   " +  (char) intSymbol;
  }//for

  println(txt); // doesn't work
}//func

void draw() {
  background(#400000);
  text(txt, width /2, height / 2);
}//func
//

Your sketch does not show all the characters:

This will show all the characters:

// Display Unicode characters
// Author: glv
// Date:   2025-10-21
// Version: 1.0.0

// References:
// https://discourse.processing.org/t/use-emoji-in-fonts-in-processing/43685/9
// https://discourse.processing.org/t/java-unicode-chars/34284/5

PFont f;
String s = "";

// List of candidate system fonts covering Unicode symbols
String[] candidateFonts = 
  {
  "SansSerif", //Default
  //"AppleColorEmoji",   // macOS, color emoji
  "Segoe UI Symbol",   // Windows
  "Segoe UI Emoji",    // Windows
  //"NotoColorEmoji",    // Linux / if installed
  //"Apple Symbols",     // macOS alternative
  //"DejaVu Sans",       // Linux alternative
  };

// Unicode Media control symbols from:
// https://discourse.processing.org/t/java-unicode-chars/34284/5
int[] symbols = 
  {
  // 11x 0x2300
  0x23F5, 0x23F8, 0x23EF, 0x23F4, 0x23F9,
  0x23EA, 0x23E9, 0x23EE, 0x23ED, 0x23FA,
  0x23CF,
  // 5x 0x1F000
  0x1F500, 0x1F501, 0x1F502, 0x1F503, 0x1F504,
  // 1x 0x2139
  0x2139
  //0x5125A is outside valid range for Unicode up to 0x10FFFF
  };

int i = 1;

void setup()
  {
  size(800, 200, JAVA2D); // Windows scales this by 125%
  //size(800, 200, P2D);  // Some characters missing!

  f = createFont(candidateFonts[i], 32);
  textFont(f);  // switch to the new font

  // reset and rebuild string
  s = ""; 
  for (int cp : symbols)
    {
    s += new String(Character.toChars(cp)) + " ";
    }
    
  fill(0);
  text(candidateFonts[i], 50, height/3);
  text(s, 50, 2*height/3);
 
  noLoop();
  }

void draw()
  {
  }

JAVA2D shows all characters. Output is larger and pixelated because of 125% Windows scaling:

P2D output does not show all characters and does not scale up 125%:

Note: You have to open images to see the original different sizes!

Reference:
Use emoji in fonts in Processing - #10 by glv

:)

1 Like