font: script to generate coverage data from ttf files
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 4 Jan 2011 20:25:35 +0000 (21:25 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 10 Apr 2012 01:03:24 +0000 (03:03 +0200)
tools/convert-ttf.pl [new file with mode: 0755]

diff --git a/tools/convert-ttf.pl b/tools/convert-ttf.pl
new file mode 100755 (executable)
index 0000000..3a7cc0e
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+use 5.010;
+use strict;
+use warnings;
+
+use Data::Dump 'pp';
+use Font::TTF::Font;
+
+my ($ttfname, $outfile) = @ARGV;
+
+for ($outfile || ()) {
+       !-e $_ or die "Output file $outfile already exists\n";
+       open my $output, '>', $_ or die "Cannot write to $outfile: $!\n";
+       select $output;
+}
+
+{
+       my $ttf = Font::TTF::Font->open($ttfname)
+               or die "Cannot open truetype in $ttfname: $!";
+
+       my %meta = (
+               filename => $ttfname,
+               name     => $ttf->{name}->read->find_name(4) || $ttfname,
+               version  => $ttf->{head}->{fontRevision},
+               date     => (map {
+                       $_ && eval {
+                               require Time::Piece;
+                               Time::Piece->new($_)->datetime;
+                       }
+               } $ttf->{head}->getdate),
+       );
+       say pp(\%meta), ',';
+
+       my $support = $ttf->{cmap}->find_ms->{val};
+       warn scalar keys %$support, " characters read from $ttfname\n";
+       say pp(sort { $a <=> $b } keys %$support);
+}
+
+__END__
+
+=head1 NAME
+
+convert-ttf.pl - Writes unicode characters present in TrueType font
+
+=head1 SYNOPSIS
+
+    convert-ttf <font.ttf> [<output.inc.pl>]
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 LICENSE
+
+Licensed under the GNU Affero General Public License version 3.
+