line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Amuse::Compile::Fonts::File; |
2
|
61
|
|
|
61
|
|
57635
|
use strict; |
|
61
|
|
|
|
|
129
|
|
|
61
|
|
|
|
|
1680
|
|
3
|
61
|
|
|
61
|
|
291
|
use warnings; |
|
61
|
|
|
|
|
120
|
|
|
61
|
|
|
|
|
1375
|
|
4
|
61
|
|
|
61
|
|
289
|
use utf8; |
|
61
|
|
|
|
|
105
|
|
|
61
|
|
|
|
|
319
|
|
5
|
|
|
|
|
|
|
|
6
|
61
|
|
|
61
|
|
1636
|
use Moo; |
|
61
|
|
|
|
|
9742
|
|
|
61
|
|
|
|
|
339
|
|
7
|
61
|
|
|
61
|
|
18425
|
use File::Basename qw//; |
|
61
|
|
|
|
|
160
|
|
|
61
|
|
|
|
|
1193
|
|
8
|
61
|
|
|
61
|
|
385
|
use File::Spec; |
|
61
|
|
|
|
|
127
|
|
|
61
|
|
|
|
|
1699
|
|
9
|
61
|
|
|
61
|
|
775
|
use Types::Standard qw/Maybe Str Enum ArrayRef/; |
|
61
|
|
|
|
|
63803
|
|
|
61
|
|
|
|
|
416
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Text::Amuse::Compile::Fonts::File - font file object |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ACCESSORS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 file |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
The filename. Required |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 shape |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The shape of the font. Must be regular, bold, italic or bolditalic. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 format |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Built lazily from the filename, validating it and crashing if it's not |
28
|
|
|
|
|
|
|
otf or ttf. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 mimetype |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Built lazily from the filename, validating it and crashing if it's not |
33
|
|
|
|
|
|
|
otf or ttf |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 basename |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The basename of the font, includin the extension. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 basename_and_ext |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Alias for C |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 extension |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The file extension, including the dot. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 dirname |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
The directory, including the trailing slash. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 css_font_weight |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
C or C depending on the shape |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 css_font_style |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
C or C depending on the shape |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has file => (is => 'ro', |
62
|
|
|
|
|
|
|
required => 1, |
63
|
|
|
|
|
|
|
isa => sub { |
64
|
|
|
|
|
|
|
die "$_[0] is not a font file" |
65
|
|
|
|
|
|
|
unless $_[0] && -f $_[0] && $_[0] =~ m/\.(ttf|otf)\z/i |
66
|
|
|
|
|
|
|
}); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has shape => (is => 'ro', |
69
|
|
|
|
|
|
|
required => 1, |
70
|
|
|
|
|
|
|
isa => Enum[qw/regular bold italic bolditalic/]); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has format => (is => 'lazy', |
73
|
|
|
|
|
|
|
isa => Str); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has mimetype => (is => 'lazy', |
76
|
|
|
|
|
|
|
isa => Str); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has _parsed_path => (is => 'lazy', |
79
|
|
|
|
|
|
|
isa => ArrayRef); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _build__parsed_path { |
82
|
104
|
|
|
104
|
|
732
|
my $self = shift; |
83
|
104
|
50
|
|
|
|
307
|
if (my $file = $self->file) { |
84
|
104
|
|
|
|
|
3272
|
my ($filename, $dirs, $suffix) = File::Basename::fileparse(File::Spec->rel2abs($file), |
85
|
|
|
|
|
|
|
qr/\.(ttf|otf)\z/i); |
86
|
104
|
|
|
|
|
1742
|
return [ $filename . $suffix , $dirs, $suffix ]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
0
|
return [ '', '', '' ]; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# my ($filename, $dirs, $suffix) = fileparse($path, @suffixes); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub basename { |
96
|
193
|
|
|
193
|
1
|
7174
|
shift->_parsed_path->[0]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub basename_and_ext { |
100
|
101
|
|
|
101
|
1
|
1687
|
shift->_parsed_path->[0]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub dirname { |
104
|
35
|
|
|
35
|
1
|
4992
|
shift->_parsed_path->[1]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub extension { |
108
|
65
|
|
|
65
|
1
|
1494
|
shift->_parsed_path->[2]; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _build_format { |
112
|
64
|
|
|
64
|
|
8724
|
my $self = shift; |
113
|
64
|
50
|
|
|
|
130
|
if (my $ext = $self->extension) { |
114
|
64
|
|
|
|
|
734
|
my %map = ( |
115
|
|
|
|
|
|
|
'.woff' => 'woff', |
116
|
|
|
|
|
|
|
'.ttf' => 'truetype', |
117
|
|
|
|
|
|
|
'.otf' => 'opentype', |
118
|
|
|
|
|
|
|
); |
119
|
64
|
50
|
|
|
|
163
|
if (my $type = $map{lc($ext)}) { |
120
|
64
|
|
|
|
|
14036
|
return $type; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
0
|
|
|
|
|
0
|
die "Bad file format without extension " . $self->file; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _build_mimetype { |
127
|
64
|
|
|
64
|
|
9286
|
my $self = shift; |
128
|
64
|
50
|
|
|
|
818
|
if (my $format = $self->format) { |
129
|
64
|
|
|
|
|
1194
|
my %map = ( |
130
|
|
|
|
|
|
|
woff => 'application/font-woff', |
131
|
|
|
|
|
|
|
truetype => 'application/x-font-ttf', |
132
|
|
|
|
|
|
|
opentype => 'application/x-font-opentype', |
133
|
|
|
|
|
|
|
); |
134
|
64
|
|
|
|
|
929
|
return $map{$format}; |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
0
|
return; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub css_font_weight { |
140
|
48
|
|
|
48
|
1
|
5155
|
my $self = shift; |
141
|
48
|
|
|
|
|
140
|
my %map = ( |
142
|
|
|
|
|
|
|
regular => "normal", |
143
|
|
|
|
|
|
|
bold => "bold", |
144
|
|
|
|
|
|
|
italic => "normal", |
145
|
|
|
|
|
|
|
bolditalic => "bold", |
146
|
|
|
|
|
|
|
); |
147
|
48
|
|
|
|
|
176
|
return $map{$self->shape}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub css_font_style { |
151
|
48
|
|
|
48
|
1
|
1268
|
my $self = shift; |
152
|
48
|
|
|
|
|
131
|
my %map = ( |
153
|
|
|
|
|
|
|
regular => "normal", |
154
|
|
|
|
|
|
|
bold => "normal", |
155
|
|
|
|
|
|
|
italic => "italic", |
156
|
|
|
|
|
|
|
bolditalic => "italic", |
157
|
|
|
|
|
|
|
); |
158
|
48
|
|
|
|
|
119
|
return $map{$self->shape}; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |