| 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
Condition66%2/3
defined $fc_pattern and &all(sub {
$fc_pattern->contains_codepoint(ord $_);
}
, split(//, $string, 0))
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))
| |||||||||||||||||||||||||||||
| 53 | ; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | 1; | |||||||||||||||||||||||||||