LazStats: Fix text printer margins to be in mm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7858 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-11-11 10:06:21 +00:00
parent 85fe20453e
commit 793e8a0afa

View File

@ -49,10 +49,12 @@ uses
Globals; Globals;
const const
LEFT_MARGIN = 200; LEFT_MARGIN = 20; // mm
RIGHT_MARGIN = 200; RIGHT_MARGIN = 20;
TOP_MARGIN = 150; TOP_MARGIN = 15;
BOTTOM_MARGIN = 200; BOTTOM_MARGIN = 20;
INCH = 25.4; // 1 inch in mm
constructor TReportFrame.Create(AOwner: TComponent); constructor TReportFrame.Create(AOwner: TComponent);
@ -117,13 +119,18 @@ var
pageNo: Integer; pageNo: Integer;
oldFontSize: Integer; oldFontSize: Integer;
h: Integer; h: Integer;
leftMM, rightMM, topMM, bottomMM: Integer;
begin begin
with Printer do with Printer do
begin begin
x := LEFT_MARGIN; leftMM := round(LEFT_MARGIN / INCH * XDpi);
FPrintY := TOP_MARGIN; rightMM := round(RIGHT_MARGIN / INCH * XDpi);
xMax := PaperSize.Width - RIGHT_MARGIN; topMM := round(TOP_MARGIN / INCH * YDpi);
yMax := PaperSize.Height - BOTTOM_MARGIN; bottomMM := round(BOTTOM_MARGIN / INCH * YDpi);
x := leftMM;
FPrintY := topMM;
xMax := PaperSize.Width - rightMM;
yMax := PaperSize.Height - bottomMM;
pageNo := 1; pageNo := 1;
try try
Canvas.Brush.Style := bsClear; // no text background color Canvas.Brush.Style := bsClear; // no text background color
@ -133,12 +140,12 @@ begin
oldFontSize := Canvas.Font.Size; oldFontSize := Canvas.Font.Size;
for i:=0 to ReportMemo.Lines.Count-1 do begin for i:=0 to ReportMemo.Lines.Count-1 do begin
// Print page number // Print page number
if FPrintY = TOP_MARGIN then begin if FPrintY = topMM then begin
Canvas.Font.Size := 10; Canvas.Font.Size := 10;
h := Canvas.TextHeight('Page 9') + 4; h := Canvas.TextHeight('Page 9') + 4;
Canvas.TextOut(x+1, FPrintY, 'Page ' + IntToStr(PageNo)); Canvas.TextOut(x+1, FPrintY, 'Page ' + IntToStr(PageNo));
Canvas.Pen.Width := 3; Canvas.Pen.Width := 3;
Canvas.Line(LEFT_MARGIN, FPrintY+h, xmax, FPrintY+h); Canvas.Line(leftMM, FPrintY+h, xMax, FPrintY+h);
inc(FPrintY, 2*h); inc(FPrintY, 2*h);
Canvas.Font.Size := oldFontSize; Canvas.Font.Size := oldFontSize;
end; end;
@ -146,7 +153,7 @@ begin
inc(FPrintY, Canvas.TextHeight('Tg')); inc(FPrintY, Canvas.TextHeight('Tg'));
if FPrintY > yMax then begin if FPrintY > yMax then begin
NewPage; NewPage;
FPrintY := TOP_MARGIN; FPrintY := topMM;
inc(PageNo); inc(PageNo);
end; end;
end; end;