ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 20 forks source link

Warning in PDF/API2/Resource/CIDFont.pm encodeByName() with utf-8 encoding. #71

Closed svenoe closed 8 months ago

svenoe commented 9 months ago

When calling ttfont() on a PDF::API2 object with -encoding => 'utf-8', I receive a warning three times. Unfortunately I understand neither the aim of the code here, nor pack and decode well enough, to say much more.

use PDF::API2;
print "Version: $PDF::API2::VERSION\n";

my $pdf = PDF::API2->new();
$pdf->addFontDirs('var/fonts'); # some font containing directory

my $font = $pdf->ttfont('DejaVuSansMono.ttf', '-encode', 'utf-8');
Version: 2.045
Use of uninitialized value in hash element at /usr/local/share/perl/5.26.1/PDF/API2/Resource/CIDFont.pm line 290.
Use of uninitialized value in hash element at /usr/local/share/perl/5.26.1/PDF/API2/Resource/CIDFont.pm line 290.
Use of uninitialized value in hash element at /usr/local/share/perl/5.26.1/PDF/API2/Resource/CIDFont.pm line 290.

This comes from https://github.com/ssimms/pdfapi2/blob/1b998771a82aab35cd633e9ad57f9020dfaea83c/lib/PDF/API2/Resource/CIDFont.pm#L276 only returning 253 instead of 256 strings, and thus the line above mapping (253..255) onto undef.

Old versions (at least 2.033-old) had a no warnings qw[ deprecated recursion uninitialized ]; in the code, so I assume that this is maybe no error. And map { unpack( 'U*', decode( $enc, pack( 'C*', $_ ) ) ) } (0..255) would do something which looks similar in outcome (to me^^), but doesn't have the gaps, but that is, as said before, just guess work...

Thanks in any case and best regards, Sven

svenoe commented 8 months ago

This is probably related to the perl version. See my follow up post in https://github.com/PhilterPaper/Perl-PDF-Builder/issues/205

Thus I will close this issue. Best regards, Sven