OSDN Git Service

Add a transcript backing store suitable for Unicode text
authorSteven Luo <steven+android@steven676.net>
Sat, 1 Oct 2011 05:48:23 +0000 (22:48 -0700)
committerJack Palevich <jack.palevich@gmail.com>
Sun, 9 Oct 2011 20:18:57 +0000 (13:18 -0700)
commit7117c41e8bfc2165009b8a3688fecbaaac036f6e
tree063176e6026c49e50c94585dde15db9b1955d068
parentb87fd19e39bffbc834ab2f7608d8e450473220ea
Add a transcript backing store suitable for Unicode text

Storing Unicode text in a form suitable for a terminal emulator poses
several challenges:

* In Java's native UTF-16 encoding, some Unicode code points (those
  outside the Basic Multilingual Plane) require two chars to express.
* The use of combining characters means that it's possible for the
  character displayed in one column/screen position to require several
  Unicode code points to express.
* Some Unicode code points (particularly East Asian wide characters,
  which include all of the CJK ideographs) take up two columns/screen
  positions.

The UnicodeTranscript class is designed to make the operations we need
most frequently -- storing a character to a particular screen position,
and getting all or part of a line -- as fast as possible.  The design
uses an array of two types of lines: "basic", which is just an array of
char[], and is used to store a line as long as it has no combining
characters, wide characters, or non-BMP characters; and "full", which is
an array of char[] together with an array of offsets allowing us to
easily find a particular column in the line.  Basic lines in the
transcript are automatically converted to full lines as needed.
Color/formatting information and line wrapping information are stored in
separate arrays.

We also expose a static method, charWidth(), which returns the number of
columns/screen positions that a particular Unicode code point will use.
This information is needed by other parts of the emulator to correctly
handle Unicode.

Correct support for East Asian wide characters requires Android 2.2 or
later -- 2.2 introduced a getEastAsianWidth() method, which we use to
determine the width of a character.  On older platforms, we just pretend
all characters which aren't combining or control characters have width
1.

Signed-off-by: Jack Palevich <jack.palevich@gmail.com>
src/jackpal/androidterm/util/UnicodeTranscript.java [new file with mode: 0644]