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

Danish letter Å rendered inconsistently by GlyphVector.getOutline()

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Introduced In Version:
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      32-bit java installed.

      A DESCRIPTION OF THE PROBLEM :
      If Graphics2.transform() is applied before the FontRenderContext is retrieved, the danish letter Å is drawn correctly by means of GlyphVector.getOutline().

      However, if Graphics2.transform() is applied after the FontRenderContext is retrieved, GlyphVector.getOuline() will not draw the letter correctly. See the attached code.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached application.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The danish letter Å should be displayed correctly in both cases.
      ACTUAL -
      The danish letter Å is not shown correctly when the Graphics2D.transform() is applied after the FontRenderContext is retrieved.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.awt.font.GlyphVector;
      import java.awt.font.FontRenderContext;
      import java.awt.geom.Area;
      import java.awt.geom.AffineTransform;
      import java.io.File;
      import java.lang.System;


      public class FontTest extends JPanel {

          static Font font = null;
          
          private void drawLetter(Graphics2D g2, FontRenderContext frc, String letter) {
              GlyphVector v = font.createGlyphVector(frc,letter);
              Shape s = v.getOutline();
              g2.setColor(new Color(0,0,0));
              // Draw the black Å character
              g2.fill(s);
              g2.setColor(new Color(255,0,0));
              // Draw the red Å character
              g2.drawGlyphVector(v,1,1);
          }

          public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;
              // If the transform is done here, both Å characters are drawn correctly.
              //g2.transform(new AffineTransform(48.0,0.0,0.0,48.0,50.0,40.0));
              FontRenderContext frc = g2.getFontRenderContext();
              // If the transform is done here, the black Å character the ring placed
              // too far to the left.
              g2.transform(new AffineTransform(48.0,0.0,0.0,48.0,50.0,40.0));
              drawLetter(g2,frc, " \u00C5 " );
          }

          public static void main(String[] a) {
              File file = new File(System.getenv( " windir " )+File.separator+ " fonts " +File.separator+ " times.ttf " );
              try {
                  font = Font.createFont(Font.TRUETYPE_FONT,file);
                  JFrame f = new JFrame();
                  f.addWindowListener(new WindowAdapter() {
                          public void windowClosing(WindowEvent e) {
                              System.exit(0);
                          }
                      }
                  );
                  f.setContentPane(new FontTest());
                  f.setSize(200,200);
                  f.setVisible(true);
              } catch (Exception e) {
                  System.err.print(e.toString());
              }
          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use Graphics2D.drawGlyphVector() instead of GlyphVector.getOutline().

        Attachments

          Activity

            People

            Assignee:
            pnarayanan Prahalad Kumar Narayanan (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: