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

Letter “o” with Graphics2D.drawString at font size 101 is angled, not round

    XMLWordPrintable

Details

    • 2d
    • x86_64
    • linux_ubuntu

    Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Ubuntu 18.04.2 LTS (Lenovo notebook) as well as Ubuntu 16.04 LTS (HP desktop).
      Java: OpenJDK 1.8.0_212.
      IDE: Eclipse 2019-03.

      A DESCRIPTION OF THE PROBLEM :
      Drawing text with font sizes up to 100 works fine with Graphics2D.drawString. Problem: With font size 101 some round characters (like "o") are getting angled.
      See images of expected/actual comparison here: https://stackoverflow.com/questions/56941002/why-is-letter-o-with-graphics2d-drawstring-at-font-size-101-broken

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Download font as described below. Most obvious behaviour is with font "Amatic SC".

      This behaviour is reproducable with fonts "Abril_Fatface", "Amatic_SC" and "Cinzel_Decorative" (from google Fonts, e.g. https://fonts.google.com/specimen/Abril+Fatface or https://fonts.google.com/specimen/Amatic+SC ; ttf-file downloadable via "select this font" and then "download this section" within the dialog "1 family selected"). With some other fonts the tested strings are drawn OK.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The letter "o" should be round at fontsize 101, as it is with fontsize <= 100.
      LibreOffice shows the characters round (as expected - so the font itself is not the problem, I guess).
      ACTUAL -
      The letter "o" is angled.
      See images of expected/actual comparison here: https://stackoverflow.com/questions/56941002/why-is-letter-o-with-graphics2d-drawstring-at-font-size-101-broken

      ---------- BEGIN SOURCE ----------
          import java.awt.Color;
          import java.awt.Font;
          import java.awt.FontFormatException;
          import java.awt.Graphics2D;
          import java.awt.image.BufferedImage;
          import java.io.File;
          import java.io.IOException;
          import javax.imageio.ImageIO;
          public class CustomFontWriting {
              public static void main(String[] args) throws FontFormatException, IOException {
                  Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Amatic_SC.ttf"));
                  // Create empty image
                  BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
                  Graphics2D graphics = image.createGraphics();
                  graphics.setColor(Color.BLACK);
                  // Draw letter "o" with fontsize 101 into an image
                  graphics.setFont(font.deriveFont(Font.PLAIN, 101));
                  graphics.drawString("o", 0, 200);
                  // Write image to disk
                  File output = new File("output.png");
                  ImageIO.write(image, "png", output);
              }
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      With Oracle Java SE RE 1.8.0_171-b11 executed at Windows 7 64 bit there is no such problem. The letter is perfectly round.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: