Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8252213

BOLD style text has different width in Java 11 and Java 8

    Details

    • Subcomponent:
      2d
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      A DESCRIPTION OF THE PROBLEM :
      BOLD style text (with some fonts, eg: Arial Black), has different width in Java 11.0.8 and Java 8

      REGRESSION : Last worked in version 8u261

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      A sample program (attached) to draw some text in JPanel, using Arial Black font in BOLD style, can reproduce the issue.
      Noticeably, this occurs only for few fonts (counter-eg: Lucida Sans)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The width of the text should be equal to its width in Oracle Java 8
      ACTUAL -
      Width of BOLD text is not as much as it is in Java 8

      ---------- BEGIN SOURCE ----------
      import javax.swing .*;
      import java.awt .*;

      public class ReproduceBoldIssue extends JPanel {
      static final String line1 = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
      static final String line2 = "the quick brown fox jumps over the lazy dog";
      static final String line3 = "0123456789";

      @Override
      public void paint(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;

      // Define rendering hint, font name, font style and font size
      //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2.setFont(new Font("Arial Black", Font.BOLD, 22));
      g2.setColor(Color.RED);
      g2.drawString(line1, 10, 100);
      g2.drawString(line2, 10, 120);
      g2.drawString(line3, 10, 140);
      }

      public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setTitle("Bold Text Demo");
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      frame.add(new ReproduceBoldIssue());
      frame.pack();
      frame.setSize(720, 350);
      frame.setVisible(true);
      }
      }

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

      FREQUENCY : always


        Attachments

        1. ReproduceBoldIssue.java
          0.9 kB
        2. result-8u-11.png
          result-8u-11.png
          25 kB
        3. screenshots.zip
          216 kB

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: