2 pixel cropped when drawing into device context

General TRichView support forum. Please post your questions here
Post Reply
lwinter
Posts: 24
Joined: Thu Dec 01, 2005 4:42 am

2 pixel cropped when drawing into device context

Post by lwinter »

Hi Sergey,

when drawing the content of a RV edior into a device context (metafile), it looks as if it would print one or two pixels over the right and bottom.

Also, when right-justified, the plain text lines are printed two pixels too far to the right and are cropped, whereas custom-control-fields are correct.

It could be possible that those two may be related.
Is there anything in your RV data / code that may cause this?

This is how I call the painting:

Code: Select all

// Draw all vector-like into given dc with transparent background.
procedure AARichViewEditControl.DrawToDC(deviceContext: HDC; rect: TRect);
var
    AARVData: AARichViewRVData;
    origin : TPoint;
    i : Integer;
    control: AARichViewCustomControl;
begin
    AARVData := RVData as AARichViewRVData;
    AARVData.PaintToDC(deviceContext, rect);
    SetViewportOrgEx(deviceContext, rect.Left, rect.Top, @origin);
    for i := 0 to ControlCount - 1 do
        if (Controls[i] is AARichViewCustomControl) then
        begin
            control := Controls[i] as AARichViewCustomControl;
            control.PaintToDC(deviceContext);
        end;
        SetViewportOrgEx(deviceContext, origin.X, origin.Y, nil);
end;

Code: Select all

procedure AARichViewRVData.PaintToDC(hdc: HDC; rect: TRect);
var
    Canvas: TCanvas;
    r: TRect;
    origin: TPoint;
begin
  SetViewportOrgEx(hdc, rect.Left, rect.Top, @origin);
  Canvas := TCanvas.Create;
  Canvas.Handle := hdc;

  r := rect;
  OffsetRect(r, -r.left, -r.top);

  try
    PaintTo(Canvas, r);
  except
    on E: Exception do begin
    end;
  end;

  Canvas.Handle := 0;
  Canvas.Free;
  SetViewportOrgEx(hdc, origin.X, origin.Y, nil);
end;
Thank you for your help!
-- Lutz
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Try to draw in bitmap, does the problem persist?
Post Reply