API3/Compat/API2/Basic/TTF/Glyf.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 81 CC 8 SCAR 23.4
CC
8
Cov
0%
XML_end
20.0
out
12.0
out_xml
6.0
CRAP 10.4
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 #=======================================================================
12 #
13 # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
14 #
15 #
16 # Copyright Martin Hosken <Martin_Hosken@sil.org>
17 #
18 # No warranty or expression of effectiveness, least of all regarding
19 # anyone's safety, is implied in this software or documentation.
20 #
21 # This specific module is licensed under the Perl Artistic License.
22 #
23 #
24 # $Id: Glyf.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Glyf;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Glyf - The Glyf data table
32
33 =head1 DESCRIPTION
34
35 This is a stub table. The real data is held in the loca table. If you want to get a glyf
36 look it up in the loca table as C<$f->{'loca'}{'glyphs'}[$num]>. It won't be here!
37
38 The difference between reading this table as opposed to the loca table is that
39 reading this table will cause updated glyphs to be written out rather than just
40 copying the glyph information from the input file. This causes font writing to be
41 slower. So read the glyf as opposed to the loca table if you want to change glyf
42 data. Read the loca table only if you are just wanting to read the glyf information.
43
44 This class is used when writing the glyphs though.
45
46 =head1 METHODS
47
48 =cut
49
50
51 use strict;
52 use vars qw(@ISA);
53 @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table);
54
55 =head2 $t->read
56
57 Reads the C<loca> table instead!
58
59 =cut
60
61 sub read
62 {
63 my ($self) = @_;
64
65 $self->{' PARENT'}{'loca'}->read;
66 $self->{' read'} = 1;
67 $self;
68 }
69
70
71 =head2 $t->out($fh)
72
73 Writes out all the glyphs in the parent's location table, calculating a new
74 output location for each one.
75
76 =cut
77
78 sub out
79 {
80 my ($self, $fh) = @_;
81 my ($i, $loca, $offset, $numGlyphs);
82
83 return $self->SUPER::out($fh) unless $self->{' read'};
84
85 $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
86 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
87
88 $offset = 0;
89 for ($i = 0; $i < $numGlyphs; $i++)
90 {
91 next unless defined $loca->[$i];
92 $loca->[$i]->update;
93 $loca->[$i]{' OUTLOC'} = $offset;
94 $loca->[$i]->out($fh);
95 $offset += $loca->[$i]{' OUTLEN'};
96 }
97 $self->{' PARENT'}{'head'}{'indexToLocFormat'} = ($offset >= 0x20000);
98 $self;
99 }
100
101
102 =head2 $t->out_xml($context, $depth)
103
104 Outputs all the glyphs in the glyph table just where they are supposed to be output!
105
106 =cut
107
108 sub out_xml
109 {
110 my ($self, $context, $depth) = @_;
111 my ($fh) = $context->{'fh'};
112 my ($loca, $i, $numGlyphs);
113
114 $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
115 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
116
117 for ($i = 0; $i < $numGlyphs; $i++)
118 {
119 $context->{'gid'} = $i;
120 $loca->[$i]->out_xml($context, $depth) if (defined $loca->[$i]);
121 }
122
123 $self;
124 }
125
126
127 =head2 $t->XML_start($context, $tag, %attrs)
128
129 Pass control to glyphs as they occur
130
131 =cut
132
133 sub XML_start
134 {
135 my ($self) = shift;
136 my ($context, $tag, %attrs) = @_;
137
138 if ($tag eq 'glyph')
139 {
140 $context->{'tree'}[-1] = PDF::API3::Compat::API2::Basic::TTF::Glyph->new(read => 2, PARENT => $self->{' PARENT'});
141 $context->{'receiver'} = $context->{'tree'}[-1];
142 }
143 }
144
145
146 =head2 $t->XML_end($context, $tag, %attrs)
147
148 Collect up glyphs and put them into the loca table
149
150 =cut
151
152 sub XML_end
153 {
154 my ($self) = shift;
155 my ($context, $tag, %attrs) = @_;
156
157 if ($tag eq 'glyph')
158 {
159 unless (defined $context->{'glyphs'})
160 {
161 if (defined $self->{' PARENT'}{'loca'})
162 { $context->{'glyphs'} = $self->{' PARENT'}{'loca'}{'glyphs'}; }
163 else
164 { $context->{'glyphs'} = []; }
165 }
166 $context->{'glyphs'}[$attrs{'gid'}] = $context->{'tree'}[-1];
167 return $context;
168 } else
169 { return $self->SUPER::XML_end(@_); }
170 }
171
172 1;
173
174 =head1 BUGS
175
176 None known
177
178 =head1 AUTHOR
179
180 Martin Hosken Martin_Hosken@sil.org. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
181 licensing.
182
183 =cut
184