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

Kerning broken on Arial, 11Pt Size on Graphics2d fillOutline

    XMLWordPrintable

Details

    • 2d
    • x86_64
    • windows_10

    Description

      A DESCRIPTION OF THE PROBLEM :
      Using the Graphics2d fillOutline with AWT Font Arial 11pt size leads to an non working kerning. Spaces between letters like 2 and A are extreme big, while others are touching each other.


      ---------- BEGIN SOURCE ----------
      import java.awt.Component;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.Shape;
      import java.awt.font.TextAttribute;
      import java.awt.font.TextLayout;
      import java.awt.geom.AffineTransform;
      import java.text.AttributedString;

      import javax.swing.JFrame;

      import org.eclipse.swt.SWT;
      import org.eclipse.swt.graphics.FontData;

      public class CheckLabel {

        public static void main(String[] args) {

          JFrame f = new JFrame();
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

          f.add(new Component() {
            @Override
            public void paint(Graphics g) {
              Graphics2D g2d = (Graphics2D) g;
              AttributedString attributedString = new AttributedString("PwA");
              FontData fontData = new FontData("Arial", 11, SWT.NONE); //$NON-NLS-1$
              java.awt.Font awtFont = new java.awt.Font(fontData.getName(), fontData.getStyle(), fontData.getHeight());
              attributedString.addAttribute(TextAttribute.FONT, awtFont);
              TextLayout tl = new TextLayout("PwA", attributedString.getIterator().getAttributes(), g2d.getFontRenderContext());
              //shape is created from the outline of the textlayout
              Shape outline = tl.getOutline(AffineTransform.getTranslateInstance(0, 20));
              g2d.fill(outline);
              g2d.setTransform(AffineTransform.getScaleInstance(2, 2));
              Shape outline2 = tl.getOutline(AffineTransform.getTranslateInstance(0, 100));

              g2d.fill(outline2);
            }

            @Override
            public Dimension getSize() {
              return new Dimension(100, 100);
            }
          });

          f.setSize(400, 400);

          f.setVisible(true);
        }

      }

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

      FREQUENCY : always


      Attachments

        1. Capture_01.JPG
          Capture_01.JPG
          38 kB
        2. Capture_02.JPG
          Capture_02.JPG
          103 kB
        3. Capture_03.jpg
          Capture_03.jpg
          34 kB
        4. CheckLabel.java
          2 kB

        Issue Links

          Activity

            People

              skodandarama Suman Rajkumaar Kodandarama (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: