| 1 | package PDF::Make::Builder::Font; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 53 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 53 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 53 | ▶ | use Object::Proto; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 53 | ▶ | use PDF::Make::Page qw(:fonts); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 53 | ▶ | use PDF::Make::Font (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 53 | ▶ | use Font::Metrics (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 53 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 53 | Object::Proto::define('PDF::Make::Builder::Font', | |||||||||||||||||||||||||||||||||||||||||
| 11 | 'colour:Str:default(#000)', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 'size:Num:default(9)', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 'family:Str:default(Helvetica)', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 'bold:Bool:default(0)', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 'italic:Bool:default(0)', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'line_height:Num', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'loaded:HashRef:default({})', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'registry:HashRef:default({})', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 53 | Object::Proto::import_accessors('PDF::Make::Builder::Font'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # Standard 14 font family mapping: family => { variant => page constant } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 53 | my %STD14 = ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | Times => { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | normal => TIMES_ROMAN, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | bold => TIMES_BOLD, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | italic => TIMES_ITALIC, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | bolditalic => TIMES_BOLDITALIC, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | Helvetica => { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | normal => HELVETICA, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | bold => HELVETICA_BOLD, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | italic => HELVETICA_OBLIQUE, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | bolditalic => HELVETICA_BOLDOBLIQUE, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | Courier => { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | normal => COURIER, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | bold => COURIER_BOLD, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | italic => COURIER_OBLIQUE, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | bolditalic => COURIER_BOLDOBLIQUE, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | Symbol => { normal => SYMBOL }, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ZapfDingbats => { normal => ZAPFDINGBATS }, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # Map family+variant to PDF BaseFont name for XS Font | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 53 | my %BASEFONT = ( | |||||||||||||||||||||||||||||||||||||||||
| 49 | 'Times_normal' => 'Times-Roman', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'Times_bold' => 'Times-Bold', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'Times_italic' => 'Times-Italic', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 'Times_bolditalic' => 'Times-BoldItalic', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 'Helvetica_normal' => 'Helvetica', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 'Helvetica_bold' => 'Helvetica-Bold', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 'Helvetica_italic' => 'Helvetica-Oblique', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 'Helvetica_bolditalic' => 'Helvetica-BoldOblique', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 'Courier_normal' => 'Courier', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 'Courier_bold' => 'Courier-Bold', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 'Courier_italic' => 'Courier-Oblique', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'Courier_bolditalic' => 'Courier-BoldOblique', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 'Symbol_normal' => 'Symbol', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 'ZapfDingbats_normal' => 'ZapfDingbats', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Cache for Font::Metrics objects (exact per-glyph metrics via Font::Metrics XS) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 53 | my %_fm_cache; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # A family registered by Builder::load_ttf, or undef for a Standard 14 family. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # The entry is the hashref the Builder owns: { font, path, obj, pages }, shared | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # by reference with every font cloned from this one, so a page recorded here is | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # a page the Builder will attach the embedded font to when it finalises. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 70894 | ▶ | sub _ttf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ttf: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 70894 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 70894 | my $reg = registry $self; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 70894 | ▶ | return undef unless $reg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 70894 | return $reg->{ family $self }; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 9182 | ▶ | sub is_ttf { return defined $_[0]->_ttf ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ttf: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 43992 | ▶ | sub _xs_font { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xs_font: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 43992 | my ($self, $variant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 43992 | my $ttf = $self->_ttf; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 43992 | ▶ | return $ttf->{font} if $ttf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 43986 | ▶ | $variant //= $self->_default_variant; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$variant //= $self->_default_variant
MC/DC0%0/2
$variant //= $self->_default_variant
$variant
$self->_default_variant
Truth table33%1/3
A //= B
A= $variantB= $self->_default_variant
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 43986 | my $fam = family $self; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 43986 | my $key = "${fam}_${variant}"; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 43986 | ▶ | return $_fm_cache{$key} if $_fm_cache{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 56 | my $basefont = $BASEFONT{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 56 | ▶ | return undef unless $basefont; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 56 | $_fm_cache{$key} = Font::Metrics->new(name => $basefont); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 56 | return $_fm_cache{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # The show operator this font's text needs, and the operand to give it. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # A loaded TTF is embedded as a Type0 font with Identity-H encoding, so its | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # operand is two bytes of glyph id per character and goes in a hex string. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # encode_utf8 also marks each glyph used, which is what the subsetter embeds, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # so this must run for every string actually drawn. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 9170 | ▶ | sub show_op { return $_[0]->is_ttf ? 'Tj_hex' : 'Tj' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_op: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 9210 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 9210 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 9210 | my $ttf = $self->_ttf; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 9210 | ▶ | return $text unless $ttf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | ▶ | return '' unless defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | my $utf8 = $text; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | utf8::upgrade($utf8); # SvPV then always hands XS UTF-8, never Latin-1 | |||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | return $ttf->{font}->encode_utf8($utf8); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 52479 | ▶ | sub _default_variant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_variant: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 52479 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 52479 | ▶ | return 'bolditalic' if bold($self) && italic($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
<custom op object_func_get> and <custom op object_func_get>
MC/DC100%2/2
<custom op object_func_get> and <custom op object_func_get>
<custom op object_func_get>
<custom op object_func_get>
Truth table100%3/3
A and B
A= <custom op object_func_get>B= <custom op object_func_get>
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 52469 | ▶ | return 'bold' if bold($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 52369 | ▶ | return 'italic' if italic($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 52339 | return 'normal'; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 961 | ▶ | sub effective_line_height { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
effective_line_height: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 961 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 961 | my $lh = line_height $self; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 961 | ▶ | return defined $lh && $lh > 0 ? $lh : size $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lh and $lh > 0
MC/DC50%1/2
defined $lh and $lh > 0
defined $lh
$lh > 0
Truth table66%2/3
A and B
A= defined $lhB= $lh > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # The leading a set of overrides gets when it is resolved against $base. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # Returns undef to mean "let effective_line_height take the size", which is | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # not the same as returning the base's leading. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # A size override has to bring its own line height with it. Taking the base | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # font's - which is what every caller here used to do - gave a 20pt run a | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # 9pt slot: the baseline sits one font size below the cursor, the cursor | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # advances by the slot, and the next block is drawn through the text above | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # it. That is the <text size="20"> collision. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # An explicit line_height always wins. Otherwise a size override with no | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # leading of its own scales the base's explicitly-set leading by the size | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # ratio - the unitless-line-height rule - and where the base never set one, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # undef leaves the new size to speak for itself. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 215 | ▶ | sub resolve_line_height { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_line_height: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 215 | my ($class, $base, $overrides) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 215 | ▶ | return $overrides->{line_height} if defined $overrides->{line_height}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 152 | ▶ | return $base->effective_line_height unless defined $overrides->{size}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 58 | my $base_lh = $base->line_height; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 58 | my $base_size = $base->size; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 58 | ▶ | return undef unless defined $base_lh && $base_lh > 0 && $base_size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $base_lh and $base_lh > 0 and $base_size
defined $base_lh and $base_lh > 0
MC/DC0%0/3
defined $base_lh and $base_lh > 0 and $base_size
defined $base_lh
$base_lh > 0
$base_size
Truth table25%1/4
A and B and C
A= defined $base_lhB= $base_lh > 0C= $base_size
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return $base_lh * ($overrides->{size} / $base_size); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 43978 | ▶ | sub measure_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
measure_text: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 43978 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 43978 | my $xs = $self->_xs_font; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 43978 | ▶ | return $xs->string_width($text, size $self) if $xs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | # Fallback for unknown fonts | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return length($text) * 0.52 * (size $self); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | ▶ | sub measure_word { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
measure_word: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | my ($self, $word) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | my $xs = $self->_xs_font; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | return $xs->string_width($word, size $self) if $xs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return length($word) * 0.52 * (size $self); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 9 | ▶ | sub space_width { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
space_width: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | my $xs = $self->_xs_font; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | ▶ | return $xs->string_width(' ', size $self) if $xs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return 0.28 * (size $self); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 8597 | ▶ | sub hex_to_rgb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hex_to_rgb: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 8597 | my ($self, $hex) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 8597 | $hex =~ s/^#//; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 8597 | my ($r, $g, $b); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 8597 | ▶ | if (length($hex) == 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 8521 | ($r, $g, $b) = map { hex($_.$_) / 255.0 } split //, $hex; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } elsif (length($hex) == 6) { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 73 | $r = hex(substr($hex, 0, 2)) / 255.0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 73 | $g = hex(substr($hex, 2, 2)) / 255.0; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 73 | $b = hex(substr($hex, 4, 2)) / 255.0; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | return (0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 8594 | return ($r, $g, $b); | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 12 | ▶ | sub resource_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource_name: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 12 | my ($self, $variant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 12 | my $fam = family $self; | |||||||||||||||||||||||||||||||||||||||||
| 193 | # One file is one face, so a loaded TTF has no bold/italic variants to | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # name - asking for bold on it gets the face as supplied. | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | ▶ | return "F_${fam}" if $self->is_ttf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 12 | ▶ | $variant //= $self->_default_variant; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$variant //= $self->_default_variant
MC/DC0%0/2
$variant //= $self->_default_variant
$variant
$self->_default_variant
Truth table33%1/3
A //= B
A= $variantB= $self->_default_variant
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | return "F_${fam}_${variant}"; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 8510 | ▶ | sub ensure_loaded { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_loaded: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 8510 | my ($self, $xs_page, $variant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 8510 | my $fam = family $self; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | # An embedded font cannot be attached to the page yet: its object number | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # is only known once the document is written, because subsetting depends | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # on every glyph drawn with it. Record the page and let the Builder | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # attach it in _finalise. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 8510 | ▶ | if (my $ttf = $self->_ttf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | my $res_name = "F_${fam}"; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | push @{ $ttf->{pages} }, $xs_page | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | unless grep { $_ == $xs_page } @{ $ttf->{pages} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | return $res_name; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 8507 | ▶ | $variant //= $self->_default_variant; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$variant //= $self->_default_variant
MC/DC0%0/2
$variant //= $self->_default_variant
$variant
$self->_default_variant
Truth table66%2/3
A //= B
A= $variantB= $self->_default_variant
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 8507 | my $key = "${fam}_${variant}"; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 8507 | my $res_name = "F_${key}"; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | # Cache is per-page (keyed by page pointer address) to handle overflow | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 8507 | my $page_id = "$xs_page"; # stringified ref = unique per page | |||||||||||||||||||||||||||||||||||||||||
| 221 | 8507 | my $ld = loaded $self; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 8507 | ▶ | return $res_name if $ld->{"${key}_${page_id}"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 629 | my $family_map = $STD14{$fam}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 629 | ▶ | die "PDF::Make::Builder::Font: unknown font family '$fam'" unless $family_map; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 629 | my $font_id = $family_map->{$variant}; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 629 | ▶ | die "PDF::Make::Builder::Font: unknown variant '$variant' for '$fam'" unless defined $font_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 629 | $xs_page->add_std14_font($res_name, $font_id); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 629 | $ld->{"${key}_${page_id}"} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 629 | loaded $self, $ld; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 629 | return $res_name; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | ▶ | sub families { return keys %STD14 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
families: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 53 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||||||||||||||||