GridPrinter: Implement scaling factor for printer (in addition to already existing preview scaling factor).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8621 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-11-14 18:49:55 +00:00
parent 1e79d006f9
commit 822873cffb
4 changed files with 30 additions and 14 deletions

View File

@ -140,6 +140,8 @@ begin
finally finally
StringGrid1.EndUpdate; StringGrid1.EndUpdate;
end; end;
// GridPrinter1.PrintScaleFactor := 0.5;
end; end;
{ Populates the languages combobox: reads the names of the app's .po files { Populates the languages combobox: reads the names of the app's .po files

View File

@ -45,6 +45,7 @@
<Unit0> <Unit0>
<Filename Value="multilanguage_demo.lpr"/> <Filename Value="multilanguage_demo.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="MultiLanguage_Demo"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="main.pas"/> <Filename Value="main.pas"/>

View File

@ -10,8 +10,7 @@ uses
athreads, athreads,
{$ENDIF} {$ENDIF}
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, Main, printer4lazarus Forms, Main;
{ you can add units after this };
{$R *.res} {$R *.res}

View File

@ -145,6 +145,7 @@ type
function IsFixedLineWidthStored: Boolean; function IsFixedLineWidthStored: Boolean;
function IsGridLineWidthStored: Boolean; function IsGridLineWidthStored: Boolean;
function IsOrientationStored: Boolean; function IsOrientationStored: Boolean;
function IsPrintScaleFactorStored: Boolean;
procedure SetBorderLineColor(AValue: TColor); procedure SetBorderLineColor(AValue: TColor);
procedure SetBorderLineWidth(AValue: Double); procedure SetBorderLineWidth(AValue: Double);
procedure SetFileName(AValue: String); procedure SetFileName(AValue: String);
@ -179,6 +180,7 @@ type
FPreviewBitmap: TBitmap; // Bitmap to which the preview image is printed FPreviewBitmap: TBitmap; // Bitmap to which the preview image is printed
FPreviewPage: Integer; // Page request for the preview bitmap FPreviewPage: Integer; // Page request for the preview bitmap
FPreviewPercent: Integer; // Scaling factor for preview bitmap FPreviewPercent: Integer; // Scaling factor for preview bitmap
FPrintScaleFactor: Double; // Scaling factor for printing
FColCount: Integer; FColCount: Integer;
FRowCount: Integer; FRowCount: Integer;
FFixedCols: Integer; FFixedCols: Integer;
@ -212,7 +214,7 @@ type
procedure PrintRowHeader(ACanvas: TCanvas; ARow: Integer; X, Y: Double); procedure PrintRowHeader(ACanvas: TCanvas; ARow: Integer; X, Y: Double);
procedure ScaleColWidths(AFactor: Double); procedure ScaleColWidths(AFactor: Double);
procedure ScaleRowHeights(AFactor: Double); procedure ScaleRowHeights(AFactor: Double);
procedure SelectFont(ACanvas: TCanvas; AFont: TFont); procedure SelectFont(ACanvas: TCanvas; AFont: TFont; AScaleFactor: Double = 1.0);
property OutputDevice: TGridPrnOutputDevice read FOutputDevice; property OutputDevice: TGridPrnOutputDevice read FOutputDevice;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -250,6 +252,7 @@ type
property Options: TGridPrnOptions read FOptions write SetOptions default []; property Options: TGridPrnOptions read FOptions write SetOptions default [];
property Orientation: TPrinterOrientation read GetOrientation write SetOrientation stored IsOrientationStored; property Orientation: TPrinterOrientation read GetOrientation write SetOrientation stored IsOrientationStored;
property PrintOrder: TGridPrnOrder read FPrintOrder write FPrintOrder default poRowsFirst; property PrintOrder: TGridPrnOrder read FPrintOrder write FPrintOrder default poRowsFirst;
property PrintScaleFactor: Double read FPrintScaleFactor write FPrintScaleFactor stored IsPrintScaleFactorStored;
property ShowPrintDialog: TGridPrnDialog read FShowPrintDialog write FShowPrintDialog default gpdNone; property ShowPrintDialog: TGridPrnDialog read FShowPrintDialog write FShowPrintDialog default gpdNone;
property ToPage: Integer read FToPage write FToPage default 0; property ToPage: Integer read FToPage write FToPage default 0;
property OnAfterPrint: TNotifyEvent read FOnAfterPrint write FOnAfterPrint; property OnAfterPrint: TNotifyEvent read FOnAfterPrint write FOnAfterPrint;
@ -500,7 +503,7 @@ begin
if FLineWidth = 0 then if FLineWidth = 0 then
Result := FOwner.ScaleY(1) Result := FOwner.ScaleY(1)
else else
Result := mm2px(FLineWidth, FOwner.PixelsPerInchY); Result := mm2px(FLineWidth/FOwner.PrintScaleFactor, FOwner.PixelsPerInchY);
end; end;
procedure TGridPrnHeaderFooter.SetFont(AValue: TFont); procedure TGridPrnHeaderFooter.SetFont(AValue: TFont);
@ -586,6 +589,7 @@ begin
FFooter := TGridPrnHeaderFooter.Create(Self); FFooter := TGridPrnHeaderFooter.Create(Self);
FPrintOrder := poRowsFirst; FPrintOrder := poRowsFirst;
FPrintScaleFactor := 1.0;
FBorderLineColor := clDefault; FBorderLineColor := clDefault;
FFixedLineColor := clDefault; FFixedLineColor := clDefault;
FGridLineColor := clDefault; FGridLineColor := clDefault;
@ -852,6 +856,11 @@ begin
Result := GetOrientation <> poPortrait; Result := GetOrientation <> poPortrait;
end; end;
function TGridPrinter.IsPrintScaleFactorStored: Boolean;
begin
Result := FPrintScaleFactor <> 1.0;
end;
{ Find the column and row indices before which page breaks are occuring. { Find the column and row indices before which page breaks are occuring.
Store them in the arrays FPageBreakCols and FPageBreakRows. Store them in the arrays FPageBreakCols and FPageBreakRows.
Note that the indices do not contain the fixed columns/rows. } Note that the indices do not contain the fixed columns/rows. }
@ -911,8 +920,8 @@ end;
procedure TGridPrinter.Measure(APageWidth, APageHeight, XDpi, YDpi: Integer); procedure TGridPrinter.Measure(APageWidth, APageHeight, XDpi, YDpi: Integer);
begin begin
// Multiplication factor needed by ScaleX and ScaleY // Multiplication factor needed by ScaleX and ScaleY
FFactorX := XDpi / ScreenInfo.PixelsPerInchX; FFactorX := XDpi / ScreenInfo.PixelsPerInchX * FPrintScaleFactor;
FFactorY := YDpi / ScreenInfo.PixelsPerInchY; FFactorY := YDpi / ScreenInfo.PixelsPerInchY * FPrintScaleFactor;
// Margins in the new pixel density units. // Margins in the new pixel density units.
FLeftMargin := mm2px(FMargins.Left, XDpi); FLeftMargin := mm2px(FMargins.Left, XDpi);
@ -996,7 +1005,7 @@ begin
ACanvas.Brush.Color := GetBrushColor(lGrid.AlternateColor); ACanvas.Brush.Color := GetBrushColor(lGrid.AlternateColor);
end; end;
// Font // Font
SelectFont(ACanvas, lGrid.Font); SelectFont(ACanvas, lGrid.Font, FPrintScaleFactor);
ACanvas.Font.Color := GetFontColor(lGrid.Font.Color); ACanvas.Font.Color := GetFontColor(lGrid.Font.Color);
FixFontSize(ACanvas.Font); FixFontSize(ACanvas.Font);
// Text style // Text style
@ -1113,7 +1122,7 @@ begin
firstPrintPage := IfThen((FFromPage < 1) or (FFromPage > FPageCount), 1, FFromPage); firstPrintPage := IfThen((FFromPage < 1) or (FFromPage > FPageCount), 1, FFromPage);
lastPrintPage := IfThen((FToPage < 1) or (FToPage > FPageCount), FPageCount, FToPage); lastPrintPage := IfThen((FToPage < 1) or (FToPage > FPageCount), FPageCount, FToPage);
SelectFont(ACanvas, FGrid.Font); SelectFont(ACanvas, FGrid.Font, FPrintScaleFactor);
FPageNumber := 1; FPageNumber := 1;
for horPage := 0 to High(FPageBreakCols) do for horPage := 0 to High(FPageBreakCols) do
@ -1159,7 +1168,7 @@ begin
firstPrintPage := IfThen((FFromPage < 1) or (FFromPage > FPageCount), 1, FFromPage); firstPrintPage := IfThen((FFromPage < 1) or (FFromPage > FPageCount), 1, FFromPage);
lastPrintPage := IfThen((FToPage < 1) or (FToPage > FPageCount), FPageCount, FToPage); lastPrintPage := IfThen((FToPage < 1) or (FToPage > FPageCount), FPageCount, FToPage);
SelectFont(ACanvas, FGrid.Font); SelectFont(ACanvas, FGrid.Font, FPrintScaleFactor);
FPageNumber := 1; FPageNumber := 1;
for vertPage := 0 to High(FPageBreakRows) do for vertPage := 0 to High(FPageBreakRows) do
@ -1324,7 +1333,7 @@ begin
if not FFooter.IsShown then if not FFooter.IsShown then
exit; exit;
SelectFont(ACanvas, FFooter.Font); SelectFont(ACanvas, FFooter.Font, 1.0);
ACanvas.Font.Color := GetFontColor(FFooter.Font.Color); ACanvas.Font.Color := GetFontColor(FFooter.Font.Color);
printableWidth := FPageRect.Width; printableWidth := FPageRect.Width;
if (FFooter.SectionText[hfsLeft] <> '') and (FFooter.SectionText[hfsCenter] = '') and (FFooter.SectionText[hfsRight] = '') then if (FFooter.SectionText[hfsLeft] <> '') and (FFooter.SectionText[hfsCenter] = '') and (FFooter.SectionText[hfsRight] = '') then
@ -1515,7 +1524,7 @@ begin
if not FHeader.IsShown then if not FHeader.IsShown then
exit; exit;
SelectFont(ACanvas, FHeader.Font); SelectFont(ACanvas, FHeader.Font, 1.0);
ACanvas.Font.Color := GetFontColor(FHeader.Font.Color); ACanvas.Font.Color := GetFontColor(FHeader.Font.Color);
printableWidth := FPageRect.Width; printableWidth := FPageRect.Width;
if (FHeader.SectionText[hfsLeft] <> '') and (FHeader.SectionText[hfsCenter] = '') and (FHeader.SectionText[hfsRight] = '') then if (FHeader.SectionText[hfsLeft] <> '') and (FHeader.SectionText[hfsCenter] = '') and (FHeader.SectionText[hfsRight] = '') then
@ -1687,17 +1696,22 @@ begin
Result := Round(FFactorY * AValue); Result := Round(FFactorY * AValue);
end; end;
procedure TGridPrinter.SelectFont(ACanvas: TCanvas; AFont: TFont); procedure TGridPrinter.SelectFont(ACanvas: TCanvas; AFont: TFont;
AScaleFactor: Double = 1.0);
var var
fd: TFontData; fd: TFontData;
fontSize: Integer;
begin begin
ACanvas.Font.Assign(AFont); ACanvas.Font.Assign(AFont);
ACanvas.Font.PixelsPerInch := FPixelsPerInchY; ACanvas.Font.PixelsPerInch := FPixelsPerInchY;
if AFont.Size = 0 then if AFont.Size = 0 then
begin begin
fd := GetFontData(AFont.Reference.Handle); fd := GetFontData(AFont.Reference.Handle);
ACanvas.Font.Size := abs(fd.Height) * 72 div ScreenInfo.PixelsPerInchY; fontSize := round(abs(fd.Height) * 72 / ScreenInfo.PixelsPerInchY * AScaleFactor);
end; end else
fontSize := round(ACanvas.Font.Size * AScaleFactor);
if fontSize < 3 then fontSize := 3;
ACanvas.Font.Size := fontSize;
end; end;
procedure TGridPrinter.SetBorderLineColor(AValue: TColor); procedure TGridPrinter.SetBorderLineColor(AValue: TColor);