OSDN Git Service
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>