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

Using Graphics2D.drawString to draw specified Unicode string cause Exception.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs
    • 2d
    • sparc
    • solaris_2.6

      JDK Version: 1.2beta4-I
      OS: Solaris 2.6
      Locale: C, zh, ja

      Using Graphics2D.drawString to draw specified Unicode string cause Exception.
      Following is a program to reproduce it.

      ============================CheckDrawer.java==================================
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.font.*;
      import java.awt.geom.*;
      import java.text.*;

      public class CheckDrawer extends Canvas {
          static String s = "";
          
          public static void main(String args[]) {
      if (args.length <= 0) {
      return;
      }
      if (args[0].equals("1")) {
      s = "\u3000\u3001\u3002\u30fb\u02c9\u02c7\u00a8\u3003\u3005\u2015";
      } else {
      s = "\u3001\u3002\u30fb\u02c9\u02c7\u00a8\u3003\u3005\u2015";
      }
      Frame f = new Frame("Check Drawer");
      f.setSize(300, 300);
      f.setLayout(new BorderLayout());
      f.add("Center", new CheckDrawer());
      f.show();
          }

          public CheckDrawer() {
          }

          public void paint(Graphics g) {
      Graphics2D g2 = (Graphics2D)g;
      AttributedString as = new AttributedString(s);
      AffineTransform at = new AffineTransform();
      at.setToTranslation(10.0,100.0);
      g2.transform(at);
      g2.drawString(as.getIterator(), 0.0f, 0.0f);
          }

      }
      ===============================================================================
      javac CheckDrawer.java
      type "java CheckDrawer 2", it work well
      type "java CheckDrawer 1", an exception generated:

      Exception occurred during event dispatching:
      java.lang.IllegalArgumentException: Start or limit out of range.
              at sun.awt.font.GlyphArrayFactory.createExtended(Compiled Code)
              at java.awt.font.TextLine.getComponents(Compiled Code)
              at java.awt.font.TextLine.createLineFromText(Compiled Code)
              at java.awt.font.TextLine.standardCreateTextLine(Compiled Code)
              at java.awt.font.TextLayout.standardInit(Compiled Code)
              at java.awt.font.TextLayout.<init>(Compiled Code)
              at sun.java2d.SunGraphics2D.drawString(Compiled Code)
              at CheckDrawer.paint(Compiled Code)
              at sun.awt.motif.MComponentPeer.handleEvent(Compiled Code)
              at java.awt.Component.dispatchEventImpl(Compiled Code)
              at java.awt.Component.dispatchEvent(Compiled Code)
              at java.awt.EventQueue.dispatchEvent(Compiled Code)
              at java.awt.EventDispatchThread.run(Compiled Code)


      jim.hu@prc 1998-06-08

            jraleysunw John Raley (Inactive)
            jhusunw Jim Hu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: