Page 1 of 1

2 pixel cropped when drawing into device context

Posted: Tue Apr 18, 2006 2:51 am
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

Posted: Tue Apr 18, 2006 10:27 am
by Sergey Tkachenko
Try to draw in bitmap, does the problem persist?