312 lines
6.3 KiB
Plaintext
312 lines
6.3 KiB
Plaintext
Uses TSPdfEnumerations;
|
|
{$IFDEF LINUX}
|
|
separator := "/";
|
|
{$ELSE}
|
|
separator := "\\";
|
|
{$ENDIF}
|
|
|
|
alias := "";
|
|
path := "";
|
|
InitCmdParams(alias, path);
|
|
output_file := "text_demo2.pdf";
|
|
output_file := path + separator + output_file;
|
|
|
|
no := 0;
|
|
|
|
pdf := new PdfFile();
|
|
SAMP_TXT := "The quick brown fox jumps over the lazy dog. ";
|
|
|
|
// add a new page object.
|
|
page := pdf.AddPage();
|
|
page.SetSize(TSPdfEnumerations.PAGE_SIZE_A5, TSPdfEnumerations.PAGE_PORTRAIT);
|
|
|
|
PrintGrid(pdf, page);
|
|
|
|
height := page.GetHeight();
|
|
|
|
font := pdf.GetFont("Helvetica", "");
|
|
page.SetTextLeading(20);
|
|
|
|
// TALIGN_LEFT
|
|
left := 25;
|
|
top := 545;
|
|
right := 200;
|
|
bottom := top - 40;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "TSPdfEnumerations.TALIGN_LEFT");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_LEFT, "");
|
|
|
|
page.EndText();
|
|
|
|
// TALIGN_RIGTH
|
|
left := 220;
|
|
right := 395;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "TSPdfEnumerations.TALIGN_RIGTH");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_RIGHT, "");
|
|
|
|
page.EndText();
|
|
|
|
// TALIGN_CENTER
|
|
left := 25;
|
|
top := 475;
|
|
right := 200;
|
|
bottom := top - 40;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "TSPdfEnumerations.TALIGN_CENTER");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_CENTER, "");
|
|
|
|
page.EndText();
|
|
|
|
// TALIGN_JUSTIFY
|
|
left := 220;
|
|
right := 395;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "TSPdfEnumerations.TALIGN_JUSTIFY");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_JUSTIFY, "");
|
|
page.EndText();
|
|
|
|
|
|
|
|
// Skewed coordinate system
|
|
page.GSave();
|
|
angle1 := 5;
|
|
angle2 := 10;
|
|
rad1 := angle1 / 180 * 3.141592;
|
|
rad2 := angle2 / 180 * 3.141592;
|
|
|
|
page.Concat(1, tan(rad1), tan(rad2), 1, 25, 350);
|
|
left := 0;
|
|
top := 40;
|
|
right := 175;
|
|
bottom := 0;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "Skewed coordinate system");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_LEFT, "");
|
|
|
|
page.EndText();
|
|
|
|
page.GRestore();
|
|
|
|
|
|
// Rotated coordinate system
|
|
page.GSave();
|
|
|
|
angle1 := 5;
|
|
rad1 := angle1 / 180 * 3.141592;
|
|
|
|
page.Concat(cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 220, 350);
|
|
left := 0;
|
|
top := 40;
|
|
right := 175;
|
|
bottom := 0;
|
|
|
|
page.Rectangle(left, bottom, right - left, top - bottom);
|
|
page.Stroke();
|
|
|
|
page.BeginText();
|
|
|
|
page.SetFontAndSize(font, 10);
|
|
page.TextOut(left, top + 3, "Rotated coordinate system");
|
|
|
|
page.SetFontAndSize(font, 13);
|
|
page.TextRect(left, top, right, bottom, SAMP_TXT, TSPdfEnumerations.TALIGN_LEFT, "");
|
|
|
|
page.EndText();
|
|
|
|
page.GRestore();
|
|
|
|
|
|
// text along a circle
|
|
page.SetGrayStroke(0);
|
|
page.Circle(210, 190, 145);
|
|
page.Circle(210, 190, 113);
|
|
page.Stroke();
|
|
|
|
angle1 := 360 /(length(SAMP_TXT));
|
|
angle2 := 180;
|
|
|
|
page.BeginText();
|
|
font := pdf.GetFont("Courier-Bold", "");
|
|
page.SetFontAndSize(font, 30);
|
|
|
|
for i:=0 to length(SAMP_TXT)-1 do
|
|
begin
|
|
rad1 := (angle2 - 90) / 180 * 3.141592;
|
|
rad2 := angle2 / 180 * 3.141592;
|
|
|
|
x := 210 + cos(rad2) * 122;
|
|
y := 190 + sin(rad2) * 122;
|
|
|
|
page.SetTextMatrix(cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y);
|
|
page.ShowText(SAMP_TXT[i+1]);
|
|
angle2 -= angle1;
|
|
end
|
|
|
|
page.EndText();
|
|
|
|
// 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 PrintText(page, no)
|
|
Begin
|
|
point := page.GetCurrentTextPos();
|
|
no++;
|
|
buf := format("[.%d%0.2f %0.2f%]", no, point[0], point[1]);
|
|
page.ShowText(buf);
|
|
End
|
|
|
|
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;
|