| 1 | package Font::Fontconfig::Pattern; | ||||||||||||
| 2 | |||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 9 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 9 | our @_internal_attributes = qw/ | |||||||||||
| 9 | charset | ||||||||||||
| 10 | family | ||||||||||||
| 11 | familylang | ||||||||||||
| 12 | file | ||||||||||||
| 13 | fontformat | ||||||||||||
| 14 | foundry | ||||||||||||
| 15 | fullname | ||||||||||||
| 16 | fullnamelang | ||||||||||||
| 17 | postscriptname | ||||||||||||
| 18 | style | ||||||||||||
| 19 | stylelang | ||||||||||||
| 20 | weight | ||||||||||||
| 21 | width | ||||||||||||
| 22 | /; | ||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | |||||||||||||
| 26 | # new_from_string | ||||||||||||
| 27 | # | ||||||||||||
| 28 | # The (only) constructor to create a new object. It takes a string returned by | ||||||||||||
| 29 | # `fc-list` | ||||||||||||
| 30 | # | ||||||||||||
| 31 | 4 | ▶ | sub new_from_string { | ||||||||||
|
Subroutine
new_from_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 32 | 4 | my $class = shift; | |||||||||||
| 33 | 4 | ▶ | my $string = shift | ||||||||||
|
Condition50%1/2
shift() // croak("'new_from_string' requires a string")
MC/DC0%0/1
shift() // croak("'new_from_string' requires a string")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 34 | // croak "'new_from_string' requires a string"; | ||||||||||||
| 35 | |||||||||||||
| 36 | 4 | my $struct = _parse_fc_line( $string ); | |||||||||||
| 37 | |||||||||||||
| 38 | 4 | bless $struct, $class | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | |||||||||||||
| 43 | # contains_codepoint | ||||||||||||
| 44 | # | ||||||||||||
| 45 | # my $bool = $font_pattern->contains_codepoint( $ordinal ) | ||||||||||||
| 46 | # | ||||||||||||
| 47 | # Returns 'true' if a font, described by the C<$font_pattern> contains the given | ||||||||||||
| 48 | # codepoint. | ||||||||||||
| 49 | # | ||||||||||||
| 50 | 5 | ▶ | sub contains_codepoint { | ||||||||||
|
Subroutine
contains_codepoint: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 51 | 5 | my $self = shift; | |||||||||||
| 52 | 5 | ▶ | my $codepoint = shift | ||||||||||
|
Condition50%1/2
shift() // croak("'contains_codepoint' requires a codepoint (int)")
MC/DC0%0/1
shift() // croak("'contains_codepoint' requires a codepoint (int)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 53 | // croak "'contains_codepoint' requires a codepoint (int)"; | ||||||||||||
| 54 | |||||||||||||
| 55 | 5 | my $codepoints = _parse_charset( $self->{charset} ); | |||||||||||
| 56 | |||||||||||||
| 57 | 5 | return !!$codepoints->[ $codepoint ]; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | # _parse_fc_line( $return_string ) | ||||||||||||
| 62 | # | ||||||||||||
| 63 | # takes a string from `fc-list` and decomposes it into a HashRef | ||||||||||||
| 64 | # | ||||||||||||
| 65 | # strings look like: | ||||||||||||
| 66 | # /path/to/font_file.ext: Family Name:key_1=value_1:key_2=value2 .. | ||||||||||||
| 67 | # | ||||||||||||
| 68 | 13 | ▶ | sub _parse_fc_line { | ||||||||||
|
Subroutine
_parse_fc_line: called CC=6 SCAR=17.9
| |||||||||||||
| 69 | 13 | ▶ | my $string = shift // return; | ||||||||||
|
Condition100%2/2
shift() // (return)
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 70 | |||||||||||||
| 71 | 12 | my $struct = {}; | |||||||||||
| 72 | |||||||||||||
| 73 | 12 | ▶ | if ($string =~ /^(?<file>.*): /) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 7 | $struct->{file} = $+{file}; | |||||||||||
| 75 | 7 | $string =~ s/^$+{file}: //; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 12 | ▶ | if ($string =~ /^(?<family>[^:]+)/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 7 | $struct->{family} = $+{family}; | |||||||||||
| 80 | 7 | $string =~ s/^$+{family}//; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 12 | ▶ | if ($string =~ /^:/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | 8 | $string =~ s/^://; | |||||||||||
| 85 | 8 | foreach my $element ( split q{:}, $string ) { | |||||||||||
| 86 | 16 | my ($key, $value) = split q{=}, $element; | |||||||||||
| 87 | 16 | $struct->{$key} = $value; | |||||||||||
| 88 | } | ||||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 12 | return $struct; | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | # _parse_charset( $$charset ) | ||||||||||||
| 97 | # | ||||||||||||
| 98 | # turns a charset string into an array of `1` for existing codepoints | ||||||||||||
| 99 | # | ||||||||||||
| 100 | # strins look like: | ||||||||||||
| 101 | # 14c-17e 192 1a0-1a1 | ||||||||||||
| 102 | # | ||||||||||||
| 103 | 5 | ▶ | sub _parse_charset { | ||||||||||
|
Subroutine
_parse_charset: called CC=5 SCAR=16.1
| |||||||||||||
| 104 | 5 | ▶ | my $charset = shift // return; | ||||||||||
|
Condition50%1/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 105 | |||||||||||||
| 106 | 5 | my @codepoints=(); | |||||||||||
| 107 | 5 | my @chunks = split ' ', $charset; | |||||||||||
| 108 | 5 | for my $chunk (@chunks) { | |||||||||||
| 109 | 10 | ▶ | if ($chunk =~ /-/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | 5 | my @range_ends = split '-', $chunk; | |||||||||||
| 111 | 5 | my $start = hex $range_ends[0]; | |||||||||||
| 112 | 5 | my $finish = hex $range_ends[1]; | |||||||||||
| 113 | 5 | for my $codepoint ($start .. $finish) { | |||||||||||
| 114 | 105 | $codepoints[ $codepoint ] = 1; | |||||||||||
| 115 | } | ||||||||||||
| 116 | } | ||||||||||||
| 117 | else { | ||||||||||||
| 118 | 5 | $codepoints[ hex $chunk ] = 1; | |||||||||||
| 119 | } | ||||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 5 | return \@codepoints; | |||||||||||
| 123 | } | ||||||||||||
| 124 | # | ||||||||||||
| 125 | # thanks to Harry Wozniak! | ||||||||||||
| 126 | |||||||||||||
| 127 | |||||||||||||
| 128 | |||||||||||||
| 129 | # copyrighted: 2019 Perceptyx Inc, Th. J. van Hoesel | ||||||||||||
| 130 | |||||||||||||
| 131 | 9 | 1; | |||||||||||