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

Soft hyphens render if not using TextLayout

XMLWordPrintable

    • 2d
    • 9
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Java 9 or 10 (did not test Java 11 ea)

      A DESCRIPTION OF THE PROBLEM :
      If kerning is enabled for a java.awt.Font instance, soft hyphens are not painted and the width of them is measured as 0 in Java 9+.

      REGRESSION : Last worked in version 8u181

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an AWT font with enabled kerning. Get width of a soft hyphen or try to paint it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Soft hyphens should be painted and width should be greater than 0.
      ACTUAL -
      Soft hyphens are not painted and measured width is 0.

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.awt.font.FontRenderContext;
      import java.awt.font.TextAttribute;
      import java.util.Collections;

      public class Worker {
          public static void main(String[] args) throws Exception {
              String SOFT_HYPHEN = Character.toString((char)173);
              FontRenderContext frc = new FontRenderContext(null, false, true);
              
              Font font = new Font("Arial",0,16); // on non-windows system use propriate system font name
              Font kerningFont = font.deriveFont(Collections.singletonMap(TextAttribute.KERNING, TextAttribute.KERNING_ON));
              
              System.out.println(font.getStringBounds(SOFT_HYPHEN, frc).getWidth());
              System.out.println(kerningFont.getStringBounds(SOFT_HYPHEN, frc).getWidth()); //Should be same as above but is 0 in Java 9+
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Measure and paint soft hyphens with alternative instance of java.awt.Font.

      FREQUENCY : always


            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: