blib/script/afpviewfontdb.pl untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 74 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use DBI;
5 use DBD::SQLite;
6 use Data::Dumper;
7  
8 $|++;
9  
10 die "Usage: $0 fonts.db\n" unless @ARGV >= 1 or -e 'fonts.db';
11  
12 my $input = shift || 'fonts.db';
13 my $dbh = DBI->connect("dbi:SQLite:dbname=$input") or die $DBI::errstr;
14 my $fonts = $dbh->selectall_arrayref("SELECT FontName, FixedWidth, FixedHeight, Resolution FROM Fonts")
15 or die $dbh->errstr;
16  
17 while (1) {
18 for (1 .. @$fonts) {
19 my ($name, $width, $height, $resolution) = @{$fonts->[$_-1]};
20 my $dimension = ($width ? "$width * $height" : 'variable width');
21 print "$_: $name - $resolution - $dimension\n";
22 }
23 print "Choose a font to display: ";
24 my $choice = int(<STDIN>) or exit;
25 my $name = $fonts->[$choice-1][0] or next;
26  
27 my $sth = $dbh->prepare("SELECT * FROM $name ORDER BY Character");
28 $sth->execute;
29  
30 while ( my $row = $sth->fetchrow_hashref ) {
31 my $map = unpack('B*', $row->{Bitmap});
32 while (my $x = substr($map, 0, int(($row->{Width} + 7)/8)*8, '')) {
33 $x =~ s/0/./g;
34 $x =~ s/1/@/g;
35 print "$x\n";
36 }
37  
38 printf "[0x%s] %s*%s Inc/Asc/Desc:%s/%s/%s A/B/C:%s/%s/%s Offset:%s | Stop? ", (
39 uc(unpack('H*', $row->{Character})), @{$row}{qw(
40 Width Height Increment Ascend Descend
41 ASpace BSpace CSpace BaseOffset
42 )}
43 );
44  
45 $row->{Bitmap} or next;
46 last if <STDIN> =~ /^\z|[yq!]/i;
47 }
48 }