Just wanted to pass along a little snippet I have found myself using fairly frequently. CSS has the ability to specify the appropriate font to use in displaying a document. It handles the tag in such a way that it can gracefully degrade from a “preferred” font through a series of less ideal typefaces depending on what’s available on the machine doing the display.
That’s a handy facility to have, even on Windows, which can have different fonts available depending on the version of Windows and what software has been installed.
Here’s a little program that illustrates the technique.
And here’s a Leiningen script to build the program.
(I will certainly be glad when Java 8 and JavaFX 8 are out so I won’t have to go through this stuff of having to specify where the JavaFX run-time is located.)
The interesting stuff is in the
get-pref functions. In
pref-typeface, you supply a list of potential fonts to use, listing the most preferred first and the least preferred last. (“Fantasy” and “Not Real” are not real typefaces. They are only to show that things work when the most preferred fonts are not available.)
get-pref function is a bit more general purpose. It finds and returns the first element of
prefs that appears in the list of available font families.
So you end up using the best available font on the system you are running.
I have not tried this on Linux or Mac, so don’t know how universally applicable it is.