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

Method Graphics2D.drawString() can not work.

    XMLWordPrintable

Details

    • 2d
    • 1.2beta3
    • sparc
    • solaris_2.6
    • Verified

    Description

      JDK Version:1.2beta3-F
      Locale: All
      Platform: Sun Ultra 1
      OS: Solaris 2.6

      Graphics2d.drawString() can not work.
      Following is the test program.
      ==============================t11.java=====================================


      import java.awt.*;
      import java.awt.font.*;
      import java.awt.event.*;
      import java.awt.geom.*;


      public class t11 extends Canvas {

      private String drawString = "";
      private Font drawFont ;

          public t11() {
              setBackground(Color.cyan);
      drawFont = getFont();
      if (drawFont == null ) {
      drawFont = new Font("Dialog",Font.PLAIN,24);
      }
      setFont(drawFont);
          }

      public void changeSetting(Font f) {
      drawFont = f;
      setFont(drawFont);
      }

      public void changeSetting(String s) {
      drawString = "-"+s+"-";
      repaint();
      }

      public void changeSetting(String s, Font f) {
      changeSetting(s);
      changeSetting(f);
      }

          public void paint(Graphics g) {

              Graphics2D g2 = (Graphics2D) g;

              AffineTransform fontAT = new AffineTransform();
              fontAT.setToScale(72.0,72.0);

              Font theDerivedFont = drawFont.deriveFont(fontAT);

              StyledString ss = new StyledString(drawString,theDerivedFont);

              // define the rendering transform
              AffineTransform at = new AffineTransform();
              at.setToTranslation(10.0,400.0);
              g2.transform(at);

              g2.drawString(ss,0.0f,0.0f);

      at.setToTranslation(100.0,100.0);
              g2.transform(at);
              at.setToRotation(-Math.PI/4.0);
              g2.transform(at);
      g2.setColor(Color.red);

      g2.drawString(ss,0.0f,0.0f);


          }


          public static void main(String s[]) {
              WindowListener l = new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
                  public void windowClosed(WindowEvent e) {
                      System.exit(0);
                  }
              };
          
      String ss = "This is a test";
      if (s.length >= 1) {
      if (s[0].equals("2")) {
      ss = "This—Ô’Ãʇ©÷’ÁÐÚa test";
      }
      }

          Frame f = new Frame("Simple 2D Demo...");
          f.addWindowListener(l);
          
      t11 d = new t11();
      d.changeSetting(new Font("Dialog",Font.PLAIN,32));
      d.changeSetting(ss);

          f.add("Center",d);
          f.pack();
          f.setSize(new Dimension(800,600));
          f.show();

          }

      }
      =======================================================================
      When type "java t11", it just run to draw a English string, first line
      on the canvas is to draw this string horizontally, but it show a strange
      string. The second line is to draw it with rotating a angle, the string
      is shown correctly, but has no angle. When typing "java t11 2" in zh loca,
      it wiil run to draw a string containing Chinese, exception will be caught.
      The ecception is as follows:

      Exception occurred during event dispatching:
      java.lang.IllegalArgumentException: GlyphSet constructor passed short glyphCodes array
              at java.awt.StandardGlyphSet.<init>(StandardGlyphSet.java:103)
              at java.awt.Font.getGlyphSet(Font.java:1333)
              at java.awt.font.TextLayout.fastInit(TextLayout.java:561)
              at java.awt.font.TextLayout.<init>(TextLayout.java:423)
              at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:1444)
              at t11.paint(t11.java:53)
              at java.awt.Component.dispatchEventImpl(Component.java:1873)
              at java.awt.Component.dispatchEvent(Component.java:1827)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:160)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:45)

      jim.hu@prc 1998-02-12

      Attachments

        Activity

          People

            busersunw Btplusnull User (Inactive)
            jhusunw Jim Hu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: