从 google/noto 字体创建 java.awt.Font
Create java.awt.Font from google/noto font
我的系统上安装了 noto 字体 (https://www.google.com/get/noto/),但是当我尝试使用某些字体(繁体中文、简体中文)时,我收到的只是一个空 space:
Font notoCJKtcfont= new Font("Noto Sans CJK TC Black", Font.PLAIN, 14);
JFrame frame = new JFrame("Test font");
JLabel chineseLable = new JLabel("大家好。 你好嗎&23latinsymbolsδ");
chineseLable.setFont(notoCJKtcfont);
frame.add(chineseLable);
frame.pack();
frame.setVisible(true);
是否与OTF格式和非拉丁符号有关?有什么方法可以使用这些字体 - 所以它们会正确显示吗?
我研究过"Java seems not to render many CJK OpenType fonts correctly"。所以,这可能与https://bugs.openjdk.java.net/browse/JDK-7140863
有关
我安装的字体是这样的
private void render(Graphics g)
{
try
{
Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("font.ttf"));
font = font.deriveFont(24F);
g.setFont(font);
g.setColor(Color.BLUE);
g.drawString(String.valueOf(count), 50, 50);
} catch (FileNotFoundException ex)
{
Logger.getLogger(TestFont.class.getName()).log(Level.SEVERE, null, ex);
} catch (FontFormatException | IOException ex)
{
Logger.getLogger(TestFont.class.getName()).log(Level.SEVERE, null, ex);
}
}
我的系统上安装了 noto 字体 (https://www.google.com/get/noto/),但是当我尝试使用某些字体(繁体中文、简体中文)时,我收到的只是一个空 space:
Font notoCJKtcfont= new Font("Noto Sans CJK TC Black", Font.PLAIN, 14);
JFrame frame = new JFrame("Test font");
JLabel chineseLable = new JLabel("大家好。 你好嗎&23latinsymbolsδ");
chineseLable.setFont(notoCJKtcfont);
frame.add(chineseLable);
frame.pack();
frame.setVisible(true);
是否与OTF格式和非拉丁符号有关?有什么方法可以使用这些字体 - 所以它们会正确显示吗?
我研究过"Java seems not to render many CJK OpenType fonts correctly"。所以,这可能与https://bugs.openjdk.java.net/browse/JDK-7140863
有关我安装的字体是这样的
private void render(Graphics g)
{
try
{
Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("font.ttf"));
font = font.deriveFont(24F);
g.setFont(font);
g.setColor(Color.BLUE);
g.drawString(String.valueOf(count), 50, 50);
} catch (FileNotFoundException ex)
{
Logger.getLogger(TestFont.class.getName()).log(Level.SEVERE, null, ex);
} catch (FontFormatException | IOException ex)
{
Logger.getLogger(TestFont.class.getName()).log(Level.SEVERE, null, ex);
}
}