John
John

Reputation: 1915

how to draw rotated part of the canvas in D-7?

I am drawing something on an A3 printer canvas.

Is it possible to copy the part of the canvas and draw rotated (180degree) in another part of the canvas?

Thanks!

Upvotes: 1

Views: 2645

Answers (2)

NGLN
NGLN

Reputation: 43664

Like Sertac commented already, use SetWorldTransform:

procedure TForm1.Button1Click(Sender: TObject);
var
  XForm: TXForm;
begin
  if PrintDialog1.Execute then
    with Printer do
    begin
      BeginDoc;
      SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
      PrintTo(Canvas);
      XForm.eM11 := Cos(DegToRad(180));
      XForm.eM12 := Sin(DegToRad(180));
      XForm.eM21 := -Sin(DegToRad(180));
      XForm.eM22 := Cos(DegToRad(180));
      XForm.eDx := PageWidth;
      XForm.eDy := PageHeight;
      SetWorldTransform(Canvas.Handle, XForm);
      PrintTo(Canvas);
      EndDoc;
    end;
end;

procedure TForm1.PrintTo(ACanvas: TCanvas);
begin
  with ACanvas do
  begin
    Font.Size := 180;
    TextOut(0, 0, 'Test text');
    Pen.Width := 40;
    MoveTo(0, 0);
    LineTo(3000, 3000);
  end;
end;

enter image description here

Upvotes: 8

NGLN
NGLN

Reputation: 43664

You could paint the repetitive part to a temporary bitmap, and draw that bitmap twice on the printer's canvas, once rotated. The rotation could be done for instance with PlgBlt:

procedure RotateBitmap180(Source, Dest: TBitmap);
var
  Points: array[0..2] of TPoint;
begin
  if (Source <> nil) and (Dest <> nil) then
    with Source, Canvas do
    begin
      Dest.Width := Width;
      Dest.Height := Height;
      Points[0].X := Width - 1;
      Points[0].Y := Height - 1;
      Points[1].X := -1;
      Points[1].Y := Height - 1;
      Points[2].X := Width - 1;
      Points[2].Y := -1;
      PlgBlt(Dest.Canvas.Handle, Points, Handle, 0, 0, Width, Height, 0, 0, 0);
      Dest.Modified := True;
    end;
end;

Note: there are way more efficient rotation routines available, since PlgBlt not only rotates but also scales. But this short one does the job.

Upvotes: 0

Related Questions