| 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: Fdsc.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||
| 25 | # | ||
| 26 | #======================================================================= | ||
| 27 | package PDF::API3::Compat::API2::Basic::TTF::Fdsc; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PDF::API3::Compat::API2::Basic::TTF::Fdsc - Font Descriptors table in a font | ||
| 32 | |||
| 33 | =head1 DESCRIPTION | ||
| 34 | |||
| 35 | =head1 INSTANCE VARIABLES | ||
| 36 | |||
| 37 | =item version | ||
| 38 | |||
| 39 | =item descriptors | ||
| 40 | |||
| 41 | Hash keyed by descriptor tags | ||
| 42 | |||
| 43 | =head1 METHODS | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | use strict; | ||
| 48 | use vars qw(@ISA %fields); | ||
| 49 | use PDF::API3::Compat::API2::Basic::TTF::Utils; | ||
| 50 | |||
| 51 | @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table); | ||
| 52 | |||
| 53 | =head2 $t->read | ||
| 54 | |||
| 55 | Reads the table into memory | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub read | ||
| 60 | { | ||
| 61 | my ($self) = @_; | ||
| 62 | my ($dat, $fh, $numDescs, $tag, $descs); | ||
| 63 | |||
| 64 | $self->SUPER::read or return $self; | ||
| 65 | |||
| 66 | $fh = $self->{' INFILE'}; | ||
| 67 | $fh->read($dat, 4); | ||
| 68 | $self->{'version'} = TTF_Unpack("f", $dat); | ||
| 69 | |||
| 70 | $fh->read($dat, 4); | ||
| 71 | |||
| 72 | foreach (1 .. unpack("N", $dat)) { | ||
| 73 | $fh->read($tag, 4); | ||
| 74 | $fh->read($dat, 4); | ||
| 75 | $descs->{$tag} = ($tag eq 'nalf') ? unpack("N", $dat) : TTF_Unpack("f", $dat); | ||
| 76 | } | ||
| 77 | |||
| 78 | $self->{'descriptors'} = $descs; | ||
| 79 | |||
| 80 | $self; | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | =head2 $t->out($fh) | ||
| 85 | |||
| 86 | Writes the table to a file either from memory or by copying | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub out | ||
| 91 | { | ||
| 92 | my ($self, $fh) = @_; | ||
| 93 | my ($descs); | ||
| 94 | |||
| 95 | return $self->SUPER::out($fh) unless $self->{' read'}; | ||
| 96 | |||
| 97 | $fh->print(TTF_Pack("f", $self->{'version'})); | ||
| 98 | |||
| 99 | $descs = $self->{'descriptors'} or {}; | ||
| 100 | |||
| 101 | $fh->print(pack("N", scalar keys %$descs)); | ||
| 102 | foreach (sort keys %$descs) { | ||
| 103 | $fh->print($_); | ||
| 104 | $fh->print(($_ eq 'nalf') ? pack("N", $descs->{$_}) : TTF_Pack("f", $descs->{$_})); | ||
| 105 | } | ||
| 106 | |||
| 107 | $self; | ||
| 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 ($descs, $k); | ||
| 120 | |||
| 121 | $self->read; | ||
| 122 | |||
| 123 | $fh = 'STDOUT' unless defined $fh; | ||
| 124 | |||
| 125 | $descs = $self->{'descriptors'}; | ||
| 126 | foreach $k (sort keys %$descs) { | ||
| 127 | if ($k eq 'nalf') { | ||
| 128 | $fh->printf("Descriptor '%s' = %d\n", $k, $descs->{$k}); | ||
| 129 | } | ||
| 130 | else { | ||
| 131 | $fh->printf("Descriptor '%s' = %f\n", $k, $descs->{$k}); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | $self; | ||
| 136 | } | ||
| 137 | |||
| 138 | 1; | ||
| 139 | |||
| 140 | |||
| 141 | =head1 BUGS | ||
| 142 | |||
| 143 | None known | ||
| 144 | |||
| 145 | =head1 AUTHOR | ||
| 146 | |||
| 147 | Jonathan Kew L<Jonathan_Kew@sil.org>. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and | ||
| 148 | licensing. | ||
| 149 | |||
| 150 | =cut | ||
| 151 |