2 # use the -CA flag so @ARGV is interpreted as UTF-8
7 use lib 'ext/Font-TTF/lib';
17 $0 [options] [inputfile.ttf] [outputfile.ttf]
20 --chars=STRING characters to include in the subset (defaults to "test")
21 --charsfile=FILE utf8-encoded file containing characters to include
22 --verbose, -v print various details about the font and the subsetting
23 --include=FEATURES comma-separated list of feature tags to include
24 (all others will be excluded by default)
25 --exclude=FEATURES comma-separated list of feature tags to exclude
26 (all others will be included by default)
27 --apply=FEATURES comma-separated list of feature tags to apply to the
28 font directly (folding into the cmap table),
29 e.g. "smcp" to replace all letters with small-caps
30 versions. (You should use --include/--exclude to remove
31 the features, so they don't get applied a second time
33 --licensesubst=STRING substitutes STRING in place of the string \${LICENSESUBST}
34 in the font's License Description
46 my $license_desc_subst;
48 my $result = GetOptions(
50 'charsfile=s' => \$charsfile,
51 'verbose' => \$verbose,
52 'include=s' => \$include,
53 'exclude=s' => \$exclude,
55 'licensesubst=s' => \$license_desc_subst,
58 if (defined $chars and defined $charsfile) {
59 print "ERROR: Only one of '--chars' and --charsfile' can be specified\n\n";
61 } elsif (defined $chars) {
63 } elsif (defined $charsfile) {
64 open my $f, '<', $charsfile or die "Failed to open $charsfile: $!";
74 my ($input_file, $output_file) = @ARGV;
78 dump_sizes($input_file);
79 print "Generating subsetted font...\n\n";
84 $features = { DEFAULT => 0 };
85 $features->{$_} = 1 for split /,/, $include;
87 $features = { DEFAULT => 1 };
88 $features->{$_} = 0 for split /,/, $exclude;
93 $fold_features = [ split /,/, $apply ];
96 my $subsetter = new Font::Subsetter();
97 $subsetter->subset($input_file, $chars, {
98 features => $features,
99 fold_features => $fold_features,
100 license_desc_subst => $license_desc_subst,
102 $subsetter->write($output_file);
106 print "Features:\n ";
107 print join ' ', $subsetter->feature_status();
109 print "Included glyphs:\n ";
110 print join ' ', $subsetter->glyph_names();
112 dump_sizes($output_file);
115 $subsetter->release();
120 my $font = Font::TTF::Font->open($filename) or die "Failed to open $filename: $!";
121 print "TTF table sizes:\n";
123 for (sort keys %$font) {
125 my $l = $font->{$_}{' LENGTH'};
129 print "Total size: $s bytes\n\n";