Font/TTF/Prop.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 113 CC 15 SCAR 36.8
CC
15
Cov
0%
meaning_
90.0
out
20.0
print
12.0
CRAP 39.6
1 package Font::TTF::Prop;
2  
3 =head1 NAME
4  
5 Font::TTF::Prop - Glyph Properties table in a font
6  
7 =head1 DESCRIPTION
8  
9 =head1 INSTANCE VARIABLES
10  
11 =over
12  
13 =item version
14  
15 =item default
16  
17 =item lookup
18  
19 Hash of property values keyed by glyph number
20  
21 =item lookupFormat
22  
23 =back
24  
25 =head1 METHODS
26  
27 =cut
28  
29 use strict;
30 use vars qw(@ISA);
31 use Font::TTF::Utils;
32 use Font::TTF::AATutils;
33 use Font::TTF::Segarr;
34  
35 @ISA = qw(Font::TTF::Table);
36  
37 =head2 $t->read
38  
39 Reads the table into memory
40  
41 =cut
42  
43 sub read
44 {
45 my ($self) = @_;
46 my ($dat, $fh);
47 my ($version, $lookupPresent, $default);
48
49 $self->SUPER::read or return $self;
50  
51 $fh = $self->{' INFILE'};
52 $fh->read($dat, 8);
53 ($version, $lookupPresent, $default) = TTF_Unpack("vSS", $dat);
54  
55 if ($lookupPresent) {
56 my ($format, $lookup) = AAT_read_lookup($fh, 2, $self->{' LENGTH'} - 8, $default);
57 $self->{'lookup'} = $lookup;
58 $self->{'format'} = $format;
59 }
60  
61 $self->{'version'} = $version;
62 $self->{'default'} = $default;
63  
64 $self;
65 }
66  
67  
68 =head2 $t->out($fh)
69  
70 Writes the table to a file either from memory or by copying
71  
72 =cut
73  
74 sub out
75 {
76 my ($self, $fh) = @_;
77 my ($default, $lookup);
78
79 return $self->SUPER::out($fh) unless $self->{' read'};
80  
81 $default = $self->{'default'};
82 $lookup = $self->{'lookup'};
83 $fh->print(TTF_Pack("vSS", $self->{'version'}, (defined $lookup ? 1 : 0), $default));
84  
85 AAT_write_lookup($fh, $self->{'format'}, $lookup, 2, $default) if (defined $lookup);
86 }
87  
88 =head2 $t->minsize()
89  
90 Returns the minimum size this table can be. If it is smaller than this, then the table
91 must be bad and should be deleted or whatever.
92  
93 =cut
94  
95 sub minsize
96 {
97 return 8;
98 }
99  
100 =head2 $t->print($fh)
101  
102 Prints a human-readable representation of the table
103  
104 =cut
105  
106 sub print
107 {
108 my ($self, $fh) = @_;
109 my ($lookup);
110
111 $self->read;
112
113 $fh = 'STDOUT' unless defined $fh;
114  
115 $fh->printf("version %f\ndefault %04x # %s\n", $self->{'version'}, $self->{'default'}, meaning_($self->{'default'}));
116 $lookup = $self->{'lookup'};
117 if (defined $lookup) {
118 $fh->printf("format %d\n", $self->{'format'});
119 foreach (sort { $a <=> $b } keys %$lookup) {
120 $fh->printf("\t%d -> %04x # %s\n", $_, $lookup->{$_}, meaning_($lookup->{$_}));
121 }
122 }
123 }
124  
125 sub meaning_
126 {
127 my ($val) = @_;
128 my ($res);
129
130 my @types = (
131 "Strong left-to-right",
132 "Strong right-to-left",
133 "Arabic letter",
134 "European number",
135 "European number separator",
136 "European number terminator",
137 "Arabic number",
138 "Common number separator",
139 "Block separator",
140 "Segment separator",
141 "Whitespace",
142 "Other neutral");
143 $res = $types[$val & 0x001f] or ("Undefined [" . ($val & 0x001f) . "]");
144
145 $res .= ", floater" if $val & 0x8000;
146 $res .= ", hang left" if $val & 0x4000;
147 $res .= ", hang right" if $val & 0x2000;
148 $res .= ", attaches on right" if $val & 0x0080;
149 $res .= ", pair" if $val & 0x1000;
150 my $pairOffset = ($val & 0x0f00) >> 8;
151 $pairOffset = $pairOffset - 16 if $pairOffset > 7;
152 $res .= $pairOffset > 0 ? " +" . $pairOffset : $pairOffset < 0 ? " " . $pairOffset : "";
153
154 $res;
155 }
156  
157 1;
158  
159  
160 =head1 BUGS
161  
162 None known
163  
164 =head1 AUTHOR
165  
166 Jonathan Kew 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