diff --git a/lib/PDF/Font/Loader.rakumod b/lib/PDF/Font/Loader.rakumod index 9872a4f..159a844 100644 --- a/lib/PDF/Font/Loader.rakumod +++ b/lib/PDF/Font/Loader.rakumod @@ -20,7 +20,7 @@ class PDF::Font::Loader:ver<0.7.8> { $class.load-font: :$font-buf, |c; } - my subset Type1 where .font-format ~~ 'Type 1'|'CFF' && !.is-internally-keyed-cid; + my subset Type1 where .font-format ~~ 'Type 1'|'CFF'|'OpenType' && !.is-internally-keyed-cid; my subset CIDEncoding of Str where m/^[identity|utf]/; multi method load-font( $?: Font::FreeType::Face :$face!, diff --git a/lib/PDF/Font/Loader/Enc.rakumod b/lib/PDF/Font/Loader/Enc.rakumod index fa455a2..d3ce74b 100644 --- a/lib/PDF/Font/Loader/Enc.rakumod +++ b/lib/PDF/Font/Loader/Enc.rakumod @@ -232,7 +232,7 @@ method make-to-unicode-cmap(:$to-unicode = self.to-unicode) { while $cid < last-char && $to-unicode[$cid + 1] && ($cid+1) div 256 == $start-byte { my $this-ord := $to-unicode[$cid + 1]; if ($this-ord == $last-ord + 1) { - if ++$ord-run-len >= 6 { + if ++$ord-run-len >= 5 { # We've encountered a run of ascending cids + ords. # Process them more elegantly on our next loop. $cid -= $ord-run-len; diff --git a/lib/PDF/Font/Loader/FontObj.rakumod b/lib/PDF/Font/Loader/FontObj.rakumod index f929123..92e33cf 100644 --- a/lib/PDF/Font/Loader/FontObj.rakumod +++ b/lib/PDF/Font/Loader/FontObj.rakumod @@ -168,8 +168,8 @@ method encode($text is raw, |c) { method !font-type-entry returns Str { given $!face.font-format { - when 'Type 1'|'CFF' { 'Type1' } - when 'TrueType'|'OpenType' { 'TrueType' } + when 'Type 1'|'CFF'|'OpenType' { 'Type1' } + when 'TrueType' { 'TrueType' } default { fail "unable to handle font type: $_" } } } @@ -203,13 +203,18 @@ method !make-other-font-file(Blob:D $buf) { given $!face.font-format { when 'OpenType' { - %dict = /; + %dict = $!face.is-internally-keyed-cid + ?? / !! /; } when 'CFF' { - # Peek at the buffer to distinguish simple CFF from OpenType/CFF - # See https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font - my subset OpenTypeCFF of Blob:D where .subbuf(0,4).decode('latin-1') eq 'OTTO'; - %dict = ($buf ~~ OpenTypeCFF) ?? / !! /; + %dict = /; + if Font::FreeType.^ver <= v0.5.4 { + # Peek at the buffer to distinguish simple CFF from OpenType/CFF + # See https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font + my subset OpenTypeCFF of Blob:D where .subbuf(0,4).decode('latin-1') eq 'OTTO'; + %dict = / + if $buf ~~ OpenTypeCFF; + } } } @@ -274,7 +279,7 @@ method font-descriptor { $dict //= .usWeightClass; $dict //= .xAvgCharWidth; - if $!face.font-format ~~ 'FreeType'|'OpenType' { + if $!face.is-internally-keyed-cid { # applicable to CID font descriptors my $buf = .panose.Blob; $buf.prepend: (.sFamilyClass div 256, .sFamilyClass mod 256); diff --git a/lib/PDF/Font/Loader/FontObj/CID.rakumod b/lib/PDF/Font/Loader/FontObj/CID.rakumod index c1fb5aa..51e8cb6 100644 --- a/lib/PDF/Font/Loader/FontObj/CID.rakumod +++ b/lib/PDF/Font/Loader/FontObj/CID.rakumod @@ -24,8 +24,8 @@ submethod TWEAK { # /Subtype entry for the descendant CID font method !cid-font-type-entry { given $.face.font-format { - when 'CFF' { 'CIDFontType0' } - when 'TrueType'|'OpenType' {'CIDFontType2'} + when 'CFF'|'OpenType' { 'CIDFontType0' } + when 'TrueType' {'CIDFontType2'} default { fail "unable to handle CID font type: $_" } } } diff --git a/t/fontobj.pdf b/t/fontobj.pdf index 01af6e1..82c3caa 100644 Binary files a/t/fontobj.pdf and b/t/fontobj.pdf differ diff --git a/t/reuse-type1.pdf b/t/reuse-type1.pdf index 33512a8..b0949b4 100644 Binary files a/t/reuse-type1.pdf and b/t/reuse-type1.pdf differ diff --git a/t/reuse-unembedded.pdf b/t/reuse-unembedded.pdf index 240b838..03298e2 100644 Binary files a/t/reuse-unembedded.pdf and b/t/reuse-unembedded.pdf differ diff --git a/t/type1-encoding.t b/t/type1-encoding.t index b4c117b..26905f6 100644 --- a/t/type1-encoding.t +++ b/t/type1-encoding.t @@ -9,7 +9,7 @@ my PDF::Lite $pdf .= new; my PDF::Lite::Page $page = $pdf.add-page; my @differences = 1, 'b', 'c', 10, 'y', 'z'; my PDF::Content::FontObj $times = PDF::Font::Loader.load-font( :file, :@differences ); -is-deeply $times.encode('abcdxyz', :cids), buf8.new(97,1,2,100,120,10,11), 'differences encoding'; +is-deeply $times.encode('abcdxyz', :cids).list, (97,1,2,100,120,10,11), 'differences encoding'; $page.text: { .text-position = 10,500; .font = $times; @@ -26,7 +26,7 @@ lives-ok { $times = PDF::Font::Loader.load-font( :$dict ); }, 'reload font from dict - lives'; -is-deeply $times.encode('abcdxyz', :cids), buf8.new(97,1,2,100,120,10,11), 'differences re-encoding'; +is-deeply $times.encode('abcdxyz', :cids).list, (97,1,2,100,120,10,11), 'differences re-encoding'; done-testing;