File Coverage

blib/lib/Font/TTF/Glyf.pm
Criterion Covered Total %
statement 27 51 52.9
branch 5 16 31.2
condition n/a
subroutine 5 8 62.5
pod 5 5 100.0
total 42 80 52.5


line stmt bran cond sub pod time code
1             package Font::TTF::Glyf;
2              
3             =head1 NAME
4              
5             Font::TTF::Glyf - The Glyf data table
6              
7             =head1 DESCRIPTION
8              
9             This is a stub table. The real data is held in the loca table. If you want to get a glyf
10             look it up in the loca table as C<$f->{'loca'}{'glyphs'}[$num]>. It will not be here!
11              
12             The difference between reading this table as opposed to the loca table is that
13             reading this table will cause updated glyphs to be written out rather than just
14             copying the glyph information from the input file. This causes font writing to be
15             slower. So read the glyf as opposed to the loca table if you want to change glyf
16             data. Read the loca table only if you are just wanting to read the glyf information.
17              
18             This class is used when writing the glyphs though.
19              
20             =head1 METHODS
21              
22             =cut
23              
24              
25 1     1   4 use strict;
  1         1  
  1         31  
26 1     1   4 use vars qw(@ISA);
  1         1  
  1         433  
27             @ISA = qw(Font::TTF::Table);
28              
29             =head2 $t->read
30              
31             Reads the C table instead!
32              
33             =cut
34              
35             sub read
36             {
37 2     2 1 12 my ($self) = @_;
38            
39 2         17 $self->{' PARENT'}{'loca'}->read;
40 2         6 $self->{' read'} = 1;
41 2         9 $self;
42             }
43              
44             # Internal function called by loca -- decompresses WOFF data if needed.
45              
46             sub _read
47             {
48 4     4   14 my ($self) = @_;
49 4 100       59 $self->SUPER::read or return $self;
50            
51             # Nothing else to do
52 2         6 $self;
53             }
54              
55             =head2 $t->out($fh)
56              
57             Writes out all the glyphs in the parent's location table, calculating a new
58             output location for each one.
59              
60             =cut
61              
62             # ' match for syntax coloring
63              
64             sub out
65             {
66 2     2 1 6 my ($self, $fh) = @_;
67 2         4 my ($i, $loca, $offset, $numGlyphs);
68              
69 2 50       10 return $self->SUPER::out($fh) unless $self->{' read'};
70              
71 2         9 $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
72 2         9 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
73              
74 2         4 $offset = 0;
75 2         10 for ($i = 0; $i < $numGlyphs; $i++)
76             {
77 196 100       362 next unless defined $loca->[$i];
78 188         409 $loca->[$i]->update;
79 188         280 $loca->[$i]{' OUTLOC'} = $offset;
80 188         373 $loca->[$i]->out($fh);
81 188         466 $offset += $loca->[$i]{' OUTLEN'};
82             }
83 2         15 $self->{' PARENT'}{'head'}{'indexToLocFormat'} = ($offset >= 0x20000);
84 2         9 $self;
85             }
86              
87              
88             =head2 $t->out_xml($context, $depth)
89              
90             Outputs all the glyphs in the glyph table just where they are supposed to be output!
91              
92             =cut
93              
94             sub out_xml
95             {
96 0     0 1   my ($self, $context, $depth) = @_;
97 0           my ($fh) = $context->{'fh'};
98 0           my ($loca, $i, $numGlyphs);
99              
100 0           $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
101 0           $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
102            
103 0           for ($i = 0; $i < $numGlyphs; $i++)
104             {
105 0           $context->{'gid'} = $i;
106 0 0         $loca->[$i]->out_xml($context, $depth) if (defined $loca->[$i]);
107             }
108              
109 0           $self;
110             }
111              
112              
113             =head2 $t->XML_start($context, $tag, %attrs)
114              
115             Pass control to glyphs as they occur
116              
117             =cut
118              
119             sub XML_start
120             {
121 0     0 1   my ($self) = shift;
122 0           my ($context, $tag, %attrs) = @_;
123              
124 0 0         if ($tag eq 'glyph')
125             {
126 0           $context->{'tree'}[-1] = Font::TTF::Glyph->new(read => 2, PARENT => $self->{' PARENT'});
127 0           $context->{'receiver'} = $context->{'tree'}[-1];
128             }
129             }
130              
131              
132             =head2 $t->XML_end($context, $tag, %attrs)
133              
134             Collect up glyphs and put them into the loca table
135              
136             =cut
137              
138             sub XML_end
139             {
140 0     0 1   my ($self) = shift;
141 0           my ($context, $tag, %attrs) = @_;
142              
143 0 0         if ($tag eq 'glyph')
144             {
145 0 0         unless (defined $context->{'glyphs'})
146             {
147 0 0         if (defined $self->{' PARENT'}{'loca'})
148 0           { $context->{'glyphs'} = $self->{' PARENT'}{'loca'}{'glyphs'}; }
149             else
150 0           { $context->{'glyphs'} = []; }
151             }
152 0           $context->{'glyphs'}[$attrs{'gid'}] = $context->{'tree'}[-1];
153 0           return $context;
154             } else
155 0           { return $self->SUPER::XML_end(@_); }
156             }
157              
158             1;
159              
160             =head1 BUGS
161              
162             None known
163              
164             =head1 AUTHOR
165              
166             Martin Hosken L.
167              
168              
169             =head1 LICENSING
170              
171             Copyright (c) 1998-2014, SIL International (http://www.sil.org)
172              
173             This module is released under the terms of the Artistic License 2.0.
174             For details, see the full text of the license in the file LICENSE.
175              
176              
177              
178             =cut
179              
180