JDK-4096232 : Chinese characters not drawn correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt:i18n
  • Affected Version: 1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-12-02
  • Updated: 1998-03-19
  • Resolved: 1998-03-19
Related Reports
Duplicate :  
Description

Name: joT67522			Date: 12/01/97


1. Steps to reproduce the problem:
   * Compile the following applet called "bug"
   * Run it with appletviewer (bug.html also attached)
   * All the Chinese strings are the two characters string
     "four" followed by "up".  Notice that while
     button, choice and Graphics.drawString draw
     the second character correctly and miss the first
     character, text area draws the first character
     correctly and misses the second character.

2, source code
==== file bug.java ====
import java.awt.*;
import java.applet.*;

public class bug extends Applet {
   // a two-character Chinese string, "four" and "up", in Unicode
  String ChineseString = "\u00a5|\u4e0a";

  public void init() {
    setLayout(null);

    setBackground(Color.lightGray);
    Choice choice = new Choice();
    choice.setBounds(0,0,100,20);
    choice.addItem(ChineseString);
    add(choice);

    Button button = new Button(ChineseString);
    button.setBounds(0,21,100,20);
    add(button);

    TextArea textArea = new TextArea();
    textArea.setText(ChineseString);
    textArea.setBounds(0,41, 200,40);
    add(textArea);

    MyComponent myComponent = new MyComponent();
    myComponent.setBounds(101,0, 100,40);
    add(myComponent);
  }

  // MyComponent is a light-weight component whose only purpose is to
  // exercise Graphics.drawString  
  class MyComponent extends Component {
    public void paint(Graphics g) {
      g.drawString(ChineseString, 20,20);
    }
  }
}
==== file bug.html ====
<head><title>bug</title></head>
<body><applet code="bug.class" width = 200 height=80></applet>/body>

3. there were no error messages
4. there were no trace infomation
5. I'm using US English NT 4.0 with Chinese fonts 
   installed from the Microsoft NT CD's langpak
   directory.  My fonts.properties is a copy
   of font.properties.zh_TW as per instructions
   of the JDK doc.  My NT has service pack 3 installed
   complete with the latest Microsoft "hot fix"
   for service pack 3.



(Review ID: 20135)
======================================================================

Comments
WORK AROUND Name: joT67522 Date: 12/01/97 [email from the user. Joon] I have narrowed this bug down to this: AWT text area is not capable of displaying Chinese characters when the Chinese characters are encoded in Unicode. It works when the characters are encoded in Big5. So the workaround is to convert Unicode encoded Chinese characters to Big5 before asking the text area to display them. The following is an example of such a wrapper around java.awt.TextArea: // Copyright (c) 1997 Kam Tsang All Rights Reserved. import java.awt.*; import java.io.*; public class ChineseTextArea extends TextArea { private String patchedString(String s) { int slen = s.length(); String ans = ""; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(slen); try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream,"Big5"); try { outputStreamWriter.write(s, 0, slen); outputStreamWriter.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); //System.err.println("bytes is " + bytes.length); try { BufferedReader bufferedReader = (new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes),"8859_1"))); while ((s = bufferedReader.readLine()) != null) ans = s + "\n"; //System.err.println("s is " + s); } catch (java.io.IOException e) { System.err.println(e); } } catch (java.io.IOException e) { System.err.println(e); } } catch (java.io.UnsupportedEncodingException e) { System.err.println(e); } return ans; } public synchronized void setText(String s) { super.setText(patchedString(s)); } public synchronized void append(String s) { super.append(patchedString(s)); } public synchronized void insert(String s, int pos) { super.insert(patchedString(s), pos); } public synchronized void replaceRange(String s, int start, int end) { super.replaceRange(patchedString(s), start, end); } } ======================================================================
11-06-2004

PUBLIC COMMENTS this is a duplicate bug
10-06-2004

EVALUATION shanmugam.senthil@Eng 1998-02-23 This problem has been fixed in JDK1.1.6 and has surfaced in JDK1.2Beta3.
23-02-1998