简体   繁体   English

Java Applet GUI组件中的多种unicode字体

[英]Multiple unicode fonts in Java Applet GUI Components

I have an applet with JLabel, JTextField and other Java Swing components. 我有一个带有JLabel,JTextField和其他Java Swing组件的applet。 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. 另一方面,我有.ttf文件的Unicode字体“ AR”,“ AR-ExtB”(扩展的B区域)和“ AR-Plus”(补充专用区域-A)。 I want the applet to use the three .ttf files on every GUI component, depending on the code points that the users enters. 我希望该applet在每个GUI组件上使用三个.ttf文件,具体取决于用户输入的代码点。

1) I know that there is no option for these components to work with multiple fonts. 1)我知道这些组件无法使用多种字体。 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. 2)嗯,有一种方法可以通过修改$ JAVA_HOME / lib目录中的fontconfig.properties文件来实现,例如,“ Dialog”(逻辑)字体已将三个.ttf文件映射为一种逻辑字体,但是问题在于所有其他Java应用程序也将具有这些字体,而这并不是想要的情况。

3) "Fallback fonts", used when there is no other font that can display the glyphs on the screen. 3)“后退字体”,当没有其他字体可以在屏幕上显示字形时使用。 This also is not a solution, because it will display only the characters that are not covered by JAVA default font. 这也不是解决方案,因为它将仅显示JAVA默认字体未涵盖的字符。

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 ? 有谁知道如何在每个GUI Swing组件中将这些.​​ttf文件用作字体,但仅在Applet内使用,而不是在JVM上运行的所有应用程序全局使用?

To use a TTF file as you a Font you need to load it and create a Font object that by set like this. 要将TTF文件用作字体,您需要加载它并创建一个按这样设置的Font对象。

    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 要使用逻辑字体,请检查Oracle文档

-- Suman -苏曼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM