font: numbered fonts; os groups in include
[sheet.git] / tools / mkttfinfo
index f69bbbb95e79adf89da39c2de64cb2420c99034b..1d8e69906269d95af82fb6844798c4b126f9d06d 100755 (executable)
@@ -5,12 +5,27 @@ 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;
 }
@@ -47,11 +62,14 @@ my %FONTID = (
                        }
                } $ttf->{head}->getdate),
        );
-       $meta{id} = $FONTID{ $meta{name} } // lc $ttfname;
-       say pp(\%meta), ',';
+       $meta{abbr} = $FONTID{ $meta{name} } // lc $ttfname;
+
+       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);
 }
 
@@ -63,7 +81,7 @@ mkttfinfo - Extract character coverage and metadata in TrueType font
 
 =head1 SYNOPSIS
 
-    mkttfinfo <font.ttf> [<output.inc.pl>]
+    mkttfinfo [-v] <font.ttf> [<output.inc.pl>]
 
 =head1 AUTHOR