GridPrinter: Fix TsWorksheetGrid scaling in preview/printout.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8627 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-11-16 23:02:24 +00:00
parent 3a6f3503fe
commit 42eccf22b7

View File

@ -39,6 +39,7 @@ type
ACanvas: TCanvas; ACol, ARow: Integer; ARect: TRect);
private
FGridCanvas: TCanvas;
FOldZoomFactor: Double;
FOldPadding: Integer;
FNewPadding: Integer;
@ -67,23 +68,15 @@ begin
sWorkbookSource1.LoadFromSpreadsheetFile(ParamStr(1));
end;
procedure TMainForm.GridPrinter1AfterPrint(Sender: TObject);
begin
sWorksheetGrid1.Canvas := FGridCanvas;
varCellPadding := FOldPadding;
// Restore drawing of the grid lines by the grid printer.
GridPrinter1.Options := GridPrinter1.Options + [
gpoHorGridLines, gpoVertGridLines,
gpoFixedHorGridLines, gpoFixedVertGridLines,
gpoHeaderBorderLines
];
end;
procedure TMainForm.GridPrinter1BeforePrint(Sender: TObject);
begin
// We want to draw on the printer/preview canvas. Therefore, we assign the
// grid's canvas to that of the GridPrinter. In order to restore the grid
// canvas after printing, we store its old canvas.
FGridCanvas := sWorksheetGrid1.Canvas;
sWorksheetGrid1.Canvas := GridPrinter1.Canvas;
//
FOldPadding := varCellPadding;
FNewPadding := GridPrinter1.Padding - varCellPadding;
@ -95,6 +88,28 @@ begin
gpoFixedHorGridLines, gpoFixedVertGridLines,
gpoHeaderBorderLines
];
// Store the worksheetgrid's ZoomFactor. We may have to change it
FOldZoomFactor := sWorksheetGrid1.ZoomFactor;
sWorksheetGrid1.ZoomFactor := GridPrinter1.PrintScaleFactor;
end;
procedure TMainForm.GridPrinter1AfterPrint(Sender: TObject);
begin
// Restore the worksheetgrid's Canvas.
sWorksheetGrid1.Canvas := FGridCanvas;
varCellPadding := FOldPadding;
// Restore drawing of the grid lines by the grid printer.
GridPrinter1.Options := GridPrinter1.Options + [
gpoHorGridLines, gpoVertGridLines,
gpoFixedHorGridLines, gpoFixedVertGridLines,
gpoHeaderBorderLines
];
// Restore the worksheetgrid's ZoomFactor
sWorksheetGrid1.ZoomFactor := FOldZoomFactor;
end;
procedure TMainForm.btnPrintClick(Sender: TObject);