191 lines
3.8 KiB
Plaintext
191 lines
3.8 KiB
Plaintext
Uses TSPdfEnumerations;
|
|
{$IFDEF LINUX}
|
|
separator := "/";
|
|
{$ELSE}
|
|
separator := "\\";
|
|
{$ENDIF}
|
|
|
|
alias := "";
|
|
path := "";
|
|
InitCmdParams(alias, path);
|
|
output_file := "arc_demo.pdf";
|
|
output_file := path + separator + output_file;
|
|
|
|
pdf := new PdfFile();
|
|
|
|
// add a new page object.
|
|
page := pdf.AddPage();
|
|
|
|
page.SetHeight(220);
|
|
page.SetWidth(200);
|
|
|
|
// draw grid to the page
|
|
PrintGrid(pdf, page);
|
|
|
|
// draw pie chart
|
|
//
|
|
// A: 45% Red
|
|
// B: 25% Blue
|
|
// C: 15% green
|
|
// D: other yellow
|
|
|
|
// A
|
|
page.SetRGBFill(1.0, 0, 0);
|
|
page.MoveTo(100, 100);
|
|
page.LineTo(100, 180);
|
|
page.Arc(100, 100, 80, 0, 360 * 0.45);
|
|
pos := page.GetCurrentPos();
|
|
page.LineTo(100, 100);
|
|
page.Fill();
|
|
|
|
// B
|
|
page.SetRGBFill(0, 0, 1.0);
|
|
page.MoveTo(100, 100);
|
|
page.LineTo(pos[0], pos[1]);
|
|
page.Arc(100, 100, 80, 360 * 0.45, 360 * 0.7);
|
|
pos := page.GetCurrentPos();
|
|
page.LineTo(100, 100);
|
|
page.Fill();
|
|
|
|
// C
|
|
page.SetRGBFill(0, 1.0, 0);
|
|
page.MoveTo(100, 100);
|
|
page.LineTo(pos[0], pos[1]);
|
|
page.Arc(100, 100, 80, 360 * 0.7, 360 * 0.85);
|
|
pos := page.GetCurrentPos();
|
|
page.LineTo(100, 100);
|
|
page.Fill();
|
|
|
|
// D
|
|
page.SetRGBFill(1.0, 1.0, 0);
|
|
page.MoveTo(100, 100);
|
|
page.LineTo(pos[0], pos[1]);
|
|
page.Arc(100, 100, 80, 360 * 0.85, 360);
|
|
pos := page.GetCurrentPos();
|
|
page.LineTo(100, 100);
|
|
page.Fill();
|
|
|
|
// draw center circle
|
|
page.SetGrayStroke(0);
|
|
page.SetGrayFill(1);
|
|
page.Circle(100, 100, 30);
|
|
page.Fill();
|
|
|
|
// save the document to a file
|
|
err := pdf.SaveToFile(alias, output_file);
|
|
echo "SaveToFile::\t", "err := ", format("%x", err), "\toutput_file := ", output_file, "\n";
|
|
return;
|
|
|
|
|
|
Function PrintGrid(pdf, page)
|
|
Begin
|
|
height := page.GetHeight();
|
|
width := page.GetWidth();
|
|
font := pdf.GetFont("Helvetica", "");
|
|
|
|
page.SetFontAndSize(font, 5);
|
|
page.SetGrayFill(0.5);
|
|
page.SetGrayStroke(0.8);
|
|
|
|
// Draw horizontal lines
|
|
y := 0;
|
|
while y < height do
|
|
begin
|
|
if y % 10 = 0 then
|
|
page.SetLineWidth(0.5);
|
|
else begin
|
|
wid := page.GetWidth();
|
|
if wid <> 0.25 then page.SetLineWidth(0.25);
|
|
end
|
|
|
|
page.MoveTo(0, y);
|
|
page.LineTo(width, y);
|
|
page.Stroke();
|
|
|
|
if y % 10 = 0 and y > 0 then
|
|
begin
|
|
page.SetGrayStroke(0.5);
|
|
|
|
page.MoveTo(0, y);
|
|
page.LineTo(5, y);
|
|
page.Stroke();
|
|
page.SetGrayStroke(0.8);
|
|
end
|
|
|
|
y += 5;
|
|
end
|
|
|
|
|
|
// Draw vertical lines
|
|
x := 0;
|
|
while x < width do
|
|
begin
|
|
if x % 10 = 0 then
|
|
page.SetLineWidth(0.5);
|
|
else begin
|
|
wid := page.GetWidth();
|
|
if wid <> 0.25 then page.SetLineWidth(0.25);
|
|
end
|
|
|
|
page.MoveTo(x, 0);
|
|
page.LineTo(x, height);
|
|
page.Stroke();
|
|
|
|
if x % 50 = 0 and x > 0 then
|
|
begin
|
|
page.SetGrayStroke(0.5);
|
|
|
|
page.MoveTo(x, 0);
|
|
page.LineTo(x, 5);
|
|
page.Stroke();
|
|
|
|
page.MoveTo(x, height);
|
|
page.LineTo(x, height - 5);
|
|
page.Stroke();
|
|
|
|
page.SetGrayStroke(0.8);
|
|
end
|
|
|
|
x += 5;
|
|
end
|
|
|
|
// Draw horizontal text
|
|
y := 0;
|
|
while y < height do
|
|
begin
|
|
if y % 10 = 0 and y > 0 then
|
|
begin
|
|
page.BeginText();
|
|
page.MoveTextPos(5, y - 2);
|
|
page.ShowText(tostring(y));
|
|
page.EndText();
|
|
end
|
|
y += 5;
|
|
end
|
|
|
|
|
|
// Draw vertical text
|
|
x := 0;
|
|
while x < width do
|
|
begin
|
|
if x % 50 = 0 and x > 0 then
|
|
begin
|
|
buf := tostring(x);
|
|
page.BeginText();
|
|
page.MoveTextPos(x, 5);
|
|
page.ShowText(buf);
|
|
page.EndText();
|
|
|
|
page.BeginText();
|
|
page.MoveTextPos(x, height - 10);
|
|
page.ShowText(buf);
|
|
page.EndText();
|
|
end
|
|
|
|
x += 5;
|
|
end
|
|
|
|
page.SetGrayFill(0);
|
|
page.SetGrayStroke(0);
|
|
End;
|