请教:文本打印问题!!!!!

neighborgirl 2003-05-23 10:30:01
我用以下的程序段打印文件(文件内容已存到文件流telsm中)。在不同的打印机上打印输出的效果不一样,有时打印出来的内容往左偏了,有时又右偏了。想必是打印机分辨率不同的缘故,但不知道该如何解决。恳请各位高手多多指教!
procedure Tfilewin.printtel;
var
ss: string;
c: char;
cr,pg: byte;
wide,heigth: byte;
pp,p: boolean;
i,j,k,l,m,ln: integer;
xx,yy,x,y: integer;
begin
ln:=0;
j:=20;
xx:=20;
pg:=1;
pp:=false;

while not pp do
begin
begin
printer.begindoc;
y:=printer.pageheight;
x:=printer.pagewidth;
printer.canvas.font.color:=clblack;
printer.canvas.font.name:='黑体';
printer.canvas.font.size:=26;

ss:='文 件 内 容 ';
yy:=50;
i:=(x-printer.canvas.textwidth(ss))div 2;
k:=printer.canvas.textheight(ss);
printer.canvas.textout(i,yy,ss);

printer.canvas.font.size:=12;
yy:=k+50+yy;
printer.canvas.moveto(xx,yy);
printer.canvas.lineto(x-20,yy);

wide:=printer.canvas.textwidth('a');
heigth:=printer.canvas.textheight('a');
k:=heigth+j;

m:=y-100;
ss:='第 '+inttostr(pg)+' 页';
i:=(x-printer.canvas.textwidth(ss))div 2;
printer.canvas.textout(i,m,ss);

m:=m-j;
printer.canvas.moveto(xx,m);
printer.canvas.lineto(x-20,m);

if pg=1 then telsm.position:=0;
if pg>1 then telsm.position:=ln;
yy:=yy+j;
printer.canvas.moveto(xx,yy);

ss:=' ';
p:=false;

yy:=yy+j;

while (telsm.position<>telsm.size)and(not p) do //文件流telsm中存放文件的内容
begin
if telsm.read(c,1)<>0 then
begin
cr:=ord(c)and($80);
l:=x-wide*2-40;
if cr=$80 then
begin
i:=printer.canvas.textwidth(ss)+wide*2;
if i<=l then
begin
ss:=ss+c;
telsm.read(c,1);
ss:=ss+c;
end;
if i>l then
begin
printer.canvas.textout(xx,yy,ss);
yy:=yy+k;
if yy>m-k then
begin
pg:=pg+1;
ln:=telsm.position-1;
p:=true;
end
else
begin
ss:=' '+c;
telsm.read(c,1);
ss:=ss+c;
end;
end;
end;

if cr=0 then
begin
i:=printer.canvas.textwidth(ss)+wide;
if (c=#13)and(ss<>' ') then
begin
printer.canvas.textout(xx,yy,ss);
yy:=yy+k;
if yy>m-k then
begin
pg:=pg+1;
ln:=telsm.position;
p:=true;
end
else ss:=' ';
end;
if (c<>#13)and(c<>#10) then
begin
if i<=l then ss:=ss+c;
if i>l then
begin
printer.canvas.textout(xx,yy,ss);
yy:=yy+k;
if yy>m-k then
begin
pg:=pg+1;
ln:=telsm.position-1;
p:=true;
end
else ss:=' '+c;
end;
end;
end;
end;
end;

if not p then
begin
pp:=true;
if ss<>' ' then printer.canvas.textout(xx,yy,ss);
end;
printer.enddoc;
end;
end;
telsm.free;
end;
...全文
54 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fyje 2003-05-23
  • 打赏
  • 举报
回复
这么长啊,up

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧