Search code examples
unicodecharacter-encodingjvmawt

JVM/AWT displays Unicode characters differently on different platforms


I've been working on a little programming environment for Lisp-like languages. The environment can be run on JVM or on Android, and the JVM variant can be rendered to either Swing or terminal (using Lanterna library)

My editor is itself written in Kawa Scheme, and I plan, at some point, to start using it to edit itself - but so far, I've been mostly editing it from Emacs.

I can also render GRASP expressions to strings, which lets me write unit tests in a more visual way. Here are two examples of such tests, as displayed in Emacs:

GRASP expression in Emacs in Terminal

GRASP lines in Emacs in Terminal

When I open them in the terminal version of GRASP, they look fairly decent:

GRASP expression in GRASP in Terminal

GRASP lines in GRASP in Terminal

When I open them in the graphical version of GRASP under WSL, it looks like the font is missing some glyphs (I'm using Fira Mono):

GRASP expression in GRASP AWT on WSL

GRASP lines in GRASP AWT on WSL

But when I open the graphical version of GRASP under native Windows, it seems that the unicode characters are diplayed completely off the charts:

GRASP expression in GRASP AWT on Windows

GRASP lines in GRASP AWT on Windows

So the questions are the following:

  1. How to force the JVM on Windows to choose the proper encoding?
  2. Can anyone recommend a good looking monospaced font that would support a wide range of characters, including box drawing characters?

Solution

  • Reading Mojibake in JavaFX (works fine in Netbeans) I found that in order to make the program behave properly on Windows, one needs to pass -Dfile.encoding=UTF-8 parameter to the java command (which solved the problem for me)