Java Fonts and Linux

In Ubuntu anyways, the Dialog logical font maps to LucidaSans, whereas in Windows, it maps to Arial. The result of this is you text wont always look proper, or in my case, fit in the specified text box. To fix this, you need to install the Arial font

sudo apt-get install msttcorefonts

and change the font mapping by

sudo nano /usr/lib/jvm/java-6-sun/jre/lib/fontconfig.properties

and change lucidasans to arial in all the dialog mappings.

Other versions of Linux can be fixed the same way, although they might use a different package manager, or might need the fonts to be installed manually.

Kyle - thanks for posting this, very handy.

That’s great Kyle - a big improvement. I’ve tried my current app. in Ubuntu 9.04 and it looks just the same as when running in Windows.

Al

Supposedly you aren’t supposed to use these fonts unless you own some copy of Windows. Not a problem for most people, but I can see a business being careful about things like that. Then again, it is hard to find a business that doesn’t have at least one Windows PC somewhere.

Any idea how to change the fonts used by OpenJDK Java 6? This is the version of Java most easily installed when using Ubuntu 10.04.

Ubuntu 10.04+ Font Configuration

The setup has change in 10.04+.

First, you still need to install the Arial font.

sudo aptitude install msttcorefonts

Secondly, there are specific mapping files installed for Ubuntu, But I just delete them and deal directly with the fontconfig.properties file.

sudo rm /usr/lib/jvm/java-6-sun/jre/lib/fontconfig.Ubuntu.*

Then replace /etc/java-6-sun/fontconfig.properties with the attached file.
fontconfig.properties (17.6 KB)

Thanks for that Kyle, that helped me get it working.

I found a good explanation of how Java maps logical fonts to physical fonts using font configuration files here. This explained that the fontconfig.Ubuntu.bfc file was taking precedence over the fontconfig.properties file. When you delete the Ubuntu version of the file the system then defaults to using fontconfig.properties.

I noticed that your version of fontconfig.properties has an xlfd name for dialog.plain.latin-1 ofdialog.plain.latin-1=-b&h-arial-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1 I found a tool called xfontsel which lets you create these names - this shows that Arial comes under monotype. As far as I can see you also have to have an entry in the Font File Names section for each flavour of Arial i.e. normal, bold, italic and bold italic. I’ve attached an updated fontconfig.properties file which includes these changes.
fontconfig.properties (18.0 KB)

While this is an old post, it was helpful to me - thanks.

Something else I learned is that msttcorefonts requires an internet connection. If you have a machine or client without an internet connection, fonts can be easily installed per the following instructions: linuxandfriends.com/2009/07/20/h … tu-debian/

Java 7 no longer uses the fontconfig.properties file on Linux, though it still has all of the files as if it did. It now uses the Linux font configuration file libfontconfig, which has to be re-built after the fonts are installed.

First, with a text editor, modify the file: /etc/fonts/conf.avail/60-latin.conf
This is an xml file that tells fontconfig which latin font families to prefer for each alias type (serif, sans-serif, monospace, etc.). Move or delete font families under each appropriate alias to get the preferred fonts to the top of each list.

Next, to rebuild libfontconfig, run the following from the command line (prefix sudo if appropriate, of course):

dpkg-reconfigure fontconfig

Sorry to bump such an old thread, but I wanted to augment pphillips’ most recent post in case it’s useful to some other Linux user. Thanks for the post by the way. This was extremely helpful!

I’m a Linux user for my daily computing needs, but all of the users who run the Ignition clients run Windows. I had an issue where alignment of text wasn’t showing up the same in Windows and Linux, so I was forced to develop for Ignition within Windows (through a VM, at least). We’ve been running the gateway through Windows, so I assumed that was all that Inductive supported it for.

I recently decided to give it another go on Linux, since I recently found that the Ignition gateway specifically supports Linux as well. Here are the font orderings in the XML file mentioned by pphillips that I moved to achieve the same look and feel as on Windows. I need to do a bit more in depth testing for it, but the screens that I’ve looked at so far look good to me on Linux. The following XML elements should be moved to the top within their respective … grouping:

<family>Times New Roman</family> <family>Arial</family> <family>Lucida Sans Unicode</family> <family>Helvetica</family> <family>Courier New</family> <family>Courier</family> <family>Impact</family> <family>Comic Sans MS</family>

Has anyone else had any success (or lack of) with the techniques described above? I am running java 7 on a test linux client and after installing the ms fonts package, changing the font preference config file and running reconfiguring via dpkg, I’m still seeing native linux fonts.

In the attached file, the top half is windows, bottom is linux. Does anyone know the name of the font in the linux shot? Maybe Deja Vu Sans? I’m trying to pin it down so I can at least attack it from that direction.

Thanks for posting all the tips. Its very helpful.

Typically, the default sans-serif font in Ubuntu is Lucinda Sans. In the “60-latin.conf” file, I normally add “Arial” somewhere above “Lucinda Sans”, since the one at the top gets preference. Of course, if you change this file, you should rebuild the libfontconfig file.

The other thing is to first make sure the msttcorefonts got installed ok. They should be somewhere in one of the directories pointed to by “/etc/fonts/fonts.conf”. To make sure linux recognizes the fonts, run:

$ sudo fc-cache -f -v

Hope this helps.

running that and grep’ing for ms gives: “/usr/share/fonts/truetype/msttcorefonts: caching, new cache contents: 60 fonts, 0 dirs”

I’ve got arial and helvetica at the top of my 60-latin.conf file 60-latin.conf.txt (1.66 KB). Did you have to reinstall java or re-download the jnlp file or anything?

Thanks again for posting the tips.

Sorry, I misspoke about the default fonts - you were correct, Ubuntu default is DejaVu Sans rather than Lucinda Sans.

From my experience, you should not have to re-load Java or the jnlp file, but you may need to re-start the application. I think Java should pick this up when it starts up.

pphillips’ method will not work if an operating system specific fontconfig properties file exists that matches the operating system.

For example, if on Ubuntu the “/usr/lib/jvm/java-7-oracle/jre/lib/fontconfig.Ubuntu.properties” file must be removed.

I recently wrote a blog post about installing Windows fonts in Java on Linux.

Thanks Nick, for posting this. Good to have this clarified and in one location.

Trying to bump this up - the above packages no longer seem to be available. Anyone know how to install the MSfonts now?

Thanks!

Worked for me (Ubuntu 14.04).

apt-get install ttf-mscorefonts-installer

Using this works too, it automatically substituted ttf-mscorefonts-installer

apt-get install msttcorefonts

What’s missing for you?

Package ttf-mscorefonts-installer is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Same version of Ubuntu…

That’s odd, I just tried it on a fairly virgin install of Ubuntu 14.04 (only change from stock was removing IcedTea and installing Java 8 ), and it worked great.

Are you running headless or anything unusual like that? Did you disable the multiverse repositories?