Subject: Building blocks of Chinese system, part II

From: Ng Liang Shing <[email-masked]>
Date: Sun, 25 Sep 1994 14:45:08 MYT

Building Blocks of Chinese Systems

part II

Chinese programs are examples of 'Two-window Model'. ASCII programs are
examples of 'One-window Model'. This argument applies to all Chinese programs
of both conventional and alternative architecture.

To illustrate what is meant by one-window model and two-window model, consider
an example of ASCII program and a Chinese program.

A Chinese program would have two windows presented to the users when it is
running. One is the main window. The other is the input window. For example,
when Eten is loaded, the input window appears at the bottom of the screen. The
remaining part of the screen is the main window. DOS prompt appears in the
main window, or when an application program like PE2 is run, PE2 occupies the
main window. In the input window, the current input method is indicated, e.g.
[Cangjie] or [ZhuYin] etc.

As constrast to a Chinese program, a ASCII program would only have one window,
which correspond to the main window of the Chinese program. ASCII programs do
not require an input window because input method in ASCII is trivial.

The same sort of windows appear in Chinese word processor like NJSTAR. At the
bottom of the screen is the input window, and the remaining part of the screen
is the main window, in which the text are displayed.

The same sort of windows also appears in Microsoft Windows environment. For
example, when Chinese Star is loaded, the input window appear at the bottom of
the screen, although in MS-Win, this windows can be moved around. In Chinese
MS-Windows, the input windows appear when Chinese input method is activated.
Although in MS-Win environment, there are many windows, but our terminology
'two-window model' refers to the current active main window and the input
window.

The two-window model also applies to non-keyboard input such as pen input. In
Eten, when the pen input is activated, the pen input window appears on the
screen.

We have shown that Chinese input mechanism is essentially more complicated
than ASCII input mechanism, which is indeed trivial. And we conclude that at
when input from an device is required for Chinese system, we need to have two
windows - the main window and the input window.

If we look at the history of object-oriented programming, we can say that the
development of OOP is indeed driven by the needs of windows environment.  The
structured programming techniques proved to be insufficient or inefficient for
windows environment, in which we need to deal with many windows of the same or
different types.  Each windows can be regarded as an object.  Types of windows
are pull down menu, dialog box, or the main window itself.

Although the original C language can be used for programming in a windows
environment, it is more efficient to use C++. It is possible to use structured
programming techniques to deal with two-window model, but it is more efficient
to use OOP to deal with two-window model. Hence for Chinese functions, it
would be more efficient to use OOP.

We shall consider three types of character input functions: getchar(),
getstring() and getpage(). getchar() gets a character. getstring() gets a
string of characters in one dimension or one direction (from left to right or
from top to bottom or from right to left), while getpage() gets a page of
characters in two directions. getstring() is built upon getchar() and
getpage() is built upon getstring().

Three parameters are required for getchar() in Chinese. They are a variable of
type Chinese character (16-bit wide or 32-bit wide) to hold the return value,
a handle to the main window, and a handle to the input window. For getstring()
and getpage(), sufficient storage space must be allocated for the returned
characters.

When the function getchar() is called, the input window is activated. Device
input (e.g. key stroke or pen input) is translated into Chinese character
code. The results are displayed in the input window, and the user is allowed
to decide or choose from a list of characters. e.g. If the input window is in
ZhuYin mode, usually a list of characters are listed and the user shall pick
one character. The result is stored in the allocated space, and the main
window is activated and the result is also displayed in the main window.

The size of the input window can vary depending on the input mode. In an Apple
Mac system for example, the input window is very large, consisting of up to
hundreds of characters when Pinyin method is used. Or for pen input, the input
window must be large enough to hold the bitmap. On the usual DOS or MS-Win
system, the input window is usually one long bar.

The psuedo code for getchar() would be,

getchar(char c, MainWin mw, InputWin iw)
{
....
iw.activate()
....
mw.activate()
....
return c
....
}

The properties of InputWin is hidden from getchar(), so is the properties of
MainWin. Programmers are free to write their own functions or methods for the
input windows and main windows, then 'plug' it into the getchar() functions.
This is only possible in OOP.

getstring() would consist of a loop while not end of line of getchar().
getpage() would consit of a loop while not end of page of getstring().

I hope I have given you some ideas of writing the Chinese input functions. I
have omitted the discussion of putchar() here, which is at a lower level. Also
omitted is the Chinese input dictionary look up algorithm. Any comments or
requests are welcome.

--
Ng Liang Shing            |   This is an Internet node host inside
Sungai Petani, Malaysia   |   an old 286.  A few years back, this place
[email-masked]          |   was not more than a small town.