JDK-8067279 : Some OpenType CFF fonts don't render correctly.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u51
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2014-08-09
  • Updated: 2014-12-11
  • Resolved: 2014-08-11
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux xxxxxxxx 3.13.0-30-generic #54~precise2-Ubuntu SMP Wed Jun 11 16:11:17 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Also on Windows 7 and Mac OSX Maverick

A DESCRIPTION OF THE PROBLEM :
Originally reported here:
https://github.com/adobe-fonts/source-han-sans/issues/53

As clearly visible from the screenshots attached, the fonts don't render the strings correctly. For some fonts, there is not drawing. For others, the glyphs are drawn on top of one another. For yet others, the rendering quality is inferior.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to draw some text with the SourceHanSans-Regular.otf which is available from the following github project: https://github.com/adobe-fonts/source-han-sans/

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Proper font rendering.
ACTUAL -
Poor rendering.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
There was no error reported. Even Font.canDisplayUpTo() returned -1 indicating that the font is capable of drawing the text.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.otf;

import javax.swing.*;
import java.awt.*;

public class Main extends JPanel {

    private Font mOriginalFont;

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        try {
            mOriginalFont = g.getFont();
            g.drawString("Default font:", 50, 50);
            g.drawString("Java version: " + System.getProperty("java.version"), 300, 50);
            Graphics2D g2 = (Graphics2D) g;
            draw("SourceHanSansSC-Regular.otf", "������������ ������������������ ������������������ ", g2, 100);
            draw("SourceHanSansK-Regular.otf", "������������ ������������ ������������ ������������������ ������������ ������������������������ ������������������ ������������������������������", g2, 150);
            draw("SourceHanSans-Regular.otf", "������������ ������������������ ������������������ ", g2, 200);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void draw(String fontName, String text, Graphics2D g, int y) throws Exception {
        Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream(fontName));
        font = font.deriveFont(40f);
        g.drawString(fontName + ":", 50, y);
        g.setFont(font);
        if (font.canDisplayUpTo(text) != -1) {
            System.out.println("Can't display all chars of \"" + text + "\" using font " + font.getName());
        }
        g.drawString(text, 300, y);
        g.setFont(mOriginalFont);
    }

    public static void main(String args[]) {
        Main main = new Main();
        JFrame jFrame = new JFrame();
        jFrame.setContentPane(main);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jFrame.setBounds(0,0,600,500);
        jFrame.setVisible(true);
    }
}

---------- END SOURCE ----------