字符画软件的四个关键技术
第一个关键技术:汉字库读取技术
使用汉字库技术可以做到和操作系统无关性,我们先了解一下点阵字库的基本原理
如下所示,下面是一个“字”的点阵图,在16点阵字库中一个汉字为16x16点,每一行使用两个字节表示,如下面示例第一行的十六进制为:0x02和0x00,所以,一个汉字在16点阵字库中需要占用2x16个字节,24点阵字库需要3x24个字节,下面我们仅以16点阵字库为例,其他点阵类似。
██████ █████████
███████ ████████
██ ██
██ ██████████ ██
█ ██████████ ███
███ █████
█████████ ██████
████████ ███████
███████ █████ ██
█
███████ ████████
███████ ████████
███████ ████████
███████ ████████
█████ █ ████████
██████ █████████
下面的函数返回指定字符串的字符画文本
function get16(const aword,aforeground,abackground:string):string;
function getbit(const c,n:byte):integer;
begin
result:=(c shr n) and 1;
end;
var
ilen :integer;
ifilesize :integer;
s :string;
k,l,i,p :integer;
cw:array[0..31] of char;
qu_ma,wei_ma:integer;
file16 :file;
begin
ilen:=length(aword);
assignfile(file16,piprograminfo.path+'hzk16');
filemode := fmopenread;
try
reset(file16,1);
finally
filemode:=fmopenreadwrite;
end;
ifilesize:=filesize(file16);
try
for l:=1 to ilen div 2 do
begin
k:=l*2-1;
// 如果不是汉字,往前进一位
while k<=ilen do
begin
if bytetype(aword,k)=mbleadbyte then break;
inc(k);
end;
if k>ilen then break;
if ((ord(aword[k]) and $80)<>0) then
begin
qu_ma:=ord(aword[k])-161;
wei_ma:=ord(aword[k+1])-161;
if (94*qu_ma+wei_ma)*32+32>ifilesize then continue;
try
seek(file16,(94*qu_ma+wei_ma)*32);
except
mymessagebox('fseek call fail!');
exit;
end;
blockread(file16,cw,32);
for i:=0 to 15 do
begin
for p:=7 downto 0 do
begin
if getbit(ord(cw[i*2]),p)=1 then s:=s+aforeground