# Trying to check if a font can display certain glyphs

**URL:** <https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795>\
**Category:** Coding Questions\
**Created:** [May 10, 2022, 8:54am UTC](https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795 "2022-05-10T08:54:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![disuye](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@disuye](https://discourse.processing.org/u/disuye)\
**Post date:** [May 10, 2022, 8:54am UTC](https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795/1 "2022-05-10T08:54:50Z")

</div>

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,

Dan

```auto
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() {
    frameRate(frameRate);

    char [] arr = theWord.toCharArray();
    println(arr);

    fontDir = new File(fontFolder);
    fontFiles = fontDir.listFiles();
    for (int i = 0; i < fontFiles.length; i++) {
        if (fontFiles[i].getName().startsWith("._")) {
            fontFiles[i].delete();
        }
        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) {
                fontName.add(fontFiles[i]);
            }
        }
    }    
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 10, 2022, 10:47am UTC](https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795/2 "2022-05-10T10:47:06Z")

</div>

> [@disuye](#):
>
> `createFont`

Check the reference on this please

---

<div class="post-metadata">

**Author:** ![disuye](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@disuye](https://discourse.processing.org/u/disuye)\
**Post date:** [May 10, 2022, 4:39pm UTC](https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795/3 "2022-05-10T16:39:58Z")

</div>

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](https://forum.processing.org/two/discussion/10107/how-to-detect-no-glyph-char)) should help any future readers:

```auto
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!");

exit();

```

Have a great day,

Dan

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 12, 2022, 7:58pm UTC](https://discourse.processing.org/t/trying-to-check-if-a-font-can-display-certain-glyphs/36795/4 "2022-05-12T19:58:30Z")

</div>

Glad to hear that!

see [Reference / Processing.org](https://processing.org/reference/createFont_.html)
