176 lines
3.6 KiB
Plaintext
176 lines
3.6 KiB
Plaintext
Uses TSPdfEnumerations;
|
|
{$IFDEF LINUX}
|
|
separator := "/";
|
|
{$ELSE}
|
|
separator := "\\";
|
|
{$ENDIF}
|
|
|
|
alias := "";
|
|
path := "";
|
|
InitCmdParams(alias, path);
|
|
output_file := "encoding_list_demo.pdf";
|
|
output_file := path + separator + output_file;
|
|
|
|
pdf := new PdfFile();
|
|
|
|
// set compression mode
|
|
pdf.SetCompressionMode(TSPdfEnumerations.COMP_ALL);
|
|
|
|
// Set page mode to use outlines.
|
|
errcode := pdf.SetPageMode(TSPdfEnumerations.PAGE_MODE_USE_OUTLINE);
|
|
|
|
// get default font
|
|
font := pdf.GetFont("Helvetica", "");
|
|
|
|
// load font object
|
|
afm_file := path + separator + "type1" + separator + "a010013l.afm";
|
|
pfb_file := path + separator + "type1" + separator + "a010013l.pfb";
|
|
|
|
font_name := pdf.LoadType1FontFromFile(alias, afm_file, pfb_file);
|
|
|
|
// create outline root.
|
|
root := pdf.CreateOutline(nil, "Encoding list", nil);
|
|
root.SetOpened(true);
|
|
|
|
encodings := array(
|
|
"StandardEncoding",
|
|
"MacRomanEncoding",
|
|
"WinAnsiEncoding",
|
|
"ISO8859-2",
|
|
"ISO8859-3",
|
|
"ISO8859-4",
|
|
"ISO8859-5",
|
|
"ISO8859-9",
|
|
"ISO8859-10",
|
|
"ISO8859-13",
|
|
"ISO8859-14",
|
|
"ISO8859-15",
|
|
"ISO8859-16",
|
|
"CP1250",
|
|
"CP1251",
|
|
"CP1252",
|
|
"CP1254",
|
|
"CP1257",
|
|
"KOI8-R",
|
|
"Symbol-Set",
|
|
"ZapfDingbats-Set",
|
|
// ""
|
|
);
|
|
|
|
page_width := 420;
|
|
page_height := 400;
|
|
cell_width := 20;
|
|
cell_height := 20;
|
|
|
|
for i:=0 to length(encodings)-1 do
|
|
begin
|
|
page := pdf.AddPage();
|
|
|
|
page.SetWidth(page_width);
|
|
page.SetHeight(page_height);
|
|
|
|
outline := pdf.CreateOutline(root, encodings[i], nil);
|
|
dst := page.CreateDestination();
|
|
dst.SetXYZ(0, page_height, 1);
|
|
// pdf.Destination_SetFitB(dst);
|
|
outline.SetDestination(dst);
|
|
|
|
page.SetFontAndSize(font, 15);
|
|
DrawGraph(page, page_width, page_height, cell_width, cell_height);
|
|
|
|
page.BeginText();
|
|
page.SetFontAndSize(font, 20);
|
|
page.MoveTextPos(40, page_height - 50);
|
|
page.ShowText(encodings[i]);
|
|
page.ShowText(" Encoding");
|
|
page.EndText();
|
|
|
|
if encodings[i] = "Symbol-Set" then
|
|
font2 := pdf.GetFont("Symbol", "");
|
|
else if encodings[i] = "ZapfDingbats-Set" then
|
|
font2 := pdf.GetFont("ZapfDingbats", "");
|
|
else
|
|
font2 := pdf.GetFont(font_name, encodings[i]);
|
|
|
|
page.SetFontAndSize(font2, 14);
|
|
DrawFonts(page, page_width, page_height, cell_width, cell_height);
|
|
|
|
end
|
|
|
|
// 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 DrawGraph(page, page_width, page_height, cell_width, cell_height);
|
|
Begin
|
|
// Draw 16 X 15 cells
|
|
|
|
// Draw vertical lines.
|
|
page.SetLineWidth(0.5);
|
|
|
|
for i:=0 to 17 do
|
|
begin
|
|
x := i * cell_width + 40;
|
|
|
|
page.MoveTo(x, page_height - 60);
|
|
page.LineTo(x, 40);
|
|
page.Stroke();
|
|
|
|
if (i > 0 and i <= 16) then
|
|
begin
|
|
page.BeginText();
|
|
page.MoveTextPos(x + 5, page_height - 75);
|
|
buf := format("%x", i - 1);
|
|
page.ShowText(buf);
|
|
page.EndText();
|
|
end
|
|
end
|
|
|
|
// Draw horizontal lines.
|
|
for i:=0 to 15 do
|
|
begin
|
|
y := i * cell_height + 40;
|
|
|
|
page.MoveTo(40, y);
|
|
page.LineTo(page_width - 40, y);
|
|
page.Stroke();
|
|
|
|
if (i < 14) then
|
|
begin
|
|
page.BeginText();
|
|
page.MoveTextPos(45, y + 5);
|
|
buf := format("%x", 15 - i);
|
|
page.ShowText(buf);
|
|
page.EndText();
|
|
end
|
|
end
|
|
End;
|
|
|
|
|
|
Function DrawFonts(page, page_width, page_height, cell_width, cell_height);
|
|
Begin
|
|
page.BeginText();
|
|
|
|
// Draw all character from 0x20 to 0xFF to the canvas.
|
|
for i:=1 to 16 do
|
|
begin
|
|
for j:=1 to 16 do
|
|
begin
|
|
y := page_height - 55 - ((i - 1) * cell_height);
|
|
x := j * cell_width + 50;
|
|
|
|
n := (i - 1) * 16 + (j - 1);
|
|
if n > 256 then n := n % 256;
|
|
buf := chr(n);
|
|
if (n >= 32) then
|
|
begin
|
|
width := page.TextWidth(buf);
|
|
d := x - width / 2;
|
|
page.TextOut(d, y, buf);
|
|
end
|
|
end
|
|
end
|
|
page.EndText();
|
|
End;
|