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

[macosx] Printing unicode chars with drawGlyphVector is broken

XMLWordPrintable

    • 2d
    • os_x

      FULL PRODUCT VERSION :
      java version " 1.7.0_21 "
      Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
          System Software Overview:

            System Version: Mac OS X 10.7.5 (11G63)
            Kernel Version: Darwin 11.4.2
            Boot Volume: Macintosh HD
            Boot Mode: Normal
            Secure Virtual Memory: Enabled
            64-bit Kernel and Extensions: Yes
            Time since boot: 22 days 1:05

      A DESCRIPTION OF THE PROBLEM :
      drawGlyphVector method fails to draw japanese unicode characters.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the testcase provided and print to a printer. Look at the printer output.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected the characters to print as they appear on screen.
      ACTUAL -
      The Japanese characters print fine but anything after the last Japanese character in a string is garbage. All subsequent print operations are garbled / ignored.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import java.awt.print.*;
      import javax.print.attribute.*;
      import javax.print.attribute.standard.*;
      import java.awt.font.*;

      public class PrintUnicodeTest implements Printable
      {
      public static int count = 0;
         public void startTestCase()
         {
          PrinterJob pj = PrinterJob.getPrinterJob();
              PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
              pras.add(DialogTypeSelection.NATIVE);
              pj.setPrintable(this);
              if (pj.printDialog(pras))
              {
                  try{
                      pj.print(pras);
                  } catch (Exception e) { }
              }
         }

          public int print(Graphics g, PageFormat pf, int pageNo) throws PrinterException
          {
              Graphics2D g2d = (Graphics2D)g;
              if(pageNo > 0)
                  return Printable.NO_SUCH_PAGE;
              else {
                  g2d.setColor(Color.blue);
                  Font fnt = new Font( " Serif " , Font.PLAIN, 24);
                  g2d.setFont(fnt);
                  String s = " ???.m " ;
                  int x = 100, y = 100;
                  GlyphVector glyphVec = g2d.getFont().createGlyphVector( g2d.getFontRenderContext(), " using shape fill: " +s);
                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                  // extract glyph shapes and draw
                  Shape shape = glyphVec.getOutline();
                  g2d.translate(x, y);
                  g2d.fill(shape);
                  g2d.translate(-x, -y);
                  // use in-built drawString method
                  g.drawString( " using drawString (sun Bug#7183516): " +s, x, y*2);
                  // use in-built drawGlyphVector method
                  GlyphVector glyphVec2 = g2d.getFont().createGlyphVector( g2d.getFontRenderContext(), " using drawGlyphVector: " +s);
                  g2d.drawGlyphVector(glyphVec2, (float)x, (float)y*3);
                  return Printable.PAGE_EXISTS;
              }
          }

         public static void main (String []Args) {
            PrintUnicodeTest st = new PrintUnicodeTest ();
            st.startTestCase ();
         }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      extract glyph shapes from the glyph vector and fill the shape in graphics context.

            bae Andrew Brygin
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: