[OpenJDK 2D-Dev] Change in appearance of text in Java 11 with fractional metrics and text antialiasing hints on

Tredinnick, Jacob jacob_tredinnick at mentor.com
Sat Nov 2 13:40:13 UTC 2019


Hello all,

We have seen changes in the appearance of text drawn by java.awt.Graphics2D when *both* fractional metrics and text antialiasing hints are enabled, between OracleJDK 1.8.0_202 and OpenJDK 11.0.1.
The differences affects text in many fonts and multiple sizes.
In the example given here (Arial Plain, size 48), the text becomes noticeably taller & thinner in Java 11 (not just pixel diffs).

The OS is Windows 10 1709.  Scaling set to 100%.  Screen resolution 1920x1080, also seen on a different monitor at 2560x1440.
I tried various combinations of -Dsun.java2d.dpiaware with no change in the outcome.
I also tried setting FREETYPE_PROPERTIES=truetype:interpreter-version=35 & again couldn't see a change in the behaviour.

Here is a code snippet demonstrating the problem:

       protected void paintComponent(Graphics g) {
            // Java 11 text looks significantly different when *both* Fractional Text Metrics and Text antialiasing hints are on
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.setFont(new Font("Arial Plain", Font.PLAIN, 48));
            g2d.drawString(TEXT, 0, 200);
        }

Here is the full test case:

package demo;

import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;

public class RenderingHintsFontDiffDemo extends JFrame {

    private static final String TEXT = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
    private static final int FRAME_WIDTH = 800;
    private static final int FRAME_HEIGHT = 600;

    private RenderingHintsFontDiffDemo() {
        super(buildTitle());
        add(new DrawingComponent(), BorderLayout.CENTER);
        pack();
    }

    private static class DrawingComponent extends JComponent {

        @Override
        protected void paintComponent(Graphics g) {
            // Java 11 text looks noticeably different when *both* Fractional Text Metrics and Text antialiasing hints are on
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.setFont(new Font("Arial Plain", Font.PLAIN, 48));
            g2d.drawString(TEXT, 0, 200);
        }
    }

    private static String buildTitle() {
        return "RenderingHintsFontDiffDemo - " + property("java.version") + " " + property("sun.java2d.dpiaware") + " FREETYPE_PROPERTIES=" + System.getenv("FREETYPE_PROPERTIES");
    }

    private static String property(String s) {
        return s + "=" + System.getProperty(s);
    }

    private static void showFrame() {
        RenderingHintsFontDiffDemo demo = new RenderingHintsFontDiffDemo();
        demo.setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
        demo.setVisible(true);
        demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) throws InvocationTargetException, InterruptedException, ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        SwingUtilities.invokeAndWait(RenderingHintsFontDiffDemo::showFrame);
    }

}


Thanks
--
Jacob Tredinnick




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20191102/30a3b6e2/attachment.html>


More information about the 2d-dev mailing list