#!/usr/bin/env perl use 5.014; use strict; use warnings; use Data::Dump 'pp'; use Font::TTF::Font; use Getopt::Long; use Cwd 'abs_path'; our $VERSION = '1.00'; GetOptions(\my %opt, 'verbose|v!', ); my ($ttfuri, $outfile) = @ARGV; $ttfuri or die "usage error\n"; my $fontinc = $ENV{FONTINC} // 'data/font,~/.fonts,/usr/share/fonts/truetype/*'; if (!-e $ttfuri) { my $found = (grep {-e} glob "{$fontinc}/$ttfuri")[0] or do { warn "font not found: $ttfuri\n"; exit 1; }; $ttfuri = $found; } for ($outfile || ()) { open my $output, '>', $_ or die "Cannot write to $outfile: $!\n"; select $output; } { my $ttf = Font::TTF::Font->open($ttfuri) or die "Cannot open truetype in $ttfuri: $!"; my $ttfname = ($ttfuri =~ m{([^/.]+) (?:[.]ttf)? \z}msx)[0]; my $ttfmeta = $ttf->{name}->read; my %meta = ( source => abs_path($ttfuri) =~ m{(^/usr/.+ | [^/]+) \z}msx, name => $ttfmeta->find_name(4) || $ttfname, revision => sprintf('%g', $ttf->{head}->{fontRevision}), version => $ttfmeta->find_name(5) =~ s/\Aversion //ri =~ s/\s+\z//r, copyright=> scalar $ttfmeta->find_name(0), license => $ttfmeta->find_name(14) || undef, date => (map { $_ && eval { require Time::Piece; Time::Piece->new($_)->datetime; } } $ttf->{head}->getdate), ); $meta{abbr} = lc join '', $meta{name} =~ s/ MS$//r =~ m{ (?!Sans) (?{cmap}->find_ms->{val}; warn scalar keys %$support, " characters read from $ttfname\n" if $opt{verbose}; say pp(sort { $a <=> $b } keys %$support); } __END__ =head1 NAME mkttfinfo - Extract character coverage and metadata in TrueType font =head1 SYNOPSIS mkttfinfo [-v] [] =head1 AUTHOR Mischa POSLAWSKY =head1 LICENSE Licensed under the GNU Affero General Public License version 3.