| 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | use vars qw(@ISA); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | @ISA = qw(Font::TTF::Table); | |||||||||
| 28 | |||||||||||
| 29 | =head2 $t->read | ||||||||||
| 30 | |||||||||||
| 31 | Reads the C<loca> table instead! | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | sub read | ||||||||||
| 36 | 2 | ▶ | { | ||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 2 | my ($self) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 2 | $self->{' PARENT'}{'loca'}->read; | |||||||||
| 40 | 2 | $self->{' read'} = 1; | |||||||||
| 41 | 2 | $self; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # Internal function called by loca -- decompresses WOFF data if needed. | ||||||||||
| 45 | |||||||||||
| 46 | sub _read | ||||||||||
| 47 | 4 | ▶ | { | ||||||||
|
Subroutine
_read: called CC=2 SCAR=6.9
| |||||||||||
| 48 | 4 | my ($self) = @_; | |||||||||
| 49 | 4 | ▶ | $self->SUPER::read or return $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | # Nothing else to do | ||||||||||
| 52 | 2 | $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 | 2 | ▶ | { | ||||||||
|
Subroutine
out: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 66 | 2 | my ($self, $fh) = @_; | |||||||||
| 67 | 2 | my ($i, $loca, $offset, $numGlyphs); | |||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | return $self->SUPER::out($fh) unless $self->{' read'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 2 | $loca = $self->{' PARENT'}{'loca'}{'glyphs'}; | |||||||||
| 72 | 2 | $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'}; | |||||||||
| 73 | |||||||||||
| 74 | 2 | $offset = 0; | |||||||||
| 75 | 2 | ▶ | for ($i = 0; $i < $numGlyphs; $i++) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | { | ||||||||||
| 77 | 196 | ▶ | next unless defined $loca->[$i]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 188 | $loca->[$i]->update; | |||||||||
| 79 | 188 | $loca->[$i]{' OUTLOC'} = $offset; | |||||||||
| 80 | 188 | $loca->[$i]->out($fh); | |||||||||
| 81 | 188 | $offset += $loca->[$i]{' OUTLEN'}; | |||||||||
| 82 | } | ||||||||||
| 83 | 2 | $self->{' PARENT'}{'head'}{'indexToLocFormat'} = ($offset >= 0x20000); | |||||||||
| 84 | 2 | $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 | 0 | ▶ | { | ||||||||
|
Subroutine
out_xml: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 96 | 0 | 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++) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | { | ||||||||||
| 105 | 0 | $context->{'gid'} = $i; | |||||||||
| 106 | 0 | ▶ | $loca->[$i]->out_xml($context, $depth) if (defined $loca->[$i]); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
XML_start: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 121 | 0 | my ($self) = shift; | |||||||||
| 122 | 0 | my ($context, $tag, %attrs) = @_; | |||||||||
| 123 | |||||||||||
| 124 | 0 | ▶ | if ($tag eq 'glyph') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | { | ||||||||
|
Subroutine
XML_end: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 140 | 0 | my ($self) = shift; | |||||||||
| 141 | 0 | my ($context, $tag, %attrs) = @_; | |||||||||
| 142 | |||||||||||
| 143 | 0 | ▶ | if ($tag eq 'glyph') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | { | ||||||||||
| 145 | 0 | ▶ | unless (defined $context->{'glyphs'}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | { | ||||||||||
| 147 | 0 | ▶ | if (defined $self->{' PARENT'}{'loca'}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 1; | |||||||||
| 159 | |||||||||||
| 160 | =head1 BUGS | ||||||||||
| 161 | |||||||||||
| 162 | None known | ||||||||||
| 163 | |||||||||||
| 164 | =head1 AUTHOR | ||||||||||
| 165 | |||||||||||
| 166 | Martin Hosken L<http://scripts.sil.org/FontUtils>. | ||||||||||
| 167 | |||||||||||
| 168 | |||||||||||
| 169 | =head1 LICENSING | ||||||||||
| 170 | |||||||||||
| 171 | Copyright (c) 1998-2016, 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 | |||||||||||