10 our $VERSION = '1.00';
16 my ($ttfuri, $outfile) = @ARGV;
17 $ttfuri or die "usage error\n";
19 my $fontinc = $ENV{FONTINC} // '~/.fonts,/usr/share/fonts/truetype/*';
21 my $found = (grep {-e} glob "{$fontinc}/$ttfuri")[0] or do {
22 warn "font not found: $ttfuri\n";
28 for ($outfile || ()) {
29 open my $output, '>', $_ or die "Cannot write to $outfile: $!\n";
34 'Times New Roman' => 'times',
35 'DejaVu Sans' => 'dv ss',
36 'DejaVu Serif' => 'dv serif',
37 'DejaVu Sans Mono'=> 'dv mono',
39 'GNU Unifont' => 'guf',
40 'Droid Sans' => 'droid',
41 'Droid Serif' => 'droid serif',
42 'Droid Sans Mono' => 'droid mono',
46 my $ttf = Font::TTF::Font->open($ttfuri)
47 or die "Cannot open truetype in $ttfuri: $!";
49 my $ttfname = ($ttfuri =~ m{([^/.]+) (?:[.]ttf)? \z}msx)[0];
50 my $ttfmeta = $ttf->{name}->read;
52 source => $ttfuri =~ m{(^/usr/.+ | [^/]+) \z}msx,
53 name => $ttfmeta->find_name(4) || $ttfname,
54 revision => $ttf->{head}->{fontRevision},
55 version => scalar $ttfmeta->find_name(5),
56 copyright=> scalar $ttfmeta->find_name(0),
57 license => $ttfmeta->find_name(14) || undef,
61 Time::Piece->new($_)->datetime;
63 } $ttf->{head}->getdate),
65 $meta{id} = $FONTID{ $meta{name} } // lc $ttfname;
66 say "# automatically generated by $0";
67 say '+', pp(\%meta), ',';
69 my $support = $ttf->{cmap}->find_ms->{val};
70 warn scalar keys %$support, " characters read from $ttfname\n"
72 say pp(sort { $a <=> $b } keys %$support);
79 mkttfinfo - Extract character coverage and metadata in TrueType font
83 mkttfinfo [-v] <font.ttf> [<output.inc.pl>]
87 Mischa POSLAWSKY <perl@shiar.org>
91 Licensed under the GNU Affero General Public License version 3.