1 package Font::TTF::Dumper;
5 Font::TTF::Dumper - Debug dump of a font datastructure, avoiding recursion on ' PARENT'
11 # Print a table from the font structure:
12 print ttfdump($font->{$tag});
14 # Print font table with name
15 print ttfdump($font->{'head'}, 'head');
17 # Print one glyph's data:
18 print ttfdump($font->{'loca'}->read->{'glyphs'}[$gid], "glyph_$gid");
22 Font::TTF data structures are trees created from hashes and arrays. When trying to figure
23 out how the structures work, sometimes it is helpful to use Data::Dumper on them. However,
24 many of the object structures have ' PARENT' links that refer back to the object's parent,
25 which means that Data::Dumper ends up dumping the whole font no matter what.
27 The purpose of this module is to do just one thing: invoke Data::Dumper with a
28 filter that skips over the ' PARENT' element of any hash.
30 To reduce output further, this module also skips over ' CACHE' elements and any
31 hash element whose value is a Font::TTF::Glyph or Font::TTF::Font object.
32 (Really should make this configurable.)
39 use vars qw(@EXPORT @ISA);
41 @ISA = qw( Exporter );
42 @EXPORT = qw( ttfdump );
44 my %skip = ( Font => 1, Glyph => 1 );
48 my ($var, $name) = @_;
51 my $d = Data::Dumper->new([$var]);
52 $d->Names([$name]) if defined $name;
53 $d->Sortkeys(\&myfilter); # This is the trick to keep from dumping the whole font
54 $d->Indent(3); # I want array indicies
55 $d->Useqq(1); # Perlquote -- slower but there might be binary data.
65 ($_ eq ' PARENT' || $_ eq ' CACHE') ? 0 :
66 ref($hash->{$_}) =~ m/^Font::TTF::(.*)$/ ? !$skip{$1} :
69 # Sort numerically if that is reasonable:
70 return [ sort {$a =~ /\D/ || $b =~ /\D/ ? $a cmp $b : $a <=> $b} @a ];