3 # -CA flag is forbidden in #! line
5 @ARGV = map { decode 'utf-8', $_ } @ARGV;
10 use lib 'ext/Font-TTF/lib';
20 $0 [options] [inputfile.ttf] [outputfile.ttf]
23 --chars=STRING characters to include in the subset (defaults to "test")
24 --charsfile=FILE utf8-encoded file containing characters to include
25 --verbose, -v print various details about the font and the subsetting
26 --include=FEATURES comma-separated list of feature tags to include
27 (all others will be excluded by default)
28 --exclude=FEATURES comma-separated list of feature tags to exclude
29 (all others will be included by default)
30 --apply=FEATURES comma-separated list of feature tags to apply to the
31 font directly (folding into the cmap table),
32 e.g. "smcp" to replace all letters with small-caps
33 versions. (You should use --include/--exclude to remove
34 the features, so they don't get applied a second time
36 --licensesubst=STRING substitutes STRING in place of the string \${LICENSESUBST}
37 in the font's License Description
49 my $license_desc_subst;
51 my $result = GetOptions(
53 'charsfile=s' => \$charsfile,
54 'verbose' => \$verbose,
55 'include=s' => \$include,
56 'exclude=s' => \$exclude,
58 'licensesubst=s' => \$license_desc_subst,
61 if (defined $chars and defined $charsfile) {
62 print "ERROR: Only one of '--chars' and --charsfile' can be specified\n\n";
64 } elsif (defined $chars) {
66 } elsif (defined $charsfile) {
67 open my $f, '<', $charsfile or die "Failed to open $charsfile: $!";
77 my ($input_file, $output_file) = @ARGV;
81 dump_sizes($input_file);
82 print "Generating subsetted font...\n\n";
87 $features = { DEFAULT => 0 };
88 $features->{$_} = 1 for split /,/, $include;
90 $features = { DEFAULT => 1 };
91 $features->{$_} = 0 for split /,/, $exclude;
96 $fold_features = [ split /,/, $apply ];
99 my $subsetter = new Font::Subsetter();
100 $subsetter->subset($input_file, $chars, {
101 features => $features,
102 fold_features => $fold_features,
103 license_desc_subst => $license_desc_subst,
105 $subsetter->write($output_file);
109 print "Features:\n ";
110 print join ' ', $subsetter->feature_status();
112 print "Included glyphs:\n ";
113 print join ' ', $subsetter->glyph_names();
115 dump_sizes($output_file);
118 $subsetter->release();
123 my $font = Font::TTF::Font->open($filename) or die "Failed to open $filename: $!";
124 print "TTF table sizes:\n";
126 for (sort keys %$font) {
128 my $l = $font->{$_}{' LENGTH'};
132 print "Total size: $s bytes\n\n";