Thanks Phil,

I did wonder whether or not this was going to be positioned as a bug, 
particularly given the use of hints.

>From our perspective, we'd like to explore the possibility of getting a fix 
>into a future Java 11 version.
A new hint would be fine & we would not require it to work with Swing text 
components.  Only Graphics2D as in the code below.
I'm not sure what exactly you mean by "properly accounting for the change in 
size caused by fractional
metrics when measuring the UI layout" but I guess we could clarify this this if 
a Java 11 fix is feasible.

Do you think it would be possible to get this new hint into a Java 11 update?
Would this be tracked but the issue you noted below?

Thanks
--
Jake

From: Philip Race [mailto:philip.r...@oracle.com]
Sent: Saturday, November 2, 2019 3:19 PM
To: Tredinnick, Jacob <jacob_tredinn...@mentor.com>
Cc: 2d-dev@openjdk.java.net
Subject: Re: [OpenJDK 2D-Dev] Change in appearance of text in Java 11 with 
fractional metrics and text antialiasing hints on

https://bugs.openjdk.java.net/browse/JDK-8214481

As you can see from reading there, this isn't really a bug, just a change in 
behaviour,
and it is not clear if we want to restore the 8u behaviour.

I think I'd prefer another hint to be created although apps would need to update
to it and run on the latest JDK.

Also if you wanted to use it in standard Swing text components, Swing would need
to be updated. What you are doing below is OK if you have your own component
and take care of properly accounting for the change in size caused by fractional
metrics when measuring the UI layout but you can't just insert that into a 
standard
Swing component UI.

-phil.

On 11/2/19, 6:40 AM, Tredinnick, Jacob wrote:
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




Reply via email to