主题:《作图模式显示汉字》的扩展
谢谢jtchang老师提供的[url=http://www.programfan.com/club/showbbs.asp?id=14025]作图模式显示16×16汉字[/url]程序,但jtchang老师特别注明“内容必须全部为全角符号或者是汉字”。我想,能否可以让程序也能显示英文字母或是半角字符呢?我考虑过用 Outtext 过程,但Outtext是8×8点阵的,与16×16的汉字混合会不美观。于是我找到了“ASC16”这个 UCDOS 98 的16×8点阵西文字库。我使用它仿照jtchang老师的程序添加了显示西文的过程,并把程序做成了单元文件。以下是程序代码:
(* UCDOS 16*16 fonts unit.
Need file: HZK16 and ASC16 to run.
display Chinese in graphics mode.
programmed by jtchang.
improved by Ben.
*)
Unit Chinese;
interface
Uses Graph;
procedure OutChinese(x,y:integer;s:string;blank:integer);
implementation
function inttostr(n:integer):string;
var
s:string;
begin
s:='';
repeat
s:=chr(ord('0')+n mod 10)+s;
n:=n div 10;
until n=0;
inttostr:=s;
end;
procedure putone(x,y:integer;s:string);
type
chinesep=array[1..32] of byte;
var
a:chinesep;
f:file of chinesep;
i,j,x0,y0:integer;
k:byte;
q,w:longint;
color:byte;
begin
color:=getcolor;
q:=ord(s[1])-160;
w:=ord(s[2])-160;
q:=(q-1)*94+(w-1);
assign(f,'HZK16');
reset(f);
if (q<0) or (q>=filesize(f)) then
begin
close(f);
exit;
end;
seek(f,q);
read(f,a);
close(f);
y0:=y;
for i:=1 to 32 do
begin
k:=a[i];
if i mod 2=1 then
begin
x0:=7+x;
y0:=y0+1;
end
else
x0:=15+x;
for j:=1 to 8 do
begin
if k and 1 =1 then putpixel(x0,y0,color);
x0:=x0-1;
k:=k shr 1;
end;
end;
end;
(* UCDOS 16*16 fonts unit.
Need file: HZK16 and ASC16 to run.
display Chinese in graphics mode.
programmed by jtchang.
improved by Ben.
*)
Unit Chinese;
interface
Uses Graph;
procedure OutChinese(x,y:integer;s:string;blank:integer);
implementation
function inttostr(n:integer):string;
var
s:string;
begin
s:='';
repeat
s:=chr(ord('0')+n mod 10)+s;
n:=n div 10;
until n=0;
inttostr:=s;
end;
procedure putone(x,y:integer;s:string);
type
chinesep=array[1..32] of byte;
var
a:chinesep;
f:file of chinesep;
i,j,x0,y0:integer;
k:byte;
q,w:longint;
color:byte;
begin
color:=getcolor;
q:=ord(s[1])-160;
w:=ord(s[2])-160;
q:=(q-1)*94+(w-1);
assign(f,'HZK16');
reset(f);
if (q<0) or (q>=filesize(f)) then
begin
close(f);
exit;
end;
seek(f,q);
read(f,a);
close(f);
y0:=y;
for i:=1 to 32 do
begin
k:=a[i];
if i mod 2=1 then
begin
x0:=7+x;
y0:=y0+1;
end
else
x0:=15+x;
for j:=1 to 8 do
begin
if k and 1 =1 then putpixel(x0,y0,color);
x0:=x0-1;
k:=k shr 1;
end;
end;
end;