6 use lib 'ext/Font-TTF/lib';
 
  15 Obfuscates fonts by deleting data that is not necessary for their use in web
 
  16 browsers. They should still work via \@font-face, but are a bit harder to
 
  17 install and use in other applications.
 
  18 The generated font will be invalid, so there are no guarantees of correct
 
  19 operation - be careful to test it with all current and future browsers that
 
  20 you want it to work in.
 
  23   $0 [options] [inputfile.ttf] [outputfile.ttf]
 
  26   --verbose, -v         print various details about the font
 
  27   At least one of the following is required:
 
  28   --all                 activate all of the options below
 
  29   --names               strip font name strings
 
  30   --post                strip PostScript glyph names
 
  36     my ($font, $id, $val, $verbose) = @_;
 
  37     my $str = $font->{name}{strings}[$id];
 
  38     for my $plat (0..$#$str) {
 
  39         next unless $str->[$plat];
 
  40         for my $enc (0..$#{$str->[$plat]}) {
 
  41             next unless $str->[$plat][$enc];
 
  42             for my $lang (keys %{$str->[$plat][$enc]}) {
 
  43                 next unless exists $str->[$plat][$enc]{$lang};
 
  45                     print "Setting string $_ (plat $plat, enc $enc) to \"$val\"\n";
 
  47                 $str->[$plat][$enc]{$lang} = $val;
 
  54     my ($font, $verbose) = @_;
 
  56     print "Stripping names\n" if $verbose;
 
  61         if ($verbose and $font->{name}{strings}[$_]) {
 
  62             print "Deleting string $_\n";
 
  64         $font->{name}{strings}[$_] = undef;
 
  68         set_name($font, $_, '', $verbose);
 
  72         set_name($font, $_, '-', $verbose);
 
  77     my ($font, $verbose) = @_;
 
  79     print "Stripping post table\n" if $verbose;
 
  81     # Replace it with the minimum necessary to work in browsers
 
  82     # (particularly Opera is a bit fussy)
 
  83     my $data = pack NNnnNNNNN => 0x10000, 0,  0, 0,  0, 0, 0, 0, 0;
 
  84     $font->{post} = new Font::TTF::Table(dat => $data);
 
  93     my $result = GetOptions(
 
  94         'verbose' => \$verbose,
 
 100     @ARGV == 2 or help();
 
 102     if (not ($all or $names or $post)) { help(); }
 
 104     my ($input_file, $output_file) = @ARGV;
 
 106     my $font = Font::TTF::Font->open($input_file) or die "Error opening $input_file: $!";
 
 108     strip_names($font, $verbose) if $all or $names;
 
 109     strip_post($font, $verbose) if $all or $post;
 
 111     $font->out($output_file);