简体   繁体   中英

Create java.awt.Font from google/noto font

I have noto fonts installed ( https://www.google.com/get/noto/ ) on my system but when I try to use some of the fonts (Chinese traditional, Chinese simplified) I receive just an empty 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);

在此处输入图片说明

Does it have something to do with OTF format and non-Latin symbols? Is there any way to use those fonts - so they will display correctly?

I have researched that "Java seems not to render many CJK OpenType fonts correctly".So, this can be related to https://bugs.openjdk.java.net/browse/JDK-7140863

https://github.com/adobe-fonts/source-han-sans/issues/53

I installed the fonts like this

    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);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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