[OpenJDK 2D-Dev] Change in appearance of text in Java 11 with fractional metrics and text antialiasing hints on
Philip Race
philip.race at oracle.com
Sat Nov 2 15:19:24 UTC 2019
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20191102/cd1d7c02/attachment-0001.html>
More information about the 2d-dev
mailing list