unit Mprint;interfaceuses Printers, Types,windows,Classes,SysUtils,forms,Graphics,Dialogs;type TPrintSet = record Pheight, Pwidth, Tx, Ty, Txheight, Infox, Infoy, Infoheight: integer; end;function CharHeight: Word; //取得字符的高度 function AvgCharWidth: Word; //取得字符的平均宽度 function GetPhicalPaper: TPoint; //取得纸张的物理尺寸---单位:点 function PaperLogicSize: TPoint; //file:2.取得纸张的逻辑宽度--可打印区域 //file:取得纸张的逻辑尺寸 function HVLogincRatio: Extended;//file:纸张水平对垂直方向的纵横比例 function GetOffSetX: Integer; //file:取得纸张的横向偏移量-单位:点 function GetOffSetY: Integer; //file:取得纸张的纵向偏移量-单位:点 function MmToInch(Length: Extended): Extended; //file:毫米单位转换为英寸单位 function InchToMm(Length: Extended): Extended;//file:英寸单位转换为毫米单位 function HPointsPerInch: Integer; //file://取得水平方向每英寸打印机的点数 function VPointsPerInch: Integer; //file:取得纵向方向每英寸打印机的光栅数 function XPointToMm(Pos: Integer): Extended; //file:横向点单位转换为毫米单位 function YPointToMm(Pos: Integer): Extended; //file://纵向点单位转换为毫米单位 procedure SetPaperHeight(Value:integer); //file://设置纸张高度-单位:mm Procedure SetPaperWidth(Value:integer); //file://设置纸张宽度:单位--mm procedure PrintText(X, Y: Extended; Txt: string; FontName:string; FontType:TFontStyles; FontSize: Integer=12); //在 (Xmm, Ymm)处按指定配置文件信息和字体输出字符串
procedure DrawLine(BX,BY,EX,EY,LWeight:Integer);// 画直线var PrintSet: TPrintSet; psBool: boolean=False; implementation //取得字符的高度 function CharHeight: Word; var Metrics: TTextMetric; begin GetTextMetrics(Printer.Canvas.Handle,Metrics); Result := Metrics.tmHeight; end;//取得字符的平均宽度 function AvgCharWidth: Word; var Metrics: TTextMetric; begin GetTextMetrics(Printer.Canvas.Handle, Metrics); Result := Metrics.tmAveCharWidth; end;//file:取得纸张的物理尺寸---单位:点 function GetPhicalPaper: TPoint; var PageSize : TPoint; begin //file:PageSize.X; 纸张物理宽度-单位:点 //file:PageSize.Y; 纸张物理高度-单位:点 Escape(Printer.Handle, GETPHYSPAGESIZE, 0,nil,@PageSize); Result := PageSize; end;//file:2.取得纸张的逻辑宽度--可打印区域 //file:取得纸张的逻辑尺寸 function PaperLogicSize: TPoint; var APoint: TPoint; begin APoint.X := Printer.PageWidth; APoint.Y := Printer.PageHeight; Result := APoint; end;//file:纸张水平对垂直方向的纵横比例 function HVLogincRatio: Extended; var AP: TPoint; begin Ap := PaperLogicSize; Result := Ap.y/Ap.X; end;//file:取得纸张的横向偏移量-单位:点 function GetOffSetX: Integer; begin Result := GetDeviceCaps(Printer.Handle, PhysicalOffSetX);
end;//file:取得纸张的纵向偏移量-单位:点 function GetOffSetY: Integer; begin Result := GetDeviceCaps(Printer.Handle, PhysicalOffSetY); end;//file:毫米单位转换为英寸单位 function MmToInch(Length: Extended): Extended; begin Result := Length/25.4; end;//file:英寸单位转换为毫米单位 function InchToMm(Length: Extended): Extended; begin Result := Length*25.4; end;
TPrintSet = record
Pheight,
Pwidth,
Tx,
Ty,
Txheight,
Infox,
Infoy,
Infoheight: integer;
end;function CharHeight: Word; //取得字符的高度
function AvgCharWidth: Word; //取得字符的平均宽度
function GetPhicalPaper: TPoint; //取得纸张的物理尺寸---单位:点
function PaperLogicSize: TPoint; //file:2.取得纸张的逻辑宽度--可打印区域 //file:取得纸张的逻辑尺寸
function HVLogincRatio: Extended;//file:纸张水平对垂直方向的纵横比例
function GetOffSetX: Integer; //file:取得纸张的横向偏移量-单位:点
function GetOffSetY: Integer; //file:取得纸张的纵向偏移量-单位:点
function MmToInch(Length: Extended): Extended; //file:毫米单位转换为英寸单位
function InchToMm(Length: Extended): Extended;//file:英寸单位转换为毫米单位
function HPointsPerInch: Integer; //file://取得水平方向每英寸打印机的点数
function VPointsPerInch: Integer; //file:取得纵向方向每英寸打印机的光栅数
function XPointToMm(Pos: Integer): Extended; //file:横向点单位转换为毫米单位
function YPointToMm(Pos: Integer): Extended; //file://纵向点单位转换为毫米单位
procedure SetPaperHeight(Value:integer); //file://设置纸张高度-单位:mm
Procedure SetPaperWidth(Value:integer); //file://设置纸张宽度:单位--mm
procedure PrintText(X, Y: Extended; Txt: string;
FontName:string; FontType:TFontStyles; FontSize: Integer=12);
//在 (Xmm, Ymm)处按指定配置文件信息和字体输出字符串
PrintSet: TPrintSet;
psBool: boolean=False;
implementation
//取得字符的高度
function CharHeight: Word;
var Metrics: TTextMetric;
begin
GetTextMetrics(Printer.Canvas.Handle,Metrics);
Result := Metrics.tmHeight;
end;//取得字符的平均宽度
function AvgCharWidth: Word;
var
Metrics: TTextMetric;
begin
GetTextMetrics(Printer.Canvas.Handle, Metrics);
Result := Metrics.tmAveCharWidth;
end;//file:取得纸张的物理尺寸---单位:点
function GetPhicalPaper: TPoint;
var
PageSize : TPoint;
begin
//file:PageSize.X; 纸张物理宽度-单位:点
//file:PageSize.Y; 纸张物理高度-单位:点
Escape(Printer.Handle, GETPHYSPAGESIZE, 0,nil,@PageSize);
Result := PageSize;
end;//file:2.取得纸张的逻辑宽度--可打印区域
//file:取得纸张的逻辑尺寸
function PaperLogicSize: TPoint;
var
APoint: TPoint;
begin
APoint.X := Printer.PageWidth;
APoint.Y := Printer.PageHeight;
Result := APoint;
end;//file:纸张水平对垂直方向的纵横比例
function HVLogincRatio: Extended;
var
AP: TPoint;
begin
Ap := PaperLogicSize;
Result := Ap.y/Ap.X;
end;//file:取得纸张的横向偏移量-单位:点
function GetOffSetX: Integer;
begin
Result := GetDeviceCaps(Printer.Handle, PhysicalOffSetX);
end;//file:取得纸张的纵向偏移量-单位:点
function GetOffSetY: Integer;
begin
Result := GetDeviceCaps(Printer.Handle, PhysicalOffSetY);
end;//file:毫米单位转换为英寸单位
function MmToInch(Length: Extended): Extended;
begin
Result := Length/25.4;
end;//file:英寸单位转换为毫米单位
function InchToMm(Length: Extended): Extended;
begin
Result := Length*25.4;
end;