Search code examples
javaunicodefontsfilternon-printable

Filtering characters missing from the user’s font in Java


I want to build a somewhat simple table with Java (as an exercise) to check for the existence of legal printable Unicode code point in the end-user’s font. Because some fonts cannot print valid code points, I have to know which printable code points the user’s font is nevertheless missing and so cannot print.

For example, if a font supports only Latin characters, I cannot print Greek characters using it, let alone Japanese characters. Unicode says they’re all printable, but the user’s font may not be good enough.

After a little research I’ve been able to print most of the characters in Eclipse (by adjusing the Encoding). However I still have a bunch of unknown/unprintable characters in my output, in that when I look at the output I see all these empty rectangles for some of my printable characters.

I’ve tried filtering them but I can’t find any way to do it. FYI I’m basically just setting a character's value to 50, 100 or 1000, then incremeningt it via a for loop from there to check what characters I can or cannot (or should not?) print.

Can anyone give me some hints on where to start here?


Solution

  • Your task is actually a little more complex than encoding because the font that you are trying to print from makes a big difference in the output. I.e. not all fonts support the same set of characters. In fact, the support of character ranges differs wildly from font to font.

    That said, your problem now becomes: How do I detect whether a certain font supports a given character? And that question has been asked and answered... See here for the Java doc of the canDisplay function which is a member of the Font class.