Debian Codegraph @

contrib/perl/examples/typeset.pl

raw
1 # SPDX-License-Identifier: Artistic-1.0-Perl
2 # Copyright (C) 2011 Simon Cozens
3 use PDF::API2;
4 use Text::Gr2;
5 use File::Slurp;
6 my ($fontfile, $textfile) = @ARGV;
7
8 push @PDF::API2::FontDirs, "/Library/Fonts", "/Users/simon/Library/Fonts";
9
10 my $graf = read_file($textfile);
11 my $face = Text::Gr2::Face->open("/Users/simon/Library/Fonts/$fontfile",
12 cache_size => 1000,
13 preload_glyphs => 1);
14 die "Invalid font, failed to read or parse tables\n" unless $face;
15
16 my $sized_font = $face->make_font(12);
17 my $pdf = PDF::API2->new(-file => "test.pdf");
18 $pdf->mediabox("A4");
19 my $page = $pdf->page;
20 our $font = $pdf->ttfont($fontfile) || die "No PDF font found";
21 my $text = $page->text;
22 $text->font($font,12);
23
24 my $seg = $sized_font->segment($face, $graf);
25 my @slots = $seg->slots;
26 my @cinfos = $seg->cinfos;
27 for (0..$#slots) {
28 $text->translate(20 + $slots[$_]->origin_X,200 + $slots[$_]->origin_Y);
29 print $slots[$_]->origin_X,"\t", $cinfos[$_]->unicode_char,"\n";
30 $text->text(chr($cinfos[$_]->unicode_char()));
31 }
32 $pdf->save;