1 package Font::TTF::Feat;
5 Font::TTF::Feat - Font Features
9 =head1 INSTANCE VARIABLES
17 An array of hashes of the following form
27 name index in name table
35 hash of setting number against name string index
50 require Font::TTF::Table;
52 @ISA = qw(Font::TTF::Table);
56 Reads the features from the TTF file into memory
63 my ($featureCount, $features);
65 $self->SUPER::read_dat or return $self;
67 ($self->{'version'}, $featureCount) = TTF_Unpack("vS", $self->{' dat'});
70 foreach (1 .. $featureCount) {
71 my ($feature, $nSettings, $settingTable, $featureFlags, $nameIndex)
72 = TTF_Unpack("SSLSS", substr($self->{' dat'}, $_ * 12, 12));
75 'feature' => $feature,
77 'exclusive' => (($featureFlags & 0x8000) != 0),
78 'settings' => { TTF_Unpack("S*", substr($self->{' dat'}, $settingTable, $nSettings * 4)) }
81 $self->{'features'} = $features;
83 delete $self->{' dat'}; # no longer needed, and may become obsolete
90 Writes the features to a TTF file
97 my ($features, $numFeatures, $settings, $featuresData, $settingsData);
99 return $self->SUPER::out($fh) unless $self->{' read'};
101 $features = $self->{'features'};
102 $numFeatures = @$features;
104 foreach (@$features) {
105 $settings = $_->{'settings'};
106 $featuresData .= TTF_Pack("SSLSS",
108 scalar keys %$settings,
109 12 + 12 * $numFeatures + length $settingsData,
110 ($_->{'exclusive'} ? 0x8000 : 0x0000),
112 foreach (sort {$a <=> $b} keys %$settings) {
113 $settingsData .= TTF_Pack("SS", $_, $settings->{$_});
117 $fh->print(TTF_Pack("vSSL", $self->{'version'}, $numFeatures, 0, 0));
118 $fh->print($featuresData);
119 $fh->print($settingsData);
124 =head2 $t->print($fh)
126 Prints a human-readable representation of the table
132 my ($self, $fh) = @_;
133 my ($names, $features, $settings);
137 $names = $self->{' PARENT'}->{'name'};
140 $fh = 'STDOUT' unless defined $fh;
142 $features = $self->{'features'};
143 foreach (@$features) {
144 $fh->printf("Feature %d, %s, name %d # '%s'\n",
146 ($_->{'exclusive'} ? "exclusive" : "additive"),
148 $names->{'strings'}[$_->{'name'}][1][0]{0});
149 $settings = $_->{'settings'};
150 foreach (sort { $a <=> $b } keys %$settings) {
151 $fh->printf("\tSetting %d, name %d # '%s'\n",
152 $_, $settings->{$_}, $names->{'strings'}[$settings->{$_}][1][0]{0});
161 my ($self, $feature, $setting) = @_;
165 my $names = $self->{' PARENT'}->{'name'};
168 my $features = $self->{'features'};
169 my ($featureEntry) = grep { $_->{'feature'} == $feature } @$features;
170 my $featureName = $names->{'strings'}[$featureEntry->{'name'}][1][0]{0};
171 my $settingName = $featureEntry->{'exclusive'}
172 ? $names->{'strings'}[$featureEntry->{'settings'}->{$setting}][1][0]{0}
173 : $names->{'strings'}[$featureEntry->{'settings'}->{$setting & ~1}][1][0]{0}
174 . (($setting & 1) == 0 ? " On" : " Off");
176 ($featureName, $settingName);
187 Jonathan Kew L<Jonathan_Kew@sil.org>. See L<Font::TTF::Font> for copyright and