📄 ptblrv.pas
字号:
var FullWidth, FullHeight: Integer;
RectWidth, RectHeight, LM: Integer;
begin
with TCustomMainPtblRVData(rv.RVData) do begin
FullWidth := rv.ClientWidth+TmpLM+TmpRM;
FullHeight := rv.ClientHeight+TmpTM+TmpBM;
RectWidth := PageRect.Right-PageRect.Left;
RectHeight := PageRect.Bottom-PageRect.Top;
LM := TCustomPrintableRVData(rv.RVData).GetPrintableAreaLeft(PageNo);
Canvas.Rectangle(
PageRect.Left+MulDiv(LM,RectWidth,FullWidth),
PageRect.Top+MulDiv(TmpTM,RectHeight,FullHeight),
PageRect.Left+MulDiv(LM+rv.ClientWidth,RectWidth,FullWidth),
PageRect.Top+MulDiv(TmpTM+rv.ClientHeight,RectHeight,FullHeight)
);
end;
end;
{=============================== TRVPrint =====================================}
constructor TRVPrint.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LeftMarginMM := 20;
RightMarginMM := 20;
TopMarginMM := 20;
BottomMarginMM := 20;
end;
{------------------------------------------------------------------------------}
function TRVPrint.CreateRichView: TCustomPrintableRV;
begin
Result := TPrintableRV.Create(Self);
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetMirrorMargins: Boolean;
begin
Result := TPrintableRV(rv).FMirrorMargins;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetMirrorMargins(const Value: Boolean);
begin
TPrintableRV(rv).FMirrorMargins := Value;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetLM: Integer;
begin
GetLM := TPrintableRV(rv).FLeftMarginMM;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetRM: Integer;
begin
GetRM := TPrintableRV(rv).FRightMarginMM;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetTM: Integer;
begin
GetTM := TPrintableRV(rv).FTopMarginMM;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetBM: Integer;
begin
GetBM := TPrintableRV(rv).FBottomMarginMM;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetLM(mm: Integer);
begin
TPrintableRV(rv).FLeftMarginMM := mm;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetRM(mm: Integer);
begin
TPrintableRV(rv).FRightMarginMM := mm;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetTM(mm: Integer);
begin
TPrintableRV(rv).FTopMarginMM := mm;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetBM(mm: Integer);
begin
TPrintableRV(rv).FBottomMarginMM := mm;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetFooterY: Integer;
begin
Result := TPrintableRVData(rv.RVData).FooterY;
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetHeaderY: Integer;
begin
Result := TPrintableRVData(rv.RVData).HeaderY;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetFooterY(const Value: Integer);
begin
TPrintableRVData(rv.RVData).FooterY := Value;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetHeaderY(const Value: Integer);
begin
TPrintableRVData(rv.RVData).HeaderY := Value;
end;
{------------------------------------------------------------------------------}
function TRVPrint.FormatPages(PrintOptions:TRVDisplayOptions): Integer;
begin
FormatPages := rv.FormatPages;
Ready := True;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.Print(Title: String; Copies: Integer; Collate: Boolean);
begin
TPrintableRV(rv).Print(Title, Copies, Collate);
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.PrintPages(firstPgNo, lastPgNo: Integer; Title: String;
Copies: Integer; Collate: Boolean);
begin
TPrintableRV(rv).PrintPages(firstPgNo, lastPgNo, Title, Copies, Collate);
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.ContinuousPrint;
begin
TPrintableRV(rv).ContinuousPrint;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.AssignSource(PrintMe: TCustomRichView);
begin
rv.RVData.ShareItemsFrom(PrintMe.RVData);
rv.RVData.State := rv.RVData.State+[rvstSkipFormatting];
try
rv.LeftMargin := PrintMe.LeftMargin;
rv.RightMargin := PrintMe.RightMargin;
rv.TopMargin := 0;
rv.BottomMargin := 0;
TPrintableRVData(rv.RVData).FTopMarginPix := PrintMe.TopMargin;
TPrintableRVData(rv.RVData).FBottomMarginPix := PrintMe.BottomMargin;
rv.Style := PrintMe.Style;
rv.DoInPaletteMode := PrintMe.DoInPaletteMode;
rv.BackgroundBitmap := PrintMe.BackgroundBitmap;
rv.BackgroundStyle := PrintMe.BackgroundStyle;
rv.Color := PrintMe.Color;
rv.BiDiMode := PrintMe.BiDiMode;
finally
rv.RVData.State := rv.RVData.State-[rvstSkipFormatting];
end;
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetHeader(RVData: TCustomRVFormattedData);
begin
TPrintableRVData(rv.RVData).Header.Free;
TPrintableRVData(rv.RVData).Header := nil;
if RVData<>nil then
TPrintableRVData(rv.RVData).Header := TRVHeaderFooterRVData.Create(rv, RVData);
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.SetFooter(RVData: TCustomRVFormattedData);
begin
TPrintableRVData(rv.RVData).Footer.Free;
TPrintableRVData(rv.RVData).Footer := nil;
if RVData<>nil then
TPrintableRVData(rv.RVData).Footer := TRVHeaderFooterRVData.Create(rv, RVData);
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.MakeScaledPreview(pgNo: Integer; bmp: TBitmap);
begin
DrawPreview(pgNo, bmp.Canvas, Rect(0,0,bmp.Width, bmp.Height));
end;
{------------------------------------------------------------------------------}
procedure TRVPrint.MakePreview(pgNo: Integer; bmp: TBitmap);
var w,h: Integer;
begin
w := GetPreview100PercentWidth;
h := GetPreview100PercentHeight;
if bmp.Width <> w then bmp.Width := w;
if bmp.Height <> h then bmp.Height := h;
MakeScaledPreview(pgNo,bmp);
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetFooterRect: TRect;
begin
if TPrintableRVData(rv.RVData).Footer=nil then
Result := Rect(0,0,0,0)
else
with TPrintableRVData(rv.RVData).Footer do
Result := Bounds(Left+DX,Top+DY,Width,DocumentHeight);
end;
{------------------------------------------------------------------------------}
function TRVPrint.GetHeaderRect: TRect;
begin
if TPrintableRVData(rv.RVData).Header=nil then
Result := Rect(0,0,0,0)
else
with TPrintableRVData(rv.RVData).Header do
Result := Bounds(Left+DX,Top+DY,Width,DocumentHeight);
end;
{======================== TCustomPrintableRV ==================================}
constructor TCustomPrintableRV.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Visible := False;
Flags := Flags - [rvflUseJumps] + [rvflPrinting,rvflShareContents,rvflAllowCustomDrawItems];
TopMargin := 0; // do not change!
BottomMargin := 0; // do not change!
BorderStyle := bsNone;
end;
{------------------------------------------------------------------------------}
function TCustomPrintableRV.FormatPages: Integer;
begin
RVData.State := RVData.State+[rvstSkipformatting];
try
VScrollVisible := False;
HScrollVisible := False;
finally
RVData.State := RVData.State-[rvstSkipformatting];
end;
Result := TPrintableRVData(RVData).FormatPages;
end;
{------------------------------------------------------------------------------}
procedure TCustomPrintableRV.DrawPage(pgNo: Integer; Canvas: TCanvas;
Preview, Correction: Boolean);
begin
TPrintableRVData(RVData).DrawPage(pgNo, Canvas, Preview, Correction);
end;
{============================= TPrintableRV ===================================}
function TPrintableRV.GetDataClass: TRichViewRVDataClass;
begin
Result := TPrintableRVData;
end;
{------------------------------------------------------------------------------}
procedure TPrintableRV.ContinuousPrint;
var i: Integer;
begin
for i := 1 to TPrintableRVData(RVData).PagesColl.Count do begin
if i<>1 then
Printer.NewPage;
DrawPage(i, Printer.Canvas,False,False);
end;
end;
{------------------------------------------------------------------------------}
procedure TPrintableRV.DoOnPrinting(PageCompleted: Integer; Step:TRVPrintingStep);
begin
if Assigned(TRVPrint(RVPrint).FOnPrinting) then
TRVPrint(RVPrint).FOnPrinting(Self, PageCompleted, Step);
end;
{------------------------------------------------------------------------------}
procedure TPrintableRV.PrintPages(firstPgNo, lastPgNo: Integer;
const Title: String;
Copies: Integer; Collate: Boolean);
var i,copyno: Integer;
PrinterCopies: Integer;
begin
FRVPrint.StartAt := 0;
DoOnPrinting(0, rvpsStarting);
Printer.Title := Title;
PrinterCopies := Printer.Copies; { storing }
if pcCopies in Printer.Capabilities then
begin
Printer.Copies := Copies;
// Printer can make copies and collation if needed
Copies := 1; // TRichView need not support copies and collation itself
end
else
Printer.Copies := 1; // TRichView will provide copies and collation itself
Printer.BeginDoc;
if Collate then
for copyno:= 1 to Copies do
for i := firstPgNo to lastPgNo do
begin
DrawPage(i, Printer.Canvas,False,False);
DoOnPrinting(i, rvpsProceeding);
if not ((i=lastPgNo) and (copyno=Copies)) then Printer.NewPage;
end
else
for i := firstPgNo to lastPgNo do
for copyno:= 1 to Copies do
begin
DrawPage(i, Printer.Canvas,False,False);
DoOnPrinting(i, rvpsProceeding);
if not ((i=lastPgNo) and (copyno=Copies)) then Printer.NewPage;
end;
Printer.EndDoc;
Printer.Copies := PrinterCopies; { restoring }
DoOnPrinting(0, rvpsFinished);
end;
{------------------------------------------------------------------------------}
procedure TPrintableRV.Print(const Title: String; Copies: Integer; Collate: Boolean);
begin
PrintPages(1, TPrintableRVData(RVData).PagesColl.Count, Title, Copies, Collate);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -