eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

How to draw an arc on screen, printer and PDF canvas using Windows GDI calls?

Using the Windows GDI Arc function to draw arcs on screen and eDocEngine’s PDF canvas
By Mamatha K.

eDocEngine VCL provides document creation components for several formats. We call these components document creation engines. The document creation engines also provide a GDI canvas to draw page content on to. So everything that can be drawn to a printer or screen canvas can be drawn on the engine’s canvas to create a PDF, HTML, RTF or other format of the contents on each page canvas. Since it’s a full GDI canvas, we can use GDI shape drawing functions for drawing shapes such as Arcs, Rectangles, Chords, Pies, etc.

Using the GDI Arc function may require some additional help. In this article , we will see how to draw an arc using the GDI Arc function, first, on a screen canvas and then make an identical call on the PDF engine’s canvas to produce a PDF.

I would like to quote below the clear explanation about drawing an Arc on a GDI canvas given by Jo, a Delphi developer in Bristol, England .

  1. The first thing to do is draw a rectangle on a piece of paper that would mark the boundaries of your ENTIRE ellipse if it were fully drawn on your canvas and mark out its top-left, top-right, bottom-left and bottom-right co-ordinates. From this rectangle you will need the top left and bottom right co-ordinates. These will become the first four parameters used in the arc procedure.
  2. Once you've drawn the boundary rectangle you need to identify the starting point of your arc on the boundary rectangle. Remember that the arc moves anti-clockwise. From this you will need the x an y co-ordinates
  3. Then identify the stopping point of your arc on the boundary rectangle. Remember that the arc moves anti-clockwise. From this you will need the x an y co-ordinates.
  4. The x and y co-ordinates from steps 2 and 3 make up the last four parameters used in the arc procedure.
For example if my boundary rectangle was 200 pixels wide and 100 pixels high it's parameters would be 0,0,200,100 and if I wanted to draw a quarter arc in the top left of the rectangle then it would start at co-ordinate 100,0 and end at co-ordinate 0,50 (ie: both these co-ordinates intersect the boundary rectangle) so the final Arc parameters would be Canvas.Arc(0,0,200,100,100,0,0,50) Likewise if I wanted to draw a semi-circle type arc across the top of the rectangle then the starting position of the arc would change to 200,50 and the end co-ordinate would stay as 0,50 giving you an Arc Parameter of (0,0,200,100,200,50,0,50)

Below is the pictorial representation of the call Canvas.Arc(0,0,200,100,100,0,0,50)

Below code draws Arc on the form canvas:

procedure TForm17.Button1Click(Sender: TObject);
begin  
    // Draw arc on Form canvas
    Canvas.Arc(0,0,200,100,100,0,0,50);
end;

This is the output on Form Canvas:

Let us draw the Arc on eDocEngine's PDF Engine

Here is the code snippet:

procedure TForm1.Button2Click(Sender: TObject);
var
  gtPDFEngine1: TgtPDFEngine;
begin
  gtPDFEngine1 := TgtPDFEngine.Create(nil);
  with gtPDFEngine1 do
  begin
    // Set file name
    FileName := 'Arc.pdf';
    // Set Measurement units to points
    MeasurementUnit := mupoints;
    // Create PDF
    BeginDoc;
    // Draw Arc
    Arc(0, 0, 200, 100, 100, 0, 0, 50);
    // Save PDF
    EndDoc;
  end;
end;

Here is the output PDF

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.