| 1 | package PDF::API2::Resource::CIDFont::TrueType; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base 'PDF::API2::Resource::CIDFont'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '2.044'; # VERSION | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use PDF::API2::Basic::PDF::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use PDF::API2::Resource::CIDFont::TrueType::FontFile; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use PDF::API2::Util; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | PDF::API2::Resource::CIDFont::TrueType - TrueType font support | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | =over | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | =item $font = PDF::API2::Resource::CIDFont::TrueType->new $pdf, $file, %options | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | Returns a font object. | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | Defined Options: | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | -encode ... specify fonts encoding for non-utf8 text. | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | -nosubset ... disables subsetting. | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | sub new { | ||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my ($class, $pdf, $file, %opts) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $opts{'-encode'} //= 'latin1'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"-encode"} //= "latin1"
MC/DC0%0/1
$opts{"-encode"} //= "latin1"
$opts{"-encode"}
Truth table0%0/2
A
A= $opts{"-encode"}
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 0 | my ($ff, $data) = PDF::API2::Resource::CIDFont::TrueType::FontFile->new($pdf, $file, %opts); | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = $class->SUPER::new($pdf, $data->{'apiname'} . pdfkey() . '~' . time()); | |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $pdf->new_obj($self) if defined($pdf) and not $self->is_obj($pdf); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pdf and not $self->is_obj($pdf)
MC/DC0%0/2
defined $pdf and not $self->is_obj($pdf)
defined $pdf
not $self->is_obj($pdf)
Truth table0%0/3
A and not(B)
A= defined $pdfB= not $self->is_obj($pdf)
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | $self->{' data'} = $data; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{'BaseFont'} = PDFName($self->fontname()); | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | my $des = $self->descrByData(); | |||||||||||||||||||||||||||||||
| 49 | 0 | my $de = $self->{' de'}; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | $de->{'FontDescriptor'} = $des; | |||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $de->{'Subtype'} = PDFName($self->iscff() ? 'CIDFontType0' : 'CIDFontType2'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $de->{'BaseFont'} = PDFName($self->fontname()); | |||||||||||||||||||||||||||||||
| 54 | 0 | $de->{'DW'} = PDFNum($self->missingwidth()); | |||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($opts{'embed'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $des->{$self->iscff() ? 'FontFile3' : 'FontFile2'} = $ff; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($self->issymbol()) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | $self->encodeByName($opts{'-encode'}); | |||||||||||||||||||||||||||||||
| 60 | 0 | $self->data->{encode} = $opts{'-encode'}; | |||||||||||||||||||||||||||||||
| 61 | 0 | $self->data->{decode} = 'ident'; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($opts{'-nosubset'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 0 | $self->data->{'nosubset'} = 1; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{' ff'} = $ff; | |||||||||||||||||||||||||||||||
| 69 | 0 | $pdf->new_obj($ff); | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->{'-dokern'} = 1 if $opts{'-dokern'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub fontfile { return $_[0]->{' ff'}; } | ||||||||||||||||||||||||||||||
|
Subroutine
fontfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub fontobj { return $_[0]->data->{'obj'}; } | ||||||||||||||||||||||||||||||
|
Subroutine
fontobj: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | sub wxByCId { | ||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ($self, $g) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
wxByCId: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 81 | 0 | my $t = $self->fontobj->{'hmtx'}->read->{'advance'}[$g]; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (defined $t) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | return int($t * 1000 / $self->data->{'upem'}); | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||
| 87 | 0 | return $self->missingwidth(); | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | sub haveKernPairs { | ||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
haveKernPairs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 93 | 0 | return $self->fontfile->haveKernPairs(); | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | sub kernPairCid { | ||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ($self, $i1, $i2) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
kernPairCid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 98 | 0 | return $self->fontfile->kernPairCid($i1, $i2); | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | sub subsetByCId { | ||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my ($self, $g) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
subsetByCId: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return if $self->iscff(); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | 0 | return $self->fontfile->subsetByCId($g); | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | sub subvec { | ||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my ($self, $g) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
subvec: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return 1 if $self->iscff(); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 0 | return $self->fontfile->subvec($g); | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub glyphNum { return $_[0]->fontfile->glyphNum() } | ||||||||||||||||||||||||||||||
|
Subroutine
glyphNum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | sub outobjdeep { | ||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my ($self, $fh, $pdf) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
outobjdeep: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | my $notdefbefore = 1; | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 0 | my $wx = PDFArray(); | |||||||||||||||||||||||||||||||
| 121 | 0 | $self->{' de'}->{'W'} = $wx; | |||||||||||||||||||||||||||||||
| 122 | 0 | my $ml; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 0 | foreach my $w (0 .. (scalar @{$self->data->{'g2u'}} - 1)) { | |||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($self->subvec($w) and $notdefbefore) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->subvec($w) and $notdefbefore
MC/DC0%0/2
$self->subvec($w) and $notdefbefore
$self->subvec($w)
$notdefbefore
Truth table0%0/3
A and B
A= $self->subvec($w)B= $notdefbefore
| |||||||||||||||||||||||||||||||||
| 126 | 0 | $notdefbefore = 0; | |||||||||||||||||||||||||||||||
| 127 | 0 | $ml = PDFArray(); | |||||||||||||||||||||||||||||||
| 128 | 0 | $wx->add_elements(PDFNum($w), $ml); | |||||||||||||||||||||||||||||||
| 129 | 0 | $ml->add_elements(PDFNum($self->wxByCId($w))); | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | ▶ | elsif ($self->subvec($w) and not $notdefbefore) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->subvec($w) and not $notdefbefore
MC/DC0%0/2
$self->subvec($w) and not $notdefbefore
$self->subvec($w)
not $notdefbefore
Truth table0%0/3
A and not(B)
A= $self->subvec($w)B= not $notdefbefore
| |||||||||||||||||||||||||||||||||
| 132 | 0 | $ml->add_elements(PDFNum($self->wxByCId($w))); | |||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||
| 135 | 0 | $notdefbefore = 1; | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | $self->SUPER::outobjdeep($fh, $pdf); | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | =back | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 1 | 1; | |||||||||||||||||||||||||||||||