Trying to check if a font can display certain glyphs

Regarding the code below, I’m having difficulties using font.canDisplayUpTo() – I think it’s an issue with the URL being passed to Font font =… ? The fonts are all fine, so it’s something to do with how Font is being fed the file locations?

Thanks in advance if you have any ideas,


int sizeWidth = 800;
int sizeHeight = 800;
int frameRate = 22;

File fontDir;
File [] fontFiles;
String fontFolder = "/Volumes/macOS/Users/****USERNAME****/Desktop/Fonts/";
String theWord = "fonte";
String [] fontArray;
PFont pfont;
Font font;
ArrayList<File> fontName = new ArrayList<File>();

import java.awt.Font;

void settings() {
    size(sizeWidth, sizeHeight);

void setup() {

    char [] arr = theWord.toCharArray();

    fontDir = new File(fontFolder);
    fontFiles = fontDir.listFiles();
    for (int i = 0; i < fontFiles.length; i++) {
        if (fontFiles[i].getName().startsWith("._")) {
        if (fontFiles[i].toString().matches(".*(ttf|otf)$")) {
            // ERROR: Unhandled exception type FontFormatException... 
            Font font = Font.createFont(Font.TRUETYPE_FONT, fontFiles[i]);
            if (font.canDisplayUpTo(arr, 0, arr.length) == -1) {

Check the reference on this please

EDIT: I was barking up the wrong tree.

Never managed to get Java’s Font createFont() & the InputStream rigmarole to work as I needed … so I resolved my issue by ignoring the Java approach and instead used PFont getGlyph() to check if a font was able to render a specific character.

The example shown at this URL (How to detect no glyph-char - Processing 2.x and 3.x Forum) should help any future readers:

PFont font = createFont("DejaVu Sans", 32, true);
char ch = '\u171A';

if (font.getGlyph(ch) == null)  println("Char ", ch, "is unavailable!");
else                            println("Char ", ch, "is displayable!");


Have a great day,


1 Like

Glad to hear that!

see Reference /

1 Like