(2)、打印位置的确定:由于组件是以图形方式进行打印,这就使得我们可以精确指向打印文件的输出位置,以便于进行对某些票据的套打。但这样就产生一个问题,我们是以打印的像素位置指定输入位置,还是以打印尺寸来指定位置。显然,利用像素来输出打印位置,对于编制程序来说是比较方便的。但由于一般用户对像素的概念并不理解,因此会带来使用上的困难;而且每一种打印机的分辩率是不一样的,因此,会出现在不同打印机上打印的效果不一样的问题。而以打印尺寸来指定位置并在程序中妥善加以处理就不会有上面的问题。具体的处理方法是,由用户输入尺寸位置。然后,在打印时,首先取得当前打印机的分辩率(注意:分辨率是以每英寸多少像素为单位的),再计算得出实际输入的像素位置后进行打印,这样就可以使得组件更加实用,而且,保持打印幅面的一致。具体的函数如下。 function tprttest3.mmtoprintpixel(inputpoint:tpoint):tpoint; begin result.x:=mmtoprintpixelx(inputpoint.x); result.y:=mmtoprintpixely(inputpoint.y); end; function tprttest3.mmtoprintpixelx(inputx:integer):integer; begin if queryprintlogpixel then begin pddix:=getdevicecaps(printer.handle,logpixelsx); pddiy:=getdevicecaps(printer.handle,logpixelsy); queryprintlogpixel:=false; end; result:=trunc(inputx/253.8*pddix+0.5); end; function tprttest3.mmtoprintpixely(inputy:integer):integer; begin if queryprintlogpixel then begin pddix:=getdevicecaps(printer.handle,logpixelsx); pddiy:=getdevicecaps(printer.handle,logpixelsy); queryprintlogpixel:=false; end; result:=trunc(inputy/253.8*pddiy+0.5); end; getdevicecaps:为windows系统中取得指定设备信息的函数。函数的原型如下 int getdevicecaps( hdc hdc, // 设置的句柄 int nindex // 查询的设备参数。 ); 其中,hdc为想要查询的打印机的句柄,logpixelsx、logpixelsy表示要查询的内容是打印机横向、纵向的每英寸的像素点数。 Delphi开发WEB应用程序打印组件(5)
|