Version bump.
[librarian.git] / librarian / font-optimizer / convert-eot.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 'ext/Font-TTF/lib';
7 use Font::TTF::Font;
8 use Font::EOTWrapper;
9
10 use Getopt::Long;
11
12 main();
13
14 sub help {
15     print <<EOF;
16 Convert between TTF and EOT. (Compressed EOTs are not supported.)
17
18 Usage:
19   $0 [options] [inputfile] [outputfile]
20
21 Options:
22   --ttf-to-eot    Convert input from TTF to EOT
23   --eot-to-ttf    Convert input from EOT to TTF
24 EOF
25     exit 1;
26 }
27
28 sub main {
29     my $verbose = 0;
30     my $ttf_to_eot;
31     my $eot_to_ttf;
32
33     my $result = GetOptions(
34         'verbose' => \$verbose,
35         'ttf-to-eot' => \$ttf_to_eot,
36         'eot-to-ttf' => \$eot_to_ttf,
37     ) or help();
38
39     @ARGV == 2 or help();
40
41     my ($input_file, $output_file) = @ARGV;
42
43     if ($ttf_to_eot and $eot_to_ttf) {
44         help();
45     }
46
47     if (not ($ttf_to_eot or $eot_to_ttf)) {
48         if ($input_file =~ /\.[ot]tf$/i and $output_file =~ /\.eot$/i) {
49             $ttf_to_eot = 1;
50         } elsif ($input_file =~ /\.eot$/i and $output_file =~ /\.[ot]tf$/i) {
51             $eot_to_ttf = 1;
52         } else {
53             help();
54         }
55     }
56
57     if ($ttf_to_eot) {
58         Font::EOTWrapper::convert($input_file, $output_file);
59     } elsif ($eot_to_ttf) {
60         Font::EOTWrapper::extract($input_file, $output_file);
61     }
62 }