18

I have listed all available fonts in system by calling

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fontNames = graphicsEnvironment.getAllFonts();
    for (Font s : fontNames) {
        System.out.println(s);
    }

On console I can see many fonts but the list looks very uncomplete. For example: My OS has installed the "System" font but in output I can't see that font:

...
java.awt.Font[family=Sylfaen,name=Sylfaen,style=plain,size=1]
java.awt.Font[family=Symbol,name=Symbol,style=plain,size=1]
java.awt.Font[family=Tahoma,name=Tahoma,style=plain,size=1]
...

Installed fonts (sorry for polish OS): enter image description here

Why is that?

Another thing is that in WordPad I can see "System" font. However in MS Word 2010 "System" font is not available.

The problem is not with this particular "System" font. There are several fonts installed but missing in Java.

EDIT: Why am I asking? My application use BIRT Report Designer to generate .rpt files with reports templates. Next I use these files to render Swing components like JLabel, JTextField etc. Main problem is: User can generate report with fields that use font that Java Swing can't handle.

The part of sample xml file generated by BIRT:

<property name="fieldName">Blablabla{Label}</property>
<property name="fontFamily">"System"</property>
<property name="fontSize">16pt</property>

Our customer requirment specifies that font can't differ between generated report and Java swing components.

What I want to do is either handle all system fonts in Java or exclude in BIRT fonts which java can't handle.

kukis
  • 4,489
  • 6
  • 27
  • 50
  • Out of interest, does `graphicsEnvironment.getAvailableFontFamilyNames()` return a complete list? – Duncan Jones Mar 27 '14 at 08:26
  • [can you test by using](http://stackoverflow.com/a/9022901/714968) or you [can to register a new Font from Java](http://stackoverflow.com/a/18462739/714968) then you can to see if all CP1250/1 forts are correctly installed in Native OS – mKorbel Mar 27 '14 at 08:27
  • I think that GraphicsEnvironmen returns all valid Fonts, but in WisOS will be everything possible – mKorbel Mar 27 '14 at 08:29
  • The program from mKorbel link doesn't render System font. – kukis Mar 27 '14 at 08:33
  • 1
    by default there weren't be any differencies, important info is that MsOffice doesn't see this font too, there are two ways re_install font in native os, register font in Java only – mKorbel Mar 27 '14 at 08:35
  • Its a fresh install of Windows 7. I need to know root of the problem, not this font. – kukis Mar 27 '14 at 08:42
  • 1
    On my computer this particular font is not a ttf font like others but has the .fon extension. Could that be the problem? – StephaneM Mar 27 '14 at 09:00
  • Yeah, maybe. I will investigate this. I see a lot of scores in google for ".fon java" – kukis Mar 27 '14 at 09:20
  • *'I see a lot of scores in google for ".fon java"'* Google ignores characters like `.` so that search should pick up everything with both font & Java! Point to some pages that actually include the string `.fon` along with Java. – Andrew Thompson Mar 28 '14 at 05:09
  • The font families present exclusively in getAllFonts() are not physical fonts, meaning they aren't font files on your computer. They are font families common in every Java implementation, and are mapped to physical fonts. Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries. Instead, the logical font names are mapped to physical fonts by the Java runtime environment. – Kathir Mar 28 '14 at 07:21
  • All implementations of the Java Platform must support TrueType fonts; support for other font technologies is implementation dependent. – Kathir Mar 28 '14 at 07:21
  • Am I right in reading that bottom part of the image to say your system has 236 fonts? How many does Java show? On my Windows system, that screen shows 244 fonts, while Java reports 265. Once 5 logical fonts are removed, it becomes 260 (16 more than can the files seen in the Windows directory). Note also that: 1) your `System` font is called `System Pogrubiona` according to that information. 2) On the other hand I have a `System Bold` font here that is visible in Windows but not Java. – Andrew Thompson Mar 28 '14 at 09:56
  • BTW - [this page](http://www.eclipse.org/forums/index.php/t/490183/) suggests that BIRT embeds fonts **by default**. I suggest you look into that. – Andrew Thompson Mar 28 '14 at 10:07

5 Answers5

9

One some Windows machines there are two buttons for installing fonts: Install For Me and Install For All Users. Java only lists fonts installed for all users.

Ivan Nikitin
  • 3,578
  • 27
  • 39
8

The JVM doesn't necessarily use the fonts installed on your System, It is being shipped with its own fonts with you can see at

JAVA_HOME/jre/lib/fonts

For you to use a font with the JVM you need create the fonts and add them to the directory above or add the directory of the new fonts to your class path.

Alternatively, you can package the fonts with your jar archive file, Download fonts here

http://cooltext.com/Fonts-Gothic

or the Microsoft true Type fonts.

JohnTheBeloved
  • 2,323
  • 3
  • 19
  • 24
5

can you try this?, and ensure that you are using the latest JDK 7

public static void main(String[] args) {        
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontFamilies = ge.getAvailableFontFamilyNames();
    for (String ff : fontFamilies) {
        System.out.println(ff);
    }
}
0009laH
  • 1,960
  • 13
  • 27
tonsquemike
  • 61
  • 2
  • 5
1

Yes, JVM does not contain all the fonts. You need to install all the core fonts manually. If you are using a Linux then this should help you :

  1. This will install all core fonts to your JVM : sudo apt-get install msttcorefonts
  2. After that,you can check these installed fonts at : /usr/share/fonts/truetype/msttcorefonts
1

I had the same issue while working with JavaFX. In Windows when you install a font, by default it's not located in

%windir%\Fonts

as expected but instead in

%homepath%\AppData\Local\Microsoft\Windows\Fonts

It seems that some classes in java doesn't check the fonts installed in user folder. Try installing the font in question by right clicking on it and choosing "Install for all users". (See the Screenshot)

abguven
  • 11
  • 2