| 1 | package Font::TTF::Fdsc; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Font::TTF::Fdsc - Font Descriptors table in a font | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | =head1 INSTANCE VARIABLES | ||
| 10 | |||
| 11 | =over | ||
| 12 | |||
| 13 | =item version | ||
| 14 | |||
| 15 | =item descriptors | ||
| 16 | |||
| 17 | Hash keyed by descriptor tags | ||
| 18 | |||
| 19 | =back | ||
| 20 | |||
| 21 | =head1 METHODS | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use vars qw(@ISA %fields); | ||
| 27 | use Font::TTF::Utils; | ||
| 28 | |||
| 29 | @ISA = qw(Font::TTF::Table); | ||
| 30 | |||
| 31 | =head2 $t->read | ||
| 32 | |||
| 33 | Reads the table into memory | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub read | ||
| 38 | { | ||
| 39 | my ($self) = @_; | ||
| 40 | my ($dat, $fh, $numDescs, $tag, $descs); | ||
| 41 | |||
| 42 | $self->SUPER::read or return $self; | ||
| 43 | |||
| 44 | $fh = $self->{' INFILE'}; | ||
| 45 | $fh->read($dat, 4); | ||
| 46 | $self->{'version'} = TTF_Unpack("v", $dat); | ||
| 47 | |||
| 48 | $fh->read($dat, 4); | ||
| 49 | |||
| 50 | foreach (1 .. unpack("N", $dat)) { | ||
| 51 | $fh->read($tag, 4); | ||
| 52 | $fh->read($dat, 4); | ||
| 53 | $descs->{$tag} = ($tag eq 'nalf') ? unpack("N", $dat) : TTF_Unpack("f", $dat); | ||
| 54 | } | ||
| 55 | |||
| 56 | $self->{'descriptors'} = $descs; | ||
| 57 | |||
| 58 | $self; | ||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | =head2 $t->out($fh) | ||
| 63 | |||
| 64 | Writes the table to a file either from memory or by copying | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub out | ||
| 69 | { | ||
| 70 | my ($self, $fh) = @_; | ||
| 71 | my ($descs); | ||
| 72 | |||
| 73 | return $self->SUPER::out($fh) unless $self->{' read'}; | ||
| 74 | |||
| 75 | $fh->print(TTF_Pack("v", $self->{'version'})); | ||
| 76 | |||
| 77 | $descs = $self->{'descriptors'} || {}; | ||
| 78 | |||
| 79 | $fh->print(pack("N", scalar keys %$descs)); | ||
| 80 | foreach (sort keys %$descs) { | ||
| 81 | $fh->print($_); | ||
| 82 | $fh->print(($_ eq 'nalf') ? pack("N", $descs->{$_}) : TTF_Pack("f", $descs->{$_})); | ||
| 83 | } | ||
| 84 | |||
| 85 | $self; | ||
| 86 | } | ||
| 87 | |||
| 88 | =head2 $t->print($fh) | ||
| 89 | |||
| 90 | Prints a human-readable representation of the table | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | sub print | ||
| 95 | { | ||
| 96 | my ($self, $fh) = @_; | ||
| 97 | my ($descs, $k); | ||
| 98 | |||
| 99 | $self->read; | ||
| 100 | |||
| 101 | $fh = 'STDOUT' unless defined $fh; | ||
| 102 | |||
| 103 | $descs = $self->{'descriptors'}; | ||
| 104 | foreach $k (sort keys %$descs) { | ||
| 105 | if ($k eq 'nalf') { | ||
| 106 | $fh->printf("Descriptor '%s' = %d\n", $k, $descs->{$k}); | ||
| 107 | } | ||
| 108 | else { | ||
| 109 | $fh->printf("Descriptor '%s' = %f\n", $k, $descs->{$k}); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | $self; | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
| 117 | |||
| 118 | |||
| 119 | =head1 BUGS | ||
| 120 | |||
| 121 | None known | ||
| 122 | |||
| 123 | =head1 AUTHOR | ||
| 124 | |||
| 125 | Jonathan Kew L<http://scripts.sil.org/FontUtils>. | ||
| 126 | |||
| 127 | |||
| 128 | =head1 LICENSING | ||
| 129 | |||
| 130 | Copyright (c) 1998-2016, SIL International (http://www.sil.org) | ||
| 131 | |||
| 132 | This module is released under the terms of the Artistic License 2.0. | ||
| 133 | For details, see the full text of the license in the file LICENSE. | ||
| 134 | |||
| 135 | |||
| 136 | |||
| 137 | =cut | ||
| 138 |