Subject: Displaying Chinese Characters: QBASIC Sourcecode

From: "L.S.Ng" <[email-masked]>
Date: Sun, 16 May 1993 14:22:31 BST

'DAZI.BAS
'Display a string of Chinese characters, vertically or horizontally
'by Liangsheng Wu, Southampton UK
'last modified 16 May 93
'
'before running check "cclib.16"

DECLARE SUB daz (x, y, a$) ' print vertically, da3zhi2, at coordinate x,y
DECLARE SUB dah (x, y, a$) ' print horizontally, da3heng2

OPTION BASE 0
DIM SHARED p%(0 TO 641) 'display buffer
'p% = a buffer to store the bitmap of a string of characters to be displayed
'each char is 16x16 bitmap => 16 bits per scan line, 16 scan lines(rows)
'so requires 2 bytes per scan line = 32 bytes or 16 integer for each char
'p% has the type of integer, so each element can hold 16bits of bitmap
'   i.e. each element in p% can hold one row of one char
'use PUT to display the buffer
'the first two elements in the array define the horizontal and vertical
'    size of the picture to be displayed.
'first = no of bits per scan line, since 1 bit = 1 pixel, hence 16 bits.
         i.e. width of the picture
'second = no of scan lines i.e. height of the picture
'The rest of the array are the bitmap info of each character
'We use VGA 640x480. max character = 640/16 = 40 per line
'so size of p% = 2 + 40 x 16 = 642, takes 0,1,2,...,641
'
'Let's call the third element in the display buffer p
'the first data element (the first two reserved
'for width and height definitions)
'
'Vertical case:
'the 1st data element (1de) = the first row of pixel of the first char
'                      2de  = the 2nd row of pixel of the 1st char
'                     16de  = 16th row of 1st char
'                     17de  = 1st row of 2nd char
'         {[(n-1)x16]+1}de  = 1st row of (n)th char
'         {[(n-1)x16]+k}de  = (k)th row of (n)th char
'......
'Horizotal case:
' 1de = 1st row of pixel of 1st char
' 2de = 1st row of pixel of 2nd char
' 3de = 1st row of pixel of 3rd char
' suppose it's a string of n char
' (n)de = 1st row of (n)th char
' (n+1)de = 2nd row of 1st char
' (n+2)de = 2nd row of 2nd char
' (2n+1)de = 3rd row of 1st char
' (2n+2)de = 3rd row of 2nd char
' [(k-1)n+1]de = (k)th row of 1st char
' [(k-1)n+m]de = (k)th row of (m)th char
'...

DIM SHARED kq

SCREEN 11: CLS

OPEN "c:\njstar\cclib.16" FOR BINARY AS #1
cc = LOF(1) / 32 - 6768: kq = 1410 - cc
'cc is the starting point in the cclib.16 of the Chinese Characters.
'in front of them are all symbols

dah 100, 100, "^{C@@v5D9CDo^}"
'this program uses HZ encoding

daz 100, 120, "^{DcTZ:N7=^}"

CLOSE
END

'bugs: this program would not display symbols.

'CCLIB.16
'CCLIB.16 is the 16x16 bitmap library of all Chinese Characters and Symbols.
'Every char/symbol occupy 32 bytes. The size is therefore the total number
'of Chinese Char (6768) plus the number of symbols (varies for different
'version of CCLIB.16). Typically 237632 or 2466656.
'use archie to search for CCLIB.16.
'ftp from ifcss.org or cnd.org/software/font
'for Fantizi, CCLIBF.16
'
'Please feel free to modify/distribute this program in the spirit
'of promoting the understanding of Chinese Computing
'and perhaps educating/training more capable young Chinese programmmers.
'
'('A Chinese Programmer' does not mean that he/she is an ethnic Chinese,
' rather he/she is doing computer programming related to Chinese Language)
'To phrase in Chinese, Chinese Programmer = ZhongWen Bian3 Cheng2 Shi1
,                      NOT Zhongguoren/Huaren Bianchengshi

SUB dah (x, y, a$)
l = LEN(a$)
FOR j = 1 TO l STEP 2
hb = ASC(MID$(a$, j, 1))
lb = ASC(MID$(a$, j + 1, 1))
n = ((hb - &H21) * 94 + (lb - &H21) - kq) * 32! + 1
FOR i = n TO n + 31 STEP 2
GET #1, i, a%
s = i - n
p%(s * l \ 4 + j \ 2 + 1) = a%
NEXT
NEXT
p%(0) = &H8 * l: p%(1) = &H10
PUT (x, y), p%
END SUB

SUB daz (x, y, a$)
l = LEN(a$)
FOR j = 1 TO l STEP 2
hb = ASC(MID$(a$, j, 1))
lb = ASC(MID$(a$, j + 1, 1))
n = ((hb - &H21) * 94 + (lb - &H21) - kq) * 32! + 1
FOR i = n TO n + 31 STEP 2
GET #1, i, a%
s = (i - n) \ 2 + 2
p%(s + (j \ 2) * 16) = a%
NEXT
NEXT
p%(0) = &H10: p%(1) = &H8 * l
PUT (x, y), p%'PUT can be accelerate for vertical matrix
END SUB