1 package Font::TTF::Post;
5 Font::TTF::Post - Holds the Postscript names for each glyph
9 Holds the postscript names for glyphs. Note that they are not held as an
10 array, but as indexes into two lists. The first list is the standard Postscript
11 name list defined by the TrueType standard. The second comes from the font
14 Looking up a glyph from a Postscript name or a name from a glyph number is
15 achieved through methods rather than variable lookup.
17 This class handles PostScript table types of 1, 2, 2.5 & 3, but not version 4.
18 Support for version 2.5 is as per Apple spec rather than MS.
20 The way to look up Postscript names or glyphs is:
22 $pname = $f->{'post'}{'VAL'}[$gnum];
23 $gnum = $f->{'post'}{'STRINGS'}{$pname};
25 =head1 INSTANCE VARIABLES
27 Due to different systems having different limitations, there are various class
28 variables available to control what post table types can be written.
32 =item $Font::TTF::Post::no25
34 If set tells Font::TTF::Post::out to use table type 2 instead of 2.5 in case apps
35 can't handle version 2.5.
39 Contains an array indexed by glyph number of Postscript names. This is used when
44 An associative array of Postscript names mapping to the highest glyph with that
45 name. These may not be in sync with VAL.
49 In addition there are the standard introductory variables defined in the
67 use vars qw(@ISA @base_set %base_set %fields $VERSION $no25 @field_info @base_set);
68 require Font::TTF::Table;
71 $no25 = 1; # officially deprecated format 2.5 tables in MS spec 1.3
73 @ISA = qw(Font::TTF::Table);
77 'underlinePosition' => 's',
78 'underlineThickness' => 's',
79 'isFixedPitch' => 'L',
80 'minMemType42' => 'L',
81 'maxMemType42' => 'L',
83 'maxMemType1' => 'L');
84 @base_set = qw(.notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle
85 parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six
86 seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q
87 R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h
88 i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla
89 Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute
90 egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex
91 odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet
92 paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity
93 plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine
94 ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal
95 Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash
96 quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency
97 guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand
98 Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex
99 apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent
100 ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth
101 Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter
102 threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat);
104 $VERSION = 0.01; # MJPH 5-AUG-1998 Re-organise data structures
109 for ($i = 0; $i < $#field_info; $i += 2)
111 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
112 next unless defined $k && $k ne "";
116 %base_set = map {$_ => $i++} @base_set;
122 Reads the Postscript table into memory from disk
129 my ($dat, $dat1, $i, $off, $c, $maxoff, $form, $angle, $numGlyphs);
130 my ($fh) = $self->{' INFILE'};
132 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
133 $self->SUPER::read or return $self;
134 init unless ($fields{'FormatType'});
136 TTF_Read_Fields($self, $dat, \%fields);
138 if (int($self->{'FormatType'} + .5) == 1)
140 for ($i = 0; $i < 258; $i++)
142 $self->{'VAL'}[$i] = $base_set[$i];
143 $self->{'STRINGS'}{$base_set[$i]} = $i unless (defined $self->{'STRINGS'}{$base_set[$i]});
145 } elsif (int($self->{'FormatType'} * 2 + .1) == 5)
148 $numGlyphs = unpack("n", $dat);
149 $fh->read($dat, $numGlyphs);
150 for ($i = 0; $i < $numGlyphs; $i++)
152 $off = unpack("c", substr($dat, $i, 1));
153 $self->{'VAL'}[$i] = $base_set[$i + $off];
154 $self->{'STRINGS'}{$base_set[$i + $off]} = $i unless (defined $self->{'STRINGS'}{$base_set[$i + $off]});
156 } elsif (int($self->{'FormatType'} + .5) == 2)
160 $fh->read($dat, ($numGlyphs + 1) << 1);
161 for ($i = 0; $i < $numGlyphs; $i++)
163 $off = unpack("n", substr($dat, ($i + 1) << 1, 2));
164 $maxoff = $off if (!defined $maxoff || $off > $maxoff);
166 for ($i = 0; $i < $maxoff - 257; $i++)
169 $off = unpack("C", $dat1);
170 $fh->read($dat1, $off);
171 $strings[$i] = $dat1;
173 for ($i = 0; $i < $numGlyphs; $i++)
175 $off = unpack("n", substr($dat, ($i + 1) << 1, 2));
178 $self->{'VAL'}[$i] = $strings[$off - 258];
179 $self->{'STRINGS'}{$strings[$off - 258]} = $i;
183 $self->{'VAL'}[$i] = $base_set[$off];
184 $self->{'STRINGS'}{$base_set[$off]} = $i unless (defined $self->{'STRINGS'}{$base_set[$off]});
194 Writes out a new Postscript name table from memory or copies from disk
200 my ($self, $fh) = @_;
203 return $self->SUPER::out($fh) unless $self->{' read'};
205 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
207 init unless ($fields{'FormatType'});
209 for ($i = $#{$self->{'VAL'}}; !defined $self->{'VAL'}[$i] && $i > 0; $i--)
210 { pop(@{$self->{'VAL'}}); }
211 if ($#{$self->{'VAL'}} < 0)
212 { $self->{'FormatType'} = 3; }
215 $self->{'FormatType'} = 1;
216 for ($i = 0; $i < $num; $i++)
218 if (!defined $base_set{$self->{'VAL'}[$i]})
220 $self->{'FormatType'} = 2;
223 elsif ($base_set{$self->{'VAL'}[$i]} != $i)
224 { $self->{'FormatType'} = ($no25 ? 2 : 2.5); }
228 $fh->print(TTF_Out_Fields($self, \%fields, 32));
230 return $self if (int($self->{'FormatType'} + .4) == 3);
232 if (int($self->{'FormatType'} + .5) == 2)
237 $fh->print(pack("n", $num));
238 for ($i = 0; $i < $num; $i++)
240 if (defined $base_set{$self->{'VAL'}[$i]})
241 { $fh->print(pack("n", $base_set{$self->{'VAL'}[$i]})); }
244 $fh->print(pack("n", $count + 258));
248 for ($i = 0; $i < $count; $i++)
250 $fh->print(pack("C", length($self->{'VAL'}[$ind[$i]])));
251 $fh->print($self->{'VAL'}[$ind[$i]]);
253 } elsif (int($self->{'FormatType'} * 2 + .5) == 5)
255 $fh->print(pack("n", $num));
256 for ($i = 0; $i < $num; $i++)
257 { $fh->print(pack("c", defined $base_set{$self->{'VAL'}[$i]} ?
258 $base_set{$self->{'VAL'}[$i]} - $i : -$i)); }
265 =head2 $t->XML_element($context, $depth, $key, $val)
267 Outputs the names as one block of XML
274 my ($context, $depth, $key, $val) = @_;
275 my ($fh) = $context->{'fh'};
278 return $self->SUPER::XML_element(@_) unless ($key eq 'STRINGS' || $key eq 'VAL');
279 return unless ($key eq 'VAL');
281 $fh->print("$depth<names>\n");
282 for ($i = 0; $i <= $#{$self->{'VAL'}}; $i++)
283 { $fh->print("$depth$context->{'indent'}<name post='$self->{'VAL'}[$i]' gid='$i'/>\n"); }
284 $fh->print("$depth</names>\n");
296 No support for type 4 tables
302 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and