blib/lib/Font/Selector.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 95.4% 42 / 44 CC 3 SCAR 4.7
CC
3
Cov
97%
_test_glyphs_for_fontname
3.0
__ANON__
1.0
BEGIN
1.0
CRAP 1.6
↑ Summary
1 package Font::Selector;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.02';
7  
8 3 ▶use Font::Fontconfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use List::Util qw/all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 our @EXPORT_OK = qw/&grep_from_fontnames/;
14  
15  
16  
17 # grep_from_fontnames
18 #
19 # This works on font-names, the litteral string, not on fontconfig patterns.
20 #
21 4 ▶sub grep_from_fontnames {
Subroutine grep_from_fontnames: called CC=1 SCAR=0.0
Pod documented
22 4 my $class = shift;
23 4 my $string = shift;
24 4 my @fontnames = @_;
25
26 4 grep { _test_glyphs_for_fontname( $string, $_ ) } @fontnames
27
28 }
29  
30  
31  
32 # _test_glyphs_for_fontname
33 #
34 # Hopefully we do the right thing here, further investigation might be needed to
35 # check against Unicode libraries, where we can have canonical glyphs, combined
36 # or split.
37 #
38 # There are opertunities to optimize the code:
39 # - cache the font-pattern returned from Font::Fontconfig->list
40 # - cache the results per fontname/glyph combination
41 # - cache the results per fontname/string
42 #
43 5 ▶sub _test_glyphs_for_fontname {
Subroutine _test_glyphs_for_fontname: called CC=3 SCAR=11.0
44 5 my $string = shift;
45 5 my $fontname = shift;
46
47 5 my ($fc_pattern) = Font::Fontconfig->list( $fontname );
48
49 return !undef if
50 defined $fc_pattern
51 and
52 5 ▶ all { $fc_pattern->contains_codepoint( ord $_ ) } split //, $string
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if defined $fc_pattern and &all(sub { $fc_pattern->contains_codepoint(ord $_); } , split(//, $string, 0)) 3 2 5
Condition66%2/3
defined $fc_pattern and &all(sub { $fc_pattern->contains_codepoint(ord $_); } , split(//, $string, 0))
!ll&&!rl&&r
023
MC/DC50%1/2
defined $fc_pattern and &all(sub { $fc_pattern->contains_codepoint(ord $_); } , split(//, $string, 0))
defined $fc_pattern &all(sub { $fc_pattern->contains_codepoint(ord $_); } , split(//, $string, 0))
Truth table66%2/3
A and B
A= defined $fc_patternB= &all(sub { $fc_pattern->contains_codepoint(ord $_); } , split(//, $string, 0))
ABresult
0X0
100
111
53 ;
54  
55 }
56  
57  
58  
59 3 1;
↑ Summary