#!/usr/bin/env perl
-use 5.010;
+use 5.014;
use strict;
use warnings;
use Data::Dump 'pp';
use Font::TTF::Font;
+use Getopt::Long;
+
+our $VERSION = '1.00';
+
+GetOptions(my %opt,
+ 'verbose|v!',
+);
my ($ttfuri, $outfile) = @ARGV;
$ttfuri or die "usage error\n";
+my $fontinc = $ENV{FONTINC} // '~/.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 || ()) {
- !-e $_ or die "Output file $outfile already exists\n";
open my $output, '>', $_ or die "Cannot write to $outfile: $!\n";
select $output;
}
-my %FONTID = (
- 'Times New Roman' => 'times',
- 'DejaVu Sans' => 'dv ss',
- 'DejaVu Serif' => 'dv serif',
- 'DejaVu Sans Mono'=> 'dv mono',
- 'Code2000' => 'c2k',
- 'GNU Unifont' => 'guf',
- 'Droid Sans' => 'droid',
- 'Droid Serif' => 'droid serif',
- 'Droid Sans Mono' => 'droid mono',
-);
-
{
my $ttf = Font::TTF::Font->open($ttfuri)
or die "Cannot open truetype in $ttfuri: $!";
}
} $ttf->{head}->getdate),
);
- $meta{id} = $FONTID{ $meta{name} } // lc $ttfname;
- say pp(\%meta), ',';
+ $meta{abbr} = lc join '', $meta{name} =~ s/ MS$//r =~ m{
+ (?!Sans) (?<! [0-9]) ([[:upper:]0-9])
+ }gx;
+
+ say "# automatically generated by $0";
+ say '+', pp(\%meta), ',';
my $support = $ttf->{cmap}->find_ms->{val};
- warn scalar keys %$support, " characters read from $ttfname\n";
+ warn scalar keys %$support, " characters read from $ttfname\n"
+ if $opt{verbose};
say pp(sort { $a <=> $b } keys %$support);
}
=head1 SYNOPSIS
- mkttfinfo <font.ttf> [<output.inc.pl>]
+ mkttfinfo [-v] <font.ttf> [<output.inc.pl>]
=head1 AUTHOR