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

Graphics failed to display Japanese strings

    XMLWordPrintable

Details

    • b01
    • x86
    • windows_nt
    • Verified

    Description

      Run attached code, you will find JDK1.1.3 failed to display Japanese or
      any other no-english language string by using Graphics.drawString().

      You'd better take a look of
      AwtGraphics::DrawSubstringWidth() at /src/win32/sun/windows/awt_Graphics.cpp.


      import java.awt.*;
      import java.io.PrintStream;

      public class sample {
      static String hexConst = "0123456789ABCDEF";

              public static void main( String[] args ) {
                      createa();
              }

      static private String getString(int higher) {
      char charr[];
      String css;

      charr = new char[8];

      for(int j = 0; j < 8; j++) {
      charr[j] = (char)(higher + j);
      //charr[j * 2 + 1] = ' ';
      }
      return new String(charr);
      }

              static void createa () {

                      Frame a=new Frame("Test");
      TestLabel tl = new TestLabel();
      TestCanvas tc = new TestCanvas();
                      a.setLayout(new BorderLayout());
                      //a.add("Center", new TextArea(getString(0x3000)));
      tc.setSize(100, 100);
      tc.setText(getString(0x8000));
                      a.add("Center", tc);

                      a.add("North", new Button(getString(0x8000)));

      tl.setText("abcdefg"); //getString(0x8000));
      a.add("South", tl);
                      //a.add("North", new Button("Ë̵þ"));
      a.pack();
                      a.show();
              }
      }

      class TestLabel extends Label{
              public static String itsName() { return "Label"; }
      String s;
              public TestLabel() {
                      super("");
              }
              public void setText(String st) {
                      s = new String(st);
                      repaint();
              }
              public void paint(Graphics g) {
                      g.drawString(s, 0, 20);
              }

      }

      class TestCanvas extends Canvas {
              public static String itsName() { return "Graphics.drawString"; }
              String s;
              public TestCanvas() {
                      super();
              }
              public void setText(String st) {
                      s = new String(st);
                      repaint();
              }
              public void paint(Graphics g) {
                      g.drawString(s, 0, 20);
              }
      }

      Attachments

        Activity

          People

            sherman Xueming Shen
            sherman Xueming Shen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: