line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Amuse::Compile::Fonts::Family; |
2
|
61
|
|
|
61
|
|
411
|
use utf8; |
|
61
|
|
|
|
|
153
|
|
|
61
|
|
|
|
|
396
|
|
3
|
61
|
|
|
61
|
|
1789
|
use strict; |
|
61
|
|
|
|
|
137
|
|
|
61
|
|
|
|
|
1115
|
|
4
|
61
|
|
|
61
|
|
294
|
use warnings; |
|
61
|
|
|
|
|
121
|
|
|
61
|
|
|
|
|
1990
|
|
5
|
61
|
|
|
61
|
|
316
|
use Types::Standard qw/Str Enum StrMatch InstanceOf Bool HashRef ArrayRef/; |
|
61
|
|
|
|
|
117
|
|
|
61
|
|
|
|
|
487
|
|
6
|
61
|
|
|
61
|
|
67538
|
use Moo; |
|
61
|
|
|
|
|
27738
|
|
|
61
|
|
|
|
|
396
|
|
7
|
61
|
|
|
61
|
|
23089
|
use Text::Amuse::Utils; |
|
61
|
|
|
|
|
3499
|
|
|
61
|
|
|
|
|
56557
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Text::Amuse::Compile::Fonts::Family - font family object |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 ACCESSORS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 name |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
The font family name. Required. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 desc |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
The font family description. Arbitrary string. Required. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 type |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The font type: must be serif, sans or mono. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 FONT FILES |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
These accessors aren't strictly required. If provided, they should be |
30
|
|
|
|
|
|
|
an instance of L. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 regular |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 italic |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 bold |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 bolditalic |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 languages |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
An optional arrayref of language codes. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 has_files |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Return true if all the 4 font slots are filled. This means we know the |
49
|
|
|
|
|
|
|
physical location of the files, not just its name. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 is_sans |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Return true if the family is a sans font |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 is_mono |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Return true if the family is a mono font |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 is_serif |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Return true if the family is a serif font |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 font_files |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Return an arrayref with the four L |
66
|
|
|
|
|
|
|
objects. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 language_names |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
An arrayref with the C codes mapped to their babel equivalent. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 has_languages |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Return true if the font family has languages set. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 for_babel_language($babel_lang) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 for_language_code($iso_code) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Return true if the family has the given language set (babel and iso version) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 babel_font_name |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 babel_font_options |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has name => (is => 'ro', |
90
|
|
|
|
|
|
|
isa => StrMatch[ qr{\A[a-zA-Z0-9 ]+\z} ], |
91
|
|
|
|
|
|
|
required => 1); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has desc => (is => 'ro', |
94
|
|
|
|
|
|
|
isa => Str, |
95
|
|
|
|
|
|
|
required => 1); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has type => (is => 'ro', |
98
|
|
|
|
|
|
|
required => 1, |
99
|
|
|
|
|
|
|
isa => Enum[qw/serif sans mono/]); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has regular => (is => 'ro', isa => InstanceOf[qw/Text::Amuse::Compile::Fonts::File/]); |
102
|
|
|
|
|
|
|
has italic => (is => 'ro', isa => InstanceOf[qw/Text::Amuse::Compile::Fonts::File/]); |
103
|
|
|
|
|
|
|
has bold => (is => 'ro', isa => InstanceOf[qw/Text::Amuse::Compile::Fonts::File/]); |
104
|
|
|
|
|
|
|
has bolditalic => (is => 'ro', isa => InstanceOf[qw/Text::Amuse::Compile::Fonts::File/]); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
has has_files => (is => 'lazy', isa => Bool); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _build_has_files { |
109
|
653
|
|
|
653
|
|
17846
|
my $self = shift; |
110
|
653
|
50
|
100
|
|
|
2454
|
if ($self->regular && |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
111
|
|
|
|
|
|
|
$self->italic && |
112
|
|
|
|
|
|
|
$self->bold && |
113
|
|
|
|
|
|
|
$self->bolditalic) { |
114
|
27
|
|
|
|
|
373
|
return 1; |
115
|
|
|
|
|
|
|
} |
116
|
626
|
|
|
|
|
8177
|
return 0; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has languages => (is => 'ro', isa => ArrayRef, default => sub { [] }); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
has language_names => (is => 'lazy', isa => ArrayRef); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _build_language_names { |
124
|
10035
|
|
|
10035
|
|
64544
|
my $self = shift; |
125
|
10035
|
|
|
|
|
11658
|
return [ map { Text::Amuse::Utils::get_latex_lang($_) } @{ $self->languages } ]; |
|
1579
|
|
|
|
|
4209
|
|
|
10035
|
|
|
|
|
115496
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
has babel_font_args => (is => 'lazy', isa => HashRef); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _build_babel_font_args { |
131
|
622
|
|
|
622
|
|
5908
|
my $self = shift; |
132
|
622
|
|
|
|
|
1618
|
my $name = $self->name; |
133
|
622
|
|
|
|
|
961
|
my @args; |
134
|
622
|
100
|
|
|
|
8703
|
if ($self->has_files) { |
135
|
22
|
|
|
|
|
259
|
my $regular; |
136
|
22
|
50
|
|
|
|
106
|
if ($self->regular->dirname =~ m/\A([A-Za-z0-9\.\/_-]+)\z/) { |
137
|
22
|
|
|
|
|
386
|
push @args, Path => $1; |
138
|
22
|
|
|
|
|
81
|
$name = $regular = $self->regular->basename_and_ext; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else { |
141
|
0
|
|
|
|
|
0
|
warn $self->regular->dirname . " does not look like a path which can be embedded." . |
142
|
|
|
|
|
|
|
" Please make sure the fonts are installed in a standard TeX location\n"; |
143
|
|
|
|
|
|
|
} |
144
|
22
|
50
|
|
|
|
222
|
if ($regular) { |
145
|
22
|
|
|
|
|
78
|
my %shapes = ( |
146
|
|
|
|
|
|
|
bold => 'BoldFont', |
147
|
|
|
|
|
|
|
italic => 'ItalicFont', |
148
|
|
|
|
|
|
|
bolditalic => 'BoldItalicFont', |
149
|
|
|
|
|
|
|
); |
150
|
22
|
|
|
|
|
92
|
foreach my $shape (sort keys %shapes) { |
151
|
66
|
50
|
|
|
|
244
|
if (my $file = $self->$shape->basename_and_ext) { |
152
|
66
|
|
|
|
|
789
|
push @args, $shapes{$shape}, $file; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
return { |
158
|
622
|
|
|
|
|
20405
|
name => $name, |
159
|
|
|
|
|
|
|
opts => \@args, |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub babel_font_name { |
164
|
838
|
|
|
838
|
1
|
12200
|
shift->babel_font_args->{name}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub babel_font_options { |
168
|
838
|
|
|
838
|
1
|
3132
|
my ($self, @args) = @_; |
169
|
838
|
50
|
|
|
|
2217
|
die "args must come in pairs" if @args % 2; |
170
|
838
|
50
|
|
|
|
1319
|
push @args, @{$self->babel_font_args->{opts} || [] }; |
|
838
|
|
|
|
|
13073
|
|
171
|
838
|
|
|
|
|
15283
|
my @list; |
172
|
838
|
|
|
|
|
3009
|
while (my @pair = splice @args, 0, 2) { |
173
|
677
|
|
|
|
|
2633
|
push @list, join('=', @pair); |
174
|
|
|
|
|
|
|
} |
175
|
838
|
|
|
|
|
2980
|
return join(",%\n ", @list) |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub is_serif { |
179
|
24531
|
|
|
24531
|
1
|
46481
|
return shift->type eq 'serif'; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub is_mono { |
183
|
24531
|
|
|
24531
|
1
|
46279
|
return shift->type eq 'mono'; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub is_sans { |
187
|
24427
|
|
|
24427
|
1
|
47713
|
return shift->type eq 'sans'; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub font_files { |
191
|
24
|
|
|
24
|
1
|
4136
|
my $self = shift; |
192
|
24
|
|
|
|
|
109
|
return [ $self->regular, $self->italic, $self->bold, $self->bolditalic ]; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub has_languages { |
196
|
13277
|
|
|
13277
|
1
|
18666
|
return scalar(@{shift->language_names}); |
|
13277
|
|
|
|
|
176320
|
|
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub for_babel_language { |
200
|
2175
|
|
|
2175
|
1
|
193901
|
my ($self, $lang) = @_; |
201
|
2175
|
|
|
|
|
2984
|
return scalar(grep { $lang eq $_ } @{$self->language_names}); |
|
2163
|
|
|
|
|
20296
|
|
|
2175
|
|
|
|
|
29163
|
|
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub for_language_code { |
205
|
3
|
|
|
3
|
1
|
711
|
my ($self, $lang) = @_; |
206
|
3
|
|
|
|
|
7
|
return scalar(grep { $lang eq $_ } @{$self->languages}); |
|
4
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
11
|
|
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |