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

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