font: support reading .ttc truetype collection files
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 16 Mar 2015 17:19:04 +0000 (18:19 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Jun 2015 03:43:44 +0000 (05:43 +0200)
Format of most original mac fonts.

tools/mkttfinfo

index 72564bffa9e656f16103fa91d4ef285a0d484291..9679f1c70f906b0f774356a30c3d845a40b348e3 100755 (executable)
@@ -30,8 +30,15 @@ for ($outfile || ()) {
 }
 
 {
 }
 
 {
-       my $ttf = Font::TTF::Font->open($ttfuri) or do {
-               warn "Cannot open truetype in $ttfuri: $!";
+       my $ttf = eval {
+               if ($ttfuri =~ /\.ttc\z/) {
+                       require Font::TTF::Ttc;
+                       my $collection = Font::TTF::Ttc->open($ttfuri) or die $!;
+                       return $collection->{directs}->[0];  # first sub-font object
+               }
+               return Font::TTF::Font->open($ttfuri);
+       } or do {
+               warn "Cannot open font file $ttfuri: ", $@ // $!;
                exit 65; # EX_DATAERR
        };
 
                exit 65; # EX_DATAERR
        };