Problems with TRvPrint

General TRichView support forum. Please post your questions here
Post Reply
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Problems with TRvPrint

Post by Michael Pro »

I've got one nasty bug - I'm using class, inherited from TRichView, in FastReport ver. 4.0 - and for some purpose I'm drawing metafile with some procedures from TRvPrint.
Actually, sometimes it works fine, but sometimes these functions:
1. DrawTransparentPreview
2. Preview100PercentWidth
3. Preview100PercentHeight
make something with global coordinates - and everything works awfully - it shifts whole image for many pixels on a FastReport Designer Form.
After a click on form everything works fine.
I've tested my sources a numerous times - this three functions create this bug.
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Well, I've solved this problem - algorithmically - but the problem still exists somewhere in sources.
Best regards,
Michael.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Preview100PercentWidth/Height just perform some calculations, they should not affect coordinates.
What is DrawTransparentPreview?
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Sergey Tkachenko wrote:Preview100PercentWidth/Height just perform some calculations, they should not affect coordinates.
What is DrawTransparentPreview?
Sorry, it was DrawPreview procedure.

Code: Select all

  PrinterHandle := GetDC(0);
  EMF := TMetafile.Create;
  try
    EMFCanvas := TMetafileCanvas.Create(EMF, PrinterHandle);
    try
      with EMF do
      begin
        Clear;
        Width := Trunc(FCustomPrinter.Preview100PercentWidth * ScaleX);
        Height := Trunc(FCustomPrinter.Preview100PercentHeight * ScaleY);
      end;
      rgn := CreateRectRgn(0, 0, FX1 - FX, FY1 - FY);
      SelectClipRgn(EMFCanvas.Handle, rgn);
      FCustomPrinter.DrawPreview(1, EMFCanvas, Rect(0, 0, EMF.Width, EMF.Height));
      SelectClipRgn(EMFCanvas.Handle, 0);
      DeleteObject(rgn);
    finally
      EMFCanvas.Free;
    end;
    Canvas.StretchDraw(Rect(FX, FY, FX1, FY1),
      EMF);
  finally
    ReleaseDC(0, PrinterHandle);
    EMF.Free;
  end;
Here is the part of code, worked with FastReport.

If I loading metafile from file (not drawing with CustomPrinter), everything works fine.
Actually, maybe it could be trouble with FastReport Designer - because it works fine after redrawing designer workspace.
I've solved this problem in following way - I've restricted to make this part of code, if nothing is loaded to document.
Don't be disturbed - it's very specific problem, and it could be solved without modifying sources :) Now everything works fine - and by the way your component could be simply integrated into FastReport.

Best regards,
Michael.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Try changing TCustomRVPrint.DrawPreview to:

Code: Select all

procedure TCustomRVPrint.DrawPreview(pgNo: Integer; Canvas: TCanvas;
  const PageRect: TRect);
var OldMapMode, OldPPI: Integer;
    OldWindowExt, OldViewportExt: TSize;
    OldViewportOrg: TPoint;
begin
  OldMapMode := GetMapMode(Canvas.Handle);
  SetMapMode(Canvas.Handle,MM_TEXT);
  Canvas.Brush.Color := clWhite;
  Canvas.Pen.Color := clWhite;
  Canvas.FillRect(PageRect);
  SetMapMode(Canvas.Handle,MM_ANISOTROPIC);
  with TCustomMainPtblRVData(rv.RVData) do
   SetWindowExtEx(Canvas.Handle,
     rv.ClientWidth +TmpM.Left+TmpM.Right,
     rv.ClientHeight+TmpM.Top+TmpM.Bottom, @OldWindowExt);
  with PageRect do begin
    SetViewportExtEx(Canvas.Handle, Right-Left, Bottom-Top, @OldViewportExt);
    SetViewportOrgEx(Canvas.Handle,Left,Top, @OldViewportOrg);
  end;
  OldPPI := Canvas.Font.PixelsPerInch;
  Canvas.Font.PixelsPerInch := TCustomMainPtblRVData(rv.RVData).PrnSaD.ppiyDevice;
  try
    rv.DrawPage(pgNo, Canvas, True, PreviewCorrection);
  finally
    Canvas.Font.PixelsPerInch := OldPPI;
    SetViewportOrgEx(Canvas.Handle, OldViewportOrg.X, OldViewportOrg.Y, nil);
    SetViewportExtEx(Canvas.Handle, OldViewportExt.cx, OldViewportExt.cy, nil);
    SetWindowExtEx(Canvas.Handle, OldWindowExt.cx, OldWindowExt.cy, nil);
    SetMapMode(Canvas.Handle, OldMapMode);
  end;
end;
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Sergey, thanks for your help.
Code won't help - well, it looks like it's internal problem of FastReport - I didn't find the reason, why your code couldn't work correctly - it means, that something wrong inside new FastReport versions.
Anyway, everything works fine with one simple if-statement.
---
Best regards,
Michael.
Post Reply