line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Font::BDF::Reader; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34101
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1065
|
use IO::File; |
|
1
|
|
|
|
|
14071
|
|
|
1
|
|
|
|
|
182
|
|
8
|
1
|
|
|
1
|
|
1535
|
use Data::Dumper; |
|
1
|
|
|
|
|
14096
|
|
|
1
|
|
|
|
|
1531
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
15
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
16
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This allows declaration use Font::BDF::Reader ':all'; |
19
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
20
|
|
|
|
|
|
|
# will save memory. |
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
22
|
|
|
|
|
|
|
) ] ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Preloaded methods go here. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my $type = shift; |
35
|
0
|
|
|
|
|
|
my $self = { STARTCHAR => {}, |
36
|
|
|
|
|
|
|
ENCODING => {}, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
bless $self, $type; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
|
my $bdf_file = shift || ""; |
42
|
0
|
0
|
|
|
|
|
if( $bdf_file ) { |
43
|
0
|
0
|
|
|
|
|
if( $self->open_bdf_file( $bdf_file ) ) { |
44
|
0
|
|
|
|
|
|
$self->read_bdf_file; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_all_STARTCHAR { |
51
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return sort keys %{$self->{STARTCHAR}}; |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_all_ENCODING { |
57
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return sort keys %{$self->{ENCODING}}; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_font_info_by_STARTCHAR { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my $key = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $self->{STARTCHAR}{$key}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_font_info_by_ENCODING { |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $key = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $self->{ENCODING}{$key}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub clear_cache { |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
$self->{ENCODING} = {}; |
79
|
0
|
|
|
|
|
|
$self->{STARTCHAR} = {}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub clear_font_info_by_STARTCHAR { |
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $key = shift; |
85
|
0
|
|
|
|
|
|
delete $self->{STARTCHAR}{$key}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub clear_font_info_by_ENCODING { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my $key = shift; |
91
|
0
|
|
|
|
|
|
delete $self->{ENCODING}{$key}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub open_bdf_file { |
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
96
|
0
|
|
0
|
|
|
|
my $bdf_file = shift || die "No bdf file specified!"; |
97
|
0
|
0
|
|
|
|
|
if( ! -f $bdf_file ) { |
98
|
0
|
|
|
|
|
|
die "bdf file '$bdf_file' not found!"; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
$self->{BDF_FILE} = $bdf_file; |
101
|
0
|
|
0
|
|
|
|
my $FH = IO::File->new( $bdf_file ) |
102
|
|
|
|
|
|
|
|| die "Can't open bdf file '$bdf_file'!"; |
103
|
0
|
|
|
|
|
|
$self->{FH} = $FH; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $self; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub read_bdf_file { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
$self->read_bdf_metadata( @_ ); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->read_bdf_chars( @_ ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub read_bdf_metadata { |
116
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
117
|
0
|
|
0
|
|
|
|
my $FH = shift || $self->{FH} || die "No FH!"; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Read in the metadata |
120
|
0
|
|
|
|
|
|
my $last_line = ""; |
121
|
0
|
|
|
|
|
|
my %METADATA = (); |
122
|
0
|
|
|
|
|
|
while( <$FH> ) { |
123
|
0
|
|
|
|
|
|
chomp; chomp; |
|
0
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my( $key, $val ) = split /\s+/, $_, 2; |
125
|
0
|
|
|
|
|
|
$METADATA{$key} = $val; |
126
|
0
|
0
|
|
|
|
|
if( $key =~ /^CHARS$/i ) { |
127
|
0
|
|
|
|
|
|
$self->{METADATA} = \%METADATA; |
128
|
0
|
|
|
|
|
|
last; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_bdf_metadata { |
134
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $self->{METADATA}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub read_bdf_chars { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
142
|
0
|
|
0
|
|
|
|
my $FH = shift || $self->{FH} || die "No FH!"; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $chars = $self->{METADATA}{CHARS}; |
145
|
0
|
|
|
|
|
|
my $chars_read = 0; |
146
|
0
|
|
|
|
|
|
while( $self->read_bdf_char ) { |
147
|
0
|
|
|
|
|
|
$chars_read++; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
if( $chars_read != $chars ) { |
151
|
0
|
|
|
|
|
|
warn "Chars read is $chars_read, expected $chars.\n"; |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
return $self; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub read_bdf_char { |
158
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
159
|
0
|
|
0
|
|
|
|
my $FH = shift || $self->{FH} || die "No FH!"; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Now, read in the character data: |
162
|
|
|
|
|
|
|
# STARTCHAR 7f56 |
163
|
|
|
|
|
|
|
# ENCODING 32598 |
164
|
|
|
|
|
|
|
# SWIDTH 150 0 |
165
|
|
|
|
|
|
|
# DWIDTH 48 0 |
166
|
|
|
|
|
|
|
# BBX 48 48 0 -2 |
167
|
|
|
|
|
|
|
# BITMAP |
168
|
|
|
|
|
|
|
# 000000000000 |
169
|
|
|
|
|
|
|
# ... |
170
|
|
|
|
|
|
|
# ENDCHAR |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my %char_data = (); |
173
|
0
|
|
|
|
|
|
while( <$FH> ) { |
174
|
0
|
|
|
|
|
|
chomp; chomp; |
|
0
|
|
|
|
|
|
|
175
|
0
|
0
|
0
|
|
|
|
return 0 if( /ENDFONT/ or /^$/ ); |
176
|
0
|
0
|
|
|
|
|
if( /^BITMAP/ ) { |
177
|
|
|
|
|
|
|
# Read the bitmap data |
178
|
0
|
|
|
|
|
|
my @bitmap_data = (); |
179
|
0
|
|
|
|
|
|
while( <$FH> ) { |
180
|
0
|
|
|
|
|
|
chomp; chomp; |
|
0
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
last if( /^ENDCHAR/ ); |
182
|
0
|
|
|
|
|
|
push @bitmap_data, $_; # Otherwise, store the line of data |
183
|
|
|
|
|
|
|
} |
184
|
0
|
|
|
|
|
|
$char_data{BITMAP} = \@bitmap_data; |
185
|
0
|
|
|
|
|
|
last; |
186
|
|
|
|
|
|
|
} |
187
|
0
|
0
|
|
|
|
|
last if( /^ENDCHAR/ ); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Read metadata |
190
|
0
|
|
|
|
|
|
my($key,$val) = split /\s+/, $_, 2; |
191
|
0
|
0
|
0
|
|
|
|
if( $key eq "STARTCHAR" or $val eq "ENCODING" ) { |
192
|
0
|
|
|
|
|
|
$char_data{$key} = $val; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else { |
195
|
0
|
|
|
|
|
|
my @array_data = split /\s+/, $val; |
196
|
0
|
|
|
|
|
|
$char_data{$key} = \@array_data; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
# print Dumper( \%char_data ); |
200
|
0
|
|
|
|
|
|
my $STARTCHAR = $char_data{STARTCHAR}; |
201
|
0
|
|
|
|
|
|
my $ENCODING = $char_data{ENCODING}; |
202
|
0
|
|
|
|
|
|
$self->{STARTCHAR}{$STARTCHAR} = \%char_data; |
203
|
0
|
|
|
|
|
|
$self->{ENCODING}{$ENCODING} = \%char_data; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
return $char_data{STARTCHAR}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
__END__ |