Subject: Q & A - Chinese Programming Basics

From: "L.S.Ng" <[email-masked]>
Date: Wed, 3 Nov 1993 16:49:07 GMT

I received over 20 responses and requests for the Q & A for Chinese
Programming Basics.

I am posting Part I - Coding and Accessing CCLIB.16 to CCNET-L.

(Part II - QBASIC source code for the Chinese printf() functions, and
its Q & A, will be posted later upon request. I have sample source code
for Displaying and Printing 16x16 bitmap both horizotally and
vertically. The principle for 24x24 bitmap is similar. 16x16 bitmap is
easy to handle and understand.)

I decided to post it to the CCNET for the following reasons:

1.  the whole document is about 300 lines, which is not very big.

2.  I wish to hear about comments and opinions from experts and seniors
in this fields.

3.  I hope to initiate discussion on this and other
related topics.

The document is included at the end of this mail. Note that my email
address was <[email-masked]> but I am at <[email-masked]> now.
So please mail me at <[email-masked]> for futher correspondence.

Thanks for your attention

Hope you enjoy it.

Sincerely
Liangsheng WU

------------------------------------------------------------
liang.1:
From:   IN%"[email-masked]"  8-AUG-1993 05:40:08.57
To:     IN%"[email-masked]"
CC:
Subj:   RE: Superset of codes

Glad to know you. I am Mr. WU3, Liang2sheng4.

> Would you please enlighten me about it, --- like recommending a book or so
> to me ?

I couldn't find a book on Chinese Programming in the market, perhaps becuase
it is too new. Sorry about that. But I am willing to share my idea via
correspondence.

Chinese Computing - the first step - how to write 'hello, world' in Chinese.

> BTW, I am a computational fluid dynamics major, and have some experience in
> graphics (animation & contouring) in C and Pascal.

Since you are a graphics programmer, this would be in fact not a problem at
all. You would learn about coding Chinese Characters and handling the Bitmap
fontfile plus turning the pixels on and off (the last part is your expertise).

> My first question, I guess, is to access the HZ library; --- or it is a
wrong question ?

Your first question - 'to access the HZ library' is a bit ambiguous :-) .
Please state your question more specifically.  Do you mean how to handle the
Bitmap fontfile of Chinese character?  Or do you mean what program should you
run to read HZ coded Chinese Characters?  (note:  HZ is a name for a Chinese
coding scheme)

I answer the question on handling the Bitmap fontfile.

I guess you are familiar with the mechanism of displaying ASCII character to
the screen. Basically a function such as 'printf()' is required. You pass a
string of ASCII code as the parameter. The function lookup a table of
ASCII bitmap fontfile and turn on/off the pixel of the screen to display the
character.

Of course, these are all transparent to novice programmers as the
English/American programmers had already done all the dirty job of bit/pixel
control etc.  for you.  But now, as for Chinese, no body has done this for
you, so you must start from scratch.  You must know about the coding, the
bitmap lookup and the pixel control.

To say 'no body has done this for you' is not exactly true.  I have done some
of this job for QBASIC - just to show how easy it is.  Hongbo Ni has written
more with Microsoft C.  You might need to rewrite for your platform.  So far,
no one that I know has done this for the Unix platform.  If you do that on
Unix, it would be the best. I suggest you write some Chinese characters in
your animation and contouring program, such as some words saying 'the results
is xxxx' etc and your name of course! The Englishman or American would be
amazed!

Please continue to write to me.

Sincerely
liangsheng wu

ps.  Please do not include my message in whole when replying.

--
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.
*********

liang.2:
From:   IN%"[email-masked]"  9-AUG-1993 11:59:36.09
To:     IN%"[email-masked]"
CC:
Subj:   RE: Superset of codes

> Sorry. I took HZ as *Chinese Character" when saying "HZ Library" (though
> vaguely know that it is some sort of coding), which I meant to be the
> library of the CC font files. So it should be CC library ???

I will explain about the HZ coding schemem later.

"Chinese Character library" is the correct term. "Font files" would mean the
same thing.

> By "accessing" CC library, I mean to call up a CC font file from say
> a C program, --- by providing the information the CC-lib needs such as
> the PinYin.

Yes you are asking a correct question accurately. I will explain the detail
mechanism - about Pinyin input method and others.

> Many questions here as you can imagine. First, how ? Second, do you
> "scratch" it *mannually*, by which I mean that you define a square of
> pixels, and turn on/off them according for each CC, or you first develope
> a tool (platform ??) and then "scratch" all the CC sort of standardly ?
> Third, how about the CC-lib; is there a shared CC-library, on which we
> can program directly, including rescale it ?

OK. Let's go back to our first question. How to say "hello, world" in Chinese.

1. you must have function similar to printf() that writes Chinese
Characters to the screen.

2. you have to build your own Chinese printf().

Now, we go one level deep into the question: how will the Chinese printf()
work?

1. it will take Chinese code as the parameter.

2. it will write Chinese characters to the screen.

Now, we identify that we need a Chinese Character library (cclib) i.e. the
fontfile. The fontfile defines the bitmap of each Chinese characters. By
reading the bitmap, we then turn on/off the pixels on the screen to display
the chinese characters.

To answer your question: is there a shared CC-library? Yes, there is. This can
be obtained by ftp various Chinese ftp site e.g.
ifcss.org:software/font/cclib.16

Try to get a cc-library file called cclib.16. There are many others. This is a
good place to start. Try investigating the file. e.g. size, structure etc. I
will explain more.

--
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.
********

liang.3:
From:   IN%"[email-masked]" 11-AUG-1993 06:15:03.60
To:     IN%"[email-masked]"
CC:     IN%"[email-masked]"  "Looi Wan Wah"
Subj:   RE: Superset of codes

To understand what is CCLIB.16, you can ftp
ifcss.org:/sofware/dos/editor/njs210-1.zip njs210-2.zip njs210-3.zip for
NJSTAR Wordprocessor version 2.1. Read the file GUOBIAO.DOC using NJStar.

CCLIB.16 is a fontfile consisting of symbols and 6763 Chinese Character.
All the characters can therefore be represented as a number. e.g. Character
no.1 is 'a symbol', character no. 1411 is 'a1' etc.

A clever scheme has be thought out to represent those characters: they are
grouped in a subgroup of 94 characters and there are 94 such subgroup. So
character no.1 'a symbol' is given the first character of the first group
whose code is 0101.  and character no 1411 'a1' is the 1st character of
subgroup no 16 hence is coded as 1601.

But why 94? This is how it is clever. There are 94 ordinary characters in the
ASCII character set (from ASCII 33 to ASCII 126). (The rest are control codes
ASCII 01-31, space 32, DEL 127).  So instead of writing 0101 and 2255 we
can code the character as two ASCII character so that 0101 becomse ASCII 33 +
ASCII 33 = !!  and 2255 becomes ASCII 32+16 + ASCII 32+1 = '0!'.

This is the coding scheme we are going to employ in the as the
parameter in printf() function. So we say printf("!!6W"); it means we want to
display the character 'a symbol' and 'a1'. So we do not need to write
printf(1,1411).

What are the advantages of this coding scheme instead of straight decimal
numbers?

liang

--
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.
********

liang.4:
From:   IN%"[email-masked]" 14-AUG-1993 14:03:22.10
To:     IN%"[email-masked]"
CC:     IN%"[email-masked]"  "Looi Wan Wah"
Subj:   RE: Superset of codes

char no.1 is coded as 0101. To convert 0101 to 1 the formula is
(01-1)*94 + 1=1. i.e. a character coded as AABB correspond to
(AA-1)*94 + BB. Hence 1601 -> (16-1)*94+1 = 1411.

The coding scheme we discussed so far is also called Hz coding scheme. The
Guobiao coding scheme is similar. The difference is that it employs the upper
128 characters of ASCII. i.e. For 1601 the ASCII code equivalent is
(128+32+16, 128+32+1) => (176,161) [in Hz it is (48,33).] Also, a name is
given to the coding scheme 1601 - Quwei, though this is not implemented
directly.

Here is a summary of the coding schemes we discussed:

Character number 1411 in cclib:

QuWei: 1601   (first character subgroup no 16, format AABB, AA=subgroup
               number=Qu in Chinese, BB=position in a subgroup=Wei in Chinese
               hence the name QUWEI)

Hz:   (48,33)="0!"   (X,Y): X,Y=ascii value of the character
GB:  (176,161)="(non-printable in email)" [note:  this is an disadvantage of
                                            GB ]

The file cclib.16 that comes with NJStar and the cclib.16 that you ftp has the
following structure:
every 32 bytes defines one character. You should divide the file size by 32 to
get the number of characters. Note that they are different. Further, divide
the number of characters by 94 to obtain the number of subgroups.

For each characters, every two bytes defines one row of pixels (there are 16
pixels in one row), there are 16 rows in total.  The values of the two bytes
represent the binary value that turns on/off the corresponding pixels in a
row.  e.g. Say you read two bytes each time. The first byte is HEX FF and
the second byte is HEX 0F, then the pixel pattern should be

XXXXXXXX____XXXX
 F   F   0   F

Q: What is the pixel pattern of HEX ABCD?
(Answer: X_X_X_XXXX__XX_X ), note: X_X_ = 1010 (binary) = HEX A = DEC 10

I shall talk about the Pinyin dictionary later. As for now, please be
convinced that cclib is only a set of graphic fonts and contain no more
information than that.

You should now have gathered enough information to write printf(). However,
there are some quirks in the CCLIB.16 file which I shall discuss later.

(clue:  note the different number of subgroups in NJStar CCLIB.16 and cclib.16
in /software/fonts. How many subgroups are there in each case? How many
subgroups are for Chinese characters? How many subgroups are for symbols?)

liang
--
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.
**************

liang.5:
From:   IN%"[email-masked]" 16-AUG-1993 13:31:02.52
To:     IN%"[email-masked]"
CC:
Subj:   RE: cclib

> 1. I edited the HZ file of " home-letter of mine written by NJSTAR before.
>    It was started with "Ba4 Ba4 Ma1 Ma1", i.e., 爸爸妈妈 in HZ. I
>    changed it into 爸妈, and it then became "Ba4 Ma1:". --- It is
>    amazing for me.

Excellent. Note that the Hz code must be enclosed in tilde+curlie-brackets.

>
> 2. I have also typed (using the DOS _type_) both GUOBIAO.DOC and QUWEIMA.DOC,
>    just to look at the "up ASCII" characters. I also translated them into the
>    readable HZ, and it then came to my attention that their HZ sizes are
>    about doubled. Does this mean that the font size of the up-ASCII
>    a character is about half of a "low" one ?

Note that the Hz code is enclosed in tilde+curlie-bracket. The
tilde+curlie-bracket pairs adds up the extra size.

>
> >Q: What is the pixel pattern of HEX ABCD?
> >(Answer: X_X_X_XXXXX__XX_X ), note: X_X_ = 1010 (binary) = HEX A = DEC 10
>                 ^^^^^

Sorry. It's my silly mistake. Thanks for spotting it.

> Sorry for my repeated asking about PinYin. I was just trying to draw as
> much as I can info from your mail. In future, whenever you find a question of
> mine improper, put it aside.

Now we talk about CCLIB. When we're finished with this soon, we will talk
about Dictionary (for Input).

The difference between NJstar CCLIB.16 AND others.

NJSTAR CCLIB.16: 246656 bytes
Standard CCLIB.16: 237632 bytes

The Standard CCLIB.16 has 72 subgroups of Chinese Char and 7 subgroups of
symbols (marks and letters). (read Guobiao.doc note at the beginning)

NJStar CCLIB.16 has 73 subgroups of Chinese Char and 9 subgroups of symbols.
The extra subgroups in NJStar CCLIB.16 are subgroup no. 8,9 and 15. This means
that NJStar CCLIB.16 has extra symbols and Chinese Char. But they are
non-standard, according to the standard defined in Guobiao2312-80. This means
that those characters are not guanranteed for support by other Chinese
softwares.

Now let me explain what I mean by 'quirk'. Now you know that the first Chinese
Character 'a1' is coded as 1601 (quwei). However, it's absolute position in
the CCLIB.16 is immediately after the symbols. Hence, in standard CCLIB.16, it
is 7 subgroups x 94 char per subgroup x 32 bytes per char + 1 = byte no 21057
In NJStar, it is, however, immediately after the symbols (subgroup 1 to 9)
plus the extra Chinese char subgroup (subgroup 15), i.e. its absolute position
is therefore 10 x 94 x 32 + 1 = 30081 byte.

The quirk or discontinuity occurs only at one place, luckily. So when you
build printf(), you must consider the absolute starting position of the
charater you wish to access.

Q: Is there a formula to cater for the two CCLIB.16 despite their difference?
(clue: there are only 72 subgroups of standard Chinese char, and they are
placed after the symbols. Note also the CCLIB has only two parts: the symbols
[7 subgroups] and Characters[72 subgroups].)

If you have no further questions, I will send you a sample print() function
written in QBASIC. I hope you can build it for 'C' for DOS and Windows and for
Unix.

Note: all symbols and characters have the same size i.e. 16x16 pixels or 32
bytes.

--
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.
**************