This patch add the pagination feature. Feel free to changing it:
From 6750de2a86dbd2c58842c28fcd9f719e47a46290 Mon Sep 17 00:00:00 2001
From: silvioprog <[email protected]>
Date: Tue, 24 Nov 2015 18:19:42 -0300
Subject: [PATCH 1/1] Add the pagination feature.
---
Component/RSPrint.pas | 70 +++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 60 insertions(+), 10 deletions(-)
diff --git a/Component/RSPrint.pas b/Component/RSPrint.pas
index 10bee8a..acdf7a5 100644
--- a/Component/RSPrint.pas
+++ b/Component/RSPrint.pas
@@ -4,7 +4,8 @@ interface
uses
Windows, Messages, SysUtils, CommDlg, Classes, Graphics, Controls, ExtCtrls, StdCtrls, Consts, ShellAPI, Menus,
- Printers, ComCtrls, Forms, Dialogs, RSPrint.Types.CommonTypes, RSPrint.Types.Document, Generics.Collections;
+ Printers, ComCtrls, Forms, Dialogs, RSPrint.Types.CommonTypes, RSPrint.Types.Document, Generics.Collections,
+ System.UITypes;
type
TRSPrinter = class(TComponent)
@@ -26,6 +27,8 @@ type
FZoom: TInitialZoom;
FWinPrinter: string; // NOMBRE DE LA IMPRESORA EN WINDOWS
FCancelado: Boolean;
+ FCurrLine: Cardinal;
+ FPaginated: Boolean;
function GetModelRealName(model: TPrinterModel): string;
procedure SetModel(name: TPrinterModel);
@@ -82,9 +85,18 @@ type
procedure Print;
procedure PrintAll;
- procedure Write(line, col: Byte; text: string);
- procedure WriteFont(line, col: Byte; text: string; font: TFastFont);
- procedure NewPage;
+ procedure Write(line, col: Byte; const text: string); overload; virtual;
+ procedure Write(line, col: Byte; const text: string;
+ ALineFeed: Boolean); overload; virtual;
+ procedure Write(col: Byte; const text: string;
+ ALineFeed: Boolean); overload; virtual;
+ procedure Write(col: Byte; const text: string); overload; virtual;
+
+ function WriteFont(line, col: Byte; const text: string;
+ font: TFastFont): Boolean; overload; virtual;
+ procedure WriteFont(line, col: Byte; const text: string; font: TFastFont;
+ ALineFeed: Boolean); overload; virtual;
+ procedure NewPage; virtual;
procedure DrawMetafile(col, line: Single; picture: TMetafile);
@@ -92,7 +104,7 @@ type
procedure LineH(line, col1, col2: Byte; kind: TLineType);
procedure LineV(line1, line2, col: Byte; kind: TLineType);
- procedure SetModelName(name: string);
+ procedure SetModelName(const name: string);
function GetModelName: string;
procedure GetModels(models: TStrings);
@@ -104,6 +116,7 @@ type
property WinPrinter: string read FWinPrinter write FWinPrinter;
property PageNo: Integer read GetCurrentPageNumber;
+ property CurrLine: Cardinal read FCurrLine;
published
property PageContinuousJump: Byte read GetPageContinuousJump write SetPageContinuousJump default 5;
property PageSize: TPageSize read GetPageSize write SetPageSize;
@@ -123,6 +136,7 @@ type
property Transliterate: Boolean read GetTransliterate write SetTransliterate default True;
property WinMarginTop: Integer read FWinSupMargin write FWinSupMargin default 0;
property WinMarginBottom: Integer read FWinBotMargin write FWinBotMargin default 0;
+ property Paginated: Boolean read FPaginated write FPaginated;
end;
procedure Register;
@@ -149,6 +163,8 @@ begin
if (AOwner is TForm) and not (csDesigning in ComponentState) then
FOwner := TForm(AOwner);
+ FCurrLine := 1;
+
FColumnas := 80;
FZoom := zWidth;
@@ -433,12 +449,14 @@ begin
FDocument.ClearPages;
end;
-procedure TRSPrinter.WriteFont(line, col: Byte; text: string; font: TFastFont);
+function TRSPrinter.WriteFont(line, col: Byte; const text: string;
+ font: TFastFont): Boolean;
var
Escritura: TWrittenText;
P: Integer;
begin
- if FDocument.Pages.Count > 0 then
+ Result := FDocument.Pages.Count > 0;
+ if Result then
begin
P := 0;
@@ -466,9 +484,40 @@ begin
end;
end;
-procedure TRSPrinter.Write(line, col: Byte; text: string);
+procedure TRSPrinter.Write(line, col: Byte; const text: string);
+begin
+ WriteFont(line, col, text, FDocument.DefaultFont, False);
+end;
+
+procedure TRSPrinter.Write(line, col: Byte; const text: string;
+ ALineFeed: Boolean);
begin
- WriteFont(line, col, text, FDocument.DefaultFont);
+ WriteFont(line, col, text, FDocument.DefaultFont, ALineFeed);
+end;
+
+procedure TRSPrinter.Write(col: Byte; const text: string; ALineFeed: Boolean);
+begin
+ WriteFont(FCurrLine, col, text, FDocument.DefaultFont, ALineFeed);
+end;
+
+procedure TRSPrinter.Write(col: Byte; const text: string);
+begin
+ WriteFont(FCurrLine, col, text, FDocument.DefaultFont, False);
+end;
+
+procedure TRSPrinter.WriteFont(line, col: Byte; const text: string;
+ font: TFastFont; ALineFeed: Boolean);
+begin
+ if WriteFont(line, col, text, font) and ALineFeed then
+ begin
+ if FPaginated and (FCurrLine = Lines) then
+ begin
+ FCurrLine := 1;
+ NewPage;
+ end
+ else
+ Inc(FCurrLine);
+ end;
end;
procedure TRSPrinter.DrawMetafile(col, line: Single; picture: TMetafile);
@@ -1081,10 +1130,11 @@ end;
procedure TRSPrinter.NewPage;
begin
+ FCurrLine := 1;
FDocument.NewPage;
end;
-procedure TRSPrinter.SetModelName(name: string);
+procedure TRSPrinter.SetModelName(const name: string);
begin
if FMode = pmWindows then
begin
--
1.9.5.msysgit.0