⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptrvdata.pas

📁 richview1.7 full.source
💻 PAS
📖 第 1 页 / 共 3 页
字号:
   if DrawItems.Count = 0 then exit;
   MaxHeight := FRichView.Height - (TmpTMPix+TmpBMPix);
   DoFormatting(0, rvpsProceeding);
   i := 0;
   while i<DrawItems.Count do
     FormatNextPage(i, StartAt, StartY, Y, Splitting, MaxHeight);
   Result := PagesColl.Count;
   DoFormatting(Result, rvpsFinished);
end;
{------------------------------------------------------------------------------}
procedure TCustomMainPtblRVData.DoFormatting(PageCompleted: Integer; Step: TRVPrintingStep);
begin
end;
{------------------------------------------------------------------------------}
function TCustomMainPtblRVData.GetPrintableAreaLeft(PageNo: Integer): Integer;
begin
  Result := TmpLM;
end;
{------------------------------------------------------------------------------}
function TCustomMainPtblRVData.GetPrintableAreaTop: Integer;
begin
  Result := TmpTM;
end;
{------------------------------------------------------------------------------}
function TCustomMainPtblRVData.GetBack: TRVBackground;
begin
  Result := TCustomRichView(FRichView).Background;
end;
{------------------------------------------------------------------------------}
function TCustomMainPtblRVData.GetTopCoord(PageNo: Integer): Integer;
begin
  Result := TRVPageInfo(PagesColl.Items[PageNo-1]).StartY-TmpTM-TmpTMPix;
  if PageNo=1 then
    dec(Result,TPrintableRV(FRichView).RVPrint.StartAt);
end;
{------------------------------------------------------------------------------}
function TCustomMainPtblRVData.GetTopCoord2(PageNo: Integer): Integer;
begin
  Result := TRVPageInfo(PagesColl.Items[PageNo-1]).StartY2-TmpTM-TmpTMPix;
  if PageNo=1 then
    dec(Result,TPrintableRV(FRichView).RVPrint.StartAt);
end;
{------------------------------------------------------------------------------}
procedure TCustomMainPtblRVData.GetSADForFormatting(Canvas: TCanvas; var sad: TRVScreenAndDevice);
begin
  sad := PrnSaD;
end;
{------------------------------------------------------------------------------}
procedure TCustomMainPtblRVData.CheckPageNo(PageNo: Integer);
begin
  if (PageNo<1) or (PageNo>PagesColl.Count) then
    raise ERichViewError.Create(errInvalidPageNo);
end;
{------------------------------------------------------------------------------}
procedure TCustomMainPtblRVData.Prepare;
begin
  RV_InfoAboutSaD(PrnSaD, PrinterCanvas);
  TmpTMPix := MulDiv(FTopMarginPix,    PrnSaD.ppiyDevice, PrnSaD.ppiyScreen);
  TmpBMPix := MulDiv(FBottomMarginPix, PrnSaD.ppiyDevice, PrnSaD.ppiyScreen);
end;
{------------------------------------------------------------------------------}
procedure TCustomMainPtblRVData.RVFGetLimits(SaveScope: TRVFSaveScope;
                             var StartItem, EndItem, StartOffs, EndOffs: Integer;
                             var StartPart, EndPart: TRVMultiDrawItemPart);
var StartPartIndex, EndPartIndex: Integer;
begin
  if SaveScope=rvfss_Page then begin
    StartPartIndex := -1;
    EndPartIndex   := -1;
    GetDrawItemsRange(StreamSavePage, StartItem, EndItem, StartPartIndex);
    StartOffs := GetOffsBeforeDrawItem(StartItem);
    EndOffs   := GetOffsAfterDrawItem(EndItem);
    if (EndItem>StartItem) and
       (StreamSavePage<PagesColl.Count) and
       (TRVPageInfo(PagesColl.Items[StreamSavePage]).StartPart>1) then
      EndPartIndex := 0;
    if StartPartIndex<0 then
      StartPart := nil
    else
      StartPart := (DrawItems[StartItem] as TRVMultiDrawItemInfo).PartsList.Items[StartPartIndex];
    if EndPartIndex<0 then
      EndPart := nil
    else
      EndPart := (DrawItems[EndItem] as TRVMultiDrawItemInfo).PartsList.Items[EndPartIndex];
    DrawItem2Item(StartItem, StartOffs, StartItem, StartOffs);
    DrawItem2Item(EndItem, EndOffs, EndItem, EndOffs);
    end
  else
    inherited RVFGetLimits(SaveScope, StartItem, EndItem, StartOffs, EndOffs,
                           StartPart, EndPart);
end;
{------------------------------------------------------------------------------}
{$IFNDEF RVDONOTUSERVF}
function TCustomMainPtblRVData.SavePageAsRVF(Stream: TStream; PageNo: Integer; Color: TColor; Background: TRVBackground): Boolean;
begin
  StreamSavePage := PageNo;
  Result := SaveRVFToStreamEx(Stream, rvfss_Page, Color, Background, nil)
end;
{$ENDIF}
{============================== TPrintableRVData ==============================}
constructor TPrintableRVData.Create(RichView: TRVScroller);
begin
  inherited Create(RichView);
  HeaderY := 10;
  FooterY := 10;
end;
{------------------------------------------------------------------------------}
destructor TPrintableRVData.Destroy;
begin
  Footer.Free;
  Header.Free;
  inherited Destroy;
end;
{------------------------------------------------------------------------------}
procedure TPrintableRVData.DoPagePrepaint(Canvas: TCanvas; PageNo:Integer; Preview, Correction: Boolean);
var r: TRect;
begin
  r := Bounds(GetPrintableAreaLeft(PageNo), GetPrintableAreaTop,GetWidth,GetHeight);
  if Assigned(TRVPrint(TPrintableRV(FRichView).RVPrint).OnPagePrepaint) then
    TRVPrint(TPrintableRV(FRichView).RVPrint).OnPagePrepaint(
      TRVPrint(TPrintableRV(FRichView).RVPrint), PageNo, Canvas, Preview,
        Rect(0, 0, TmpLM+TmpRM+GetWidth, TmpTM+TmpBM+GetHeight),
        r
      );
  if Header<>nil then
    Header.DrawPage(1, Canvas, Preview, Correction);
  if Footer<>nil then
    Footer.DrawPage(1, Canvas, Preview, Correction);

  if TRVPrint(TPrintableRV(FRichView).RVPrint).ClipMargins then
    with r do
      IntersectClipRect(Canvas.Handle,Left,Top,Right,Bottom);
end;
{------------------------------------------------------------------------------}
procedure TPrintableRVData.DoPagePostpaint(Canvas: TCanvas; PageNo:Integer; Preview: Boolean);
var r: TRect;
begin
  r := Bounds(GetPrintableAreaLeft(PageNo), GetPrintableAreaTop,GetWidth,GetHeight);
  if Assigned(TRVPrint(TPrintableRV(FRichView).RVPrint).OnPagePostpaint) then
    TRVPrint(TPrintableRV(FRichView).RVPrint).OnPagePostpaint(
      TRVPrint(TPrintableRV(FRichView).RVPrint), PageNo, Canvas, Preview,
        Rect(0, 0, TmpLM+TmpRM+GetWidth, TmpTM+TmpBM+GetHeight),
        r
      );
end;
{------------------------------------------------------------------------------}
function TPrintableRVData.InitPrinterCanvas: TCanvas;
begin
  Result := TCanvas.Create;
  Result.Handle := RV_GetPrinterDC;
end;
{------------------------------------------------------------------------------}
procedure TPrintableRVData.DonePrinterCanvas(Canvas: TCanvas);
var PHDC: HDC;
begin
  PHDC := Canvas.Handle;
  Canvas.Handle := 0;
  Canvas.Free;
  DeleteDC(PHDC);
end;
{------------------------------------------------------------------------------}
procedure TPrintableRVData.DoFormatting(PageCompleted: Integer;
  Step: TRVPrintingStep);
begin
  if Assigned(TRVPrint(TPrintableRV(FRichView).RVPrint).OnFormatting) then
    TRVPrint(TPrintableRV(FRichView).RVPrint).OnFormatting(TPrintableRV(FRichView), PageCompleted, Step);
end;
{------------------------------------------------------------------------------}
function TPrintableRVData.GetPrintableAreaLeft(PageNo: Integer): Integer;
begin
  if not TPrintableRV(FRichView).FMirrorMargins or ((PageNo mod 2)=1) then
    Result := TmpLM
  else
    Result := TmpLMMir;
end;
{------------------------------------------------------------------------------}
function TPrintableRVData.GetPageHeight: Integer;
begin
  Result := Printer.PageHeight;
end;
{------------------------------------------------------------------------------}
function TPrintableRVData.GetPageWidth: Integer;
begin
  Result := Printer.PageWidth;
end;
{------------------------------------------------------------------------------}
procedure TPrintableRVData.Prepare;
var phoX, phoY, phW, phH, lpy, lpx, footeroffs: Integer;
    PHDC: HDC;
begin
  inherited Prepare;

  PrinterCanvas.Font.PixelsPerInch := PrnSaD.ppiyDevice;

  PHDC := PrinterCanvas.Handle;

  lpy := GetDeviceCaps(PHDC, LOGPIXELSY);
  lpx := GetDeviceCaps(PHDC, LOGPIXELSX);

  phoX := GetDeviceCaps(PHDC, PHYSICALOFFSETX);
  phoY := GetDeviceCaps(PHDC, PHYSICALOFFSETY);
  phW  := GetDeviceCaps(PHDC, PHYSICALWIDTH);
  phH  := GetDeviceCaps(PHDC, PHYSICALHEIGHT);

  {
  if phW>phoX+GetPageWidth then
    phW := phoX+GetPageWidth;
  if phH>phoY+GetPageHeight then
    phH := phoY+GetPageHeight;
  }

  with TPrintableRV(FRichView) do begin
    TmpLM := MulDiv(FLeftMarginMM,   5*lpx, 127)- phoX;
    TmpTM := MulDiv(FTopMarginMM,    5*lpy, 127)- phoY;
    TmpRM := MulDiv(FRightMarginMM,  5*lpx, 127)- (phW-(phoX+GetPageWidth));
    TmpBM := MulDiv(FBottomMarginMM, 5*lpy, 127)- (phH-(phoY+GetPageHeight));

    TmpLMMir := MulDiv(FRightMarginMM,   5*lpx, 127)- phoX;
  end;

  if TmpLM<0 then TmpLM := 0;
  if TmpTM<0 then TmpTM := 0;
  if TmpRM<0 then TmpRM := 0;
  if TmpBM<0 then TmpBM := 0;
  if TmpLMMir<0 then TmpLMMir := 0;

  if Header<>nil then begin
    Header.Left := TmpLM;
    Header.Width := GetPageWidth - (TmpLM+TmpRM);
    Header.Top := MulDiv(HeaderY,  5*lpy, 127)- phoY;
    if Header.Top<0 then
      Header.Top := 0;
    Header.Height := 1;
    Header.Format(True);
    if TmpTM<Header.Top+Header.DocumentHeight then
      TmpTM := Header.Top+Header.DocumentHeight;
  end;

  if Footer<>nil then begin
    Footer.Left := TmpLM;
    Footer.Width := GetPageWidth - (TmpLM+TmpRM);
    Footer.Top := 0;
    Footer.Height := 1;
    Footer.Format(True);
    footeroffs := MulDiv(FooterY,  5*lpy, 127)-(phH-(phoY+GetPageHeight))+Footer.DocumentHeight;
    Footer.Top := GetPageHeight-footeroffs;
    if TmpBM<footeroffs then
      TmpBM := footeroffs;
  end;

  State := State+[rvstSkipformatting];
  try
    FRichView.ClientWidth := GetPageWidth - (TmpLM+TmpRM);
    FRichView.ClientHeight:= GetPageHeight - (TmpTM+TmpBM);
  finally
    State := State-[rvstSkipformatting];
  end;
end;
{================================ TRectPtblRVData =============================}
constructor TRectPtblRVData.Create(RichView: TRVScroller;
  PrintingData: TCustomRVFormattedData);
begin
  inherited Create(RichView);
  FPrintingData := PrintingData;
  ShareItemsFrom(PrintingData);
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetPrintableAreaLeft(PageNo: Integer): Integer;
begin
  Result := Left+DX;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetPrintableAreaTop: Integer;
begin
  Result := Top+DY;
end;
{------------------------------------------------------------------------------}
procedure TRectPtblRVData.GetSADForFormatting(Canvas: TCanvas; var sad: TRVScreenAndDevice);
begin
  sad := TCustomMainPtblRVData(TPrintableRV(FRichView).RVData).PrnSaD;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetTopCoord(PageNo: Integer): Integer;
begin
  Result := -(Top+DY);
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetWidth: Integer;
begin
  Result := Width;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetHeight: Integer;
begin
  Result := Height;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.InitPrinterCanvas: TCanvas;
begin
  Result := GetCanvas;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetCanvas: TCanvas;
begin
  Result := TCustomMainPtblRVData(TPrintableRV(FRichView).RVData).PrinterCanvas;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetColor: TColor;
begin
  Result := FColor;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetBottomMargin: Integer;
begin
  Result := 0;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetLeftMargin: Integer;
begin
  Result := 0;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetRightMargin: Integer;
begin
  Result := 0;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetTopMargin: Integer;
begin
  Result := 0;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetParentData: TCustomRVData;
begin
  Result := TCustomRichView(FRichView).RVData;
end;
{------------------------------------------------------------------------------}
function TRectPtblRVData.GetRootData: TCustomRVData;
begin
  Result := GetParentData.GetRootData;
end;
{========================= TRVHeaderFooterRVData ==============================}
constructor TRVHeaderFooterRVData.Create(RichView: TRVScroller;
  PrintingData: TCustomRVFormattedData);
begin
  inherited;
  FColor := clNone;
end;

function TRVHeaderFooterRVData.GetMaxTextWidth: Integer;
begin
  Result := 0;
end;

function TRVHeaderFooterRVData.GetRVStyle: TRVStyle;
begin
  Result := FPrintingData.GetRVStyle;
end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -