3

In my Swing application I use Arial font. Unfortunately it is rendered differently on different platforms:

Windows:

Windows variant

Mac OS X:

enter image description here

Linux:

enter image description here

Windows and Mac OS X variants look almost the same. Linux is quite different and seems to be not an Arial at all. Main problem is the different width of letters...

What would be the best solution that would render text similar to Windows variant on Linux? Probably some alternative fonts like for example Nimbus Sans L?

Some limitations: JRE cannot be supplied with the application and it should be very close to Arial.

Thanks!

Andrej
  • 1,679
  • 1
  • 26
  • 40

4 Answers4

5

Embrace platform variety. Given that different platforms have similar fonts with different metrics, let each component do the work of calculating its own preferred size by not interfering and by using layouts correctly. Here's a nice example with screenshots.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 2
    As an aside, choosing a _logical_ font like [`Font.SANS_SERIF`](http://docs.oracle.com/javase/7/docs/api/java/awt/Font.html#SANS_SERIF), rather than a _physical_ font like _Ariel_, is a convenient way to get the platform designer's best choice. – trashgod Mar 15 '12 at 22:03
  • But I am using custom look and feel. And at some places absolute layout is used. It's not an option for me to switch to a layout manager. BTW screenshots from your example show an ugly and unergonomic design. – Andrej Mar 16 '12 at 18:33
  • Is your application intended to work on more than one platform? – trashgod Mar 16 '12 at 22:25
2

One solution may be load the font file using Font.createFont(). Here's a sample.

  • Thanks! Do you know if it is allowed by the Arial license? I think it must be bought before it can be bundled into an application. – Andrej Mar 15 '12 at 16:14
  • I think you will have to find a free font to use. [Arial font license](http://en.wikipedia.org/wiki/Arial) says that you cannot distribute the font. But there are many free fonts in the web, I have sure that you will find something that fits :) –  Mar 15 '12 at 16:21
0

Did you try antialiasing, like this article http://docs.oracle.com/javase/tutorial/2d/text/renderinghints.html

tiboo
  • 8,213
  • 6
  • 33
  • 43
  • Yes, actually it is enabled on example images. And antialiasing does not affect the width of letters. – Andrej Nov 19 '13 at 14:06
0

You can install Microsoft's free fonts on Linux and use them in Java. This includes an Arial font. This blog post shows you how: How to Install Windows Fonts in Java on Linux

Nick Mudge
  • 51
  • 1
  • 4