HTML格式的JLabel上的古吉拉特语Unicode文本不起作用(方框)



在我的JLabel/JButton组件等上。我使用 HTML 来格式化文本。这在除古吉拉特语以外的所有语言中都非常有效。

我使用普通的ASCII字母对古吉拉特语字母进行编码,例如:

u0aaeu0ac1u0ab6u0acdu0a95u0ac7u0ab2u0ac0 

将解码为:

મુશ્કેલી

当我把文字放在JLabel上时:

myJLabel.setText("u0aaeu0ac1u0ab6u0acdu0a95u0ac7u0ab2u0ac0") 

文本很好地呈现在古吉拉特语中。

但是当我将 html 标签合并到它以格式化文本时,它不再起作用并且显示方框(所有其他语言都可以使用 html 呈现良好,包括阿拉伯语和西里尔字母(。一旦我使用带有古吉拉特字母的html - 标签,这就不再起作用了,并且打印了方框(未知字符(:

myJLabel.setText("<html>u0aaeu0ac1u0ab6u0acdu0a95u0ac7u0ab2u0ac0<html>")

我已经为这个问题使用了几个提示,例如以下提示,但没有成功:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

使用此代码输出中显示的字体之一:

import java.awt.Font;
import java.awt.GraphicsEnvironment;
public class GujaratiFonts {
public static void main(String[] args) {
String gujaratiText
= "u0aaeu0ac1u0ab6u0acdu0a95u0ac7u0ab2u0ac0";
Font[] fonts = GraphicsEnvironment.
getLocalGraphicsEnvironment().getAllFonts();
int count = 0;
for (Font font : fonts) {
if (font.canDisplayUpTo(gujaratiText) < 0) {
System.out.println(font.getName() + " can print this.");
count++;
}
}
System.out.println("Supported Fonts: t" + count);
System.out.println("Installed Fonts: t" + fonts.length);
}
}

结果在这里

Arial Unicode MS can print this.
Nirmala UI can print this.
Nirmala UI Bold can print this.
Nirmala UI Semilight can print this.
Supported Fonts:    4
Installed Fonts:    440

注意

除非应用提供适合所显示语言的Font,否则每次运行应用时运行该代码并选择已安装的字体是有意义的。安装的字体将在不同的计算机上随时间而变化。

最新更新