0
votes

I have an applet with JLabel, JTextField and other Java Swing components. On the other hand, i have unicode fonts "AR", "AR-ExtB" (extended B area) and "AR-Plus" (Supplementary Private Use Area-A) which are .ttf files. I want the applet to use the three .ttf files on every GUI component, depending on the code points that the users enters.

1) I know that there is no option for these components to work with multiple fonts. So, the explicit way to set the fonts to the components is not an option.

2) Well, there is a way to accomplish this by modifying the fontconfig.properties file in $JAVA_HOME/lib directory, where, for example, the "Dialog" (logical) font has mapped the three .ttf files as one logical font, but the problem is that all other java applications, also will have these fonts, and that is not the wanted scenario.

3) "Fallback fonts", used when there is no other font that can display the glyphs on the screen. This also is not a solution, because it will display only the characters that are not covered by JAVA default font.

The question is:

Do anyone have an idea how to use these .ttf files as font in every GUI Swing component, but only within the Applet, not globally for all applications that run on JVM ?

1
Regarding point 2 - do you have any links to support that this is how java logical fonts work? My understanding was that the java concept of a "logical" font just meant that the JDK would guarantee that if you use a logical font name like "Dialog" you were assured that some physical font would definitely be loaded (thus avoiding the problem of having to worry about what fonts are loaded on any given platform). - Shorn
Ooops, never mind - I see now in the font config doco that's how it's supposed to work (I thought that fontconfig.properties stuff was for the HtmlView). - Shorn

1 Answers

0
votes

To use a TTF file as you a Font you need to load it and create a Font object that by set like this.

    try {
     GraphicsEnvironment ge = 
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf")));
} catch (IOException|FontFormatException e) {
     //Handle exception
}

After this the font object can be used.

To use logical font check Oracle docs

-- Suman