Subject: Chinese fonts

From: Cheng-yeh Yen <[email-masked]>
Date: Mon, 14 Sep 1992 23:31:23 EDT

Hi,

    I don't know much about GB code and cclib.16.  But I know something
about Big-5 code and some Font file structure.

    Big-5 code use 2 bytes to present a Chinese character.  The range of
each byte is :
    High Byte : A1-FE
		8E-A0
		81-8D
    Low  Byte : 40-7E
		A1-FE
So, the normal Chinese fonts should start from A140.  But there are some
different types of fonts :
    Special  fonts : A140 - A38E	 408 characters
		     A3C0 - A3E0
    Standard fonts : A440 - C67E	5401 fundamental characters
		     C940 - F9D5	7652 characters
Normally we start from A440 ( _yi1_ "one" ).  Some Chinese system (like
ETen) put Chinese font in this order.  Below are two programs which can
transfer the "order" to big5 code and vice versa.

ToBig5( n, k1, k2 )
int	      n;
unsigned char *k1, *k2;
{
  *k1 = *k2 = 0;
  if( n>=0 && n<13094 ) {
    if( n>=5401 )  n+=408;
    *k1=n/157+164;
    *k2=n%157+64;
    if( *k2>=63+64 )  *k2+=34;
  }
}

FromBig5( n, k1, k2 )
int	      *n;
unsigned char k1, k2;
{
  int  n1, n2;

  if( k1>=164 ) {
    n1=k1-164;
    n2=k2-64;
    if( k2>=161 )  n2-=34;
    *n=n1*157+n2;
    if( *n>=5401 )  *n-=408;
  }
}

    After you have the "order" of the character, you can get it's bitmap
from the font files.  ETen system use 16x15 fonts, so each character is
30 bytes.  You can also get 24x24 fonts, and each character is 72 bytes.
Below is a small program to show the Chinese fonts under X-window.  This
program use XDrawPoints only.  If you like, you can use pixmap to do it.
You can use the same technique to show it on PC screen.  You can use
BIOS call : int 10h, function 10h (or 12h, I don't remember) to do it.
If you want the fastest speed, you can access video memory directly (start
from A0000h for VGA).

unsigned char font[13094][30];
unsigned char bit[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };

xDrawCFont( n, x, y )
int  n, x, y;
{
  int	 i, j, k;
  XPoint xp[240];

  for( k=i=0; i<15; ++i ) {
    for( j=0; j<8; ++j )		  /*  First Byte   */
      if( font[n][i*2] & bit[j] )
	xp[k].x=x+j,  xp[k++].y=y+i;
    for( j=0; j<8; ++j )		  /*  Second Byte  */
      if( font[n][i*2+1] & bit[j] )
	xp[k].x=x+j+8,	xp[k++].y=y+i;
  }
  XDrawPoints(mydisp,mywin,mygc,xp,k,CoordModeOrigin);
}

----------------------------------------------------------------------
Cheng-yeh Yen                               [email-masked]
Dept. of Electrical Engineering
The Ohio State University                               679 Dreese Lab
2015 Neil Avenue                                     TEL:(614)292-6176
Columbus, OH 43210                                   FAX:(614)292-7596