It is currently Thu Jul 31, 2014 5:31 am




Post new topic Reply to topic  [ 15 posts ] 
 Java Fonts and Linux 
Author Message
General
General

Joined: Sun Feb 25, 2007 2:54 pm
Posts: 563
Post 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
Code:
sudo apt-get install msttcorefonts


and change the font mapping by
Code:
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.


Mon Apr 27, 2009 8:27 am
Profile WWW
Moderator
Moderator

Joined: Sun Apr 02, 2006 2:46 pm
Posts: 4046
Location: Sacramento, CA
Post Re: Java Fonts and Linux
Kyle - thanks for posting this, very handy.

_________________
Carl Gould
Co-Director, Software Engineering
Inductive Automation


Mon Apr 27, 2009 8:54 am
Profile WWW
General
General

Joined: Fri Aug 03, 2007 11:39 am
Posts: 626
Location: Devon, England
Post Re: Java Fonts and Linux
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

_________________
Al
DataCapture Ltd.

www.datacap.co.uk


Mon Apr 27, 2009 1:04 pm
Profile
Captain
Captain

Joined: Fri Apr 27, 2007 5:25 am
Posts: 88
Location: Fremont, CA
Post Re: Java Fonts and Linux
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.


Mon May 11, 2009 10:29 am
Profile
General
General

Joined: Fri Aug 03, 2007 11:39 am
Posts: 626
Location: Devon, England
Post Re: Java Fonts and Linux
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.

_________________
Al
DataCapture Ltd.

www.datacap.co.uk


Fri Apr 30, 2010 1:31 am
Profile
General
General

Joined: Sun Feb 25, 2007 2:54 pm
Posts: 563
Post Re: Java Fonts and Linux
Ubuntu 10.04+ Font Configuration

The setup has change in 10.04+.

First, you still need to install the Arial font.
Code:
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.

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


Then replace /etc/java-6-sun/fontconfig.properties with the attached file.


Attachments:
fontconfig.properties [17.56 KiB]
Downloaded 1125 times
Tue Oct 26, 2010 5:51 am
Profile WWW
General
General

Joined: Fri Aug 03, 2007 11:39 am
Posts: 626
Location: Devon, England
Post Re: Java Fonts and Linux
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 of
Code:
dialog.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.


Attachments:
fontconfig.properties [18.05 KiB]
Downloaded 637 times

_________________
Al
DataCapture Ltd.

www.datacap.co.uk
Tue Oct 26, 2010 2:01 pm
Profile
Lieutenant
Lieutenant

Joined: Wed May 25, 2011 10:50 am
Posts: 67
Location: Wichita Falls, TX
Post Re: Java Fonts and Linux
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: http://linuxandfriends.com/2009/07/20/h ... tu-debian/


Fri Sep 02, 2011 11:48 am
Profile
Lieutenant
Lieutenant

Joined: Wed May 25, 2011 10:50 am
Posts: 67
Location: Wichita Falls, TX
Post Re: Java Fonts and Linux
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:
Code:
/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):

Code:
dpkg-reconfigure fontconfig


Thu Jun 28, 2012 6:34 am
Profile
Private
Private

Joined: Mon Jan 23, 2012 7:46 am
Posts: 34
Location: Breinigsville, PA
Post Re: Java Fonts and Linux
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 <prefer>...</prefer> grouping:

Code:
<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>


Mon Nov 05, 2012 11:58 am
Profile
Sergeant
Sergeant

Joined: Wed Apr 03, 2013 7:11 am
Posts: 58
Post Re: Java Fonts and Linux
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.


Attachments:
linux_windows_fonts.jpg
linux_windows_fonts.jpg [ 20.31 KiB | Viewed 4633 times ]
Wed May 01, 2013 7:11 am
Profile
Lieutenant
Lieutenant

Joined: Wed May 25, 2011 10:50 am
Posts: 67
Location: Wichita Falls, TX
Post Re: Java Fonts and Linux
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:
Code:
$ sudo fc-cache -f -v

Hope this helps.


Wed May 01, 2013 8:19 am
Profile
Sergeant
Sergeant

Joined: Wed Apr 03, 2013 7:11 am
Posts: 58
Post Re: Java Fonts and Linux
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
Attachment:
60-latin.conf.txt [1.66 KiB]
Downloaded 217 times
. Did you have to reinstall java or re-download the jnlp file or anything?

Thanks again for posting the tips.


Wed May 01, 2013 8:58 am
Profile
Lieutenant
Lieutenant

Joined: Wed May 25, 2011 10:50 am
Posts: 67
Location: Wichita Falls, TX
Post Re: Java Fonts and Linux
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.


Tue May 07, 2013 5:55 am
Profile
General
General

Joined: Fri Mar 19, 2010 2:56 pm
Posts: 415
Post Re: Java Fonts and Linux
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.

_________________
Nick Mudge
Ignition Consultant
http://www.perfectabstractions.com/blog


Mon Jul 28, 2014 11:06 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: