deri pushed a commit to branch master in repository groff. commit 7c0358816253817a3594be6402c4b9b7e68db01d Author: Deri James <d...@chuzzlewit.myzen.co.uk> AuthorDate: Sun Jan 7 19:51:35 2024 +0000
Fix for including pdf v1.7 files. PDF 1.5 introduced object type ObjStm which can contain a bunch of objects in its own compressed stream, but there is a restriction that if an object has its own stream it cannot be included into the ObjStm (i.e. no stream within stream). Gropdf has supported this for some years, but it has come to light that some pdfs have a "skeleton" object which contains the stream and the rest of the object is held in the ObjStm stream. Also fix incorrect application of patch in bug #65112. * src/devices/gropdf/gropdf.pl: If a skeleton object exists at the top-level and in an ObjStm stream, the two objects should be merged. --- src/devices/gropdf/gropdf.pl | 57 +++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl index 3f70a4263..14b7b3312 100644 --- a/src/devices/gropdf/gropdf.pl +++ b/src/devices/gropdf/gropdf.pl @@ -2413,6 +2413,7 @@ sub LoadPDF my (@pdfwds)=split(' ',$pdftxt); my $wd; my $root; + my @ObjStm; while ($wd=nextwd(\@pdfwds),length($wd)) { @@ -2424,24 +2425,7 @@ sub LoadPDF $pdf->[$curobj]->{OBJ}=ParsePDFObj(\@pdfwds); my $o=$pdf->[$curobj]; - if (ref($o->{OBJ}) eq 'HASH' and exists($o->{OBJ}->{Type}) and $o->{OBJ}->{Type} eq '/ObjStm') - { - LoadStream($o,$pdf); - my $pos=$o->{OBJ}->{First}; - my $s=$o->{STREAM}; - my @o=split(' ',substr($s,0,$pos)); - substr($s,0,$pos)=''; - push(@o,-1,length($s)); - - for (my $j=0; $j<=$#o-2; $j+=2) - { - my @w=split(' ',substr($s,$o[$j+1],$o[$j+3]-$o[$j+1])); - $pdf->[$o[$j]]->{OBJ}=ParsePDFObj(\@w); - } - - $pdf->[$curobj]=undef; - } - + push(@ObjStm,$curobj) if (ref($o->{OBJ}) eq 'HASH' and exists($o->{OBJ}->{Type}) and $o->{OBJ}->{Type} eq '/ObjStm'); $root=$curobj if ref($pdf->[$curobj]->{OBJ}) eq 'HASH' and exists($pdf->[$curobj]->{OBJ}->{Type}) and $pdf->[$curobj]->{OBJ}->{Type} eq '/XRef'; } elsif ($wd eq 'trailer' and !exists($pdf->[0]->{OBJ})) @@ -2454,6 +2438,25 @@ sub LoadPDF } } + foreach my $ObjStm (@ObjStm) + { + LoadStream($pdf->[$ObjStm],$pdf); + my $pos=$pdf->[$ObjStm]->{OBJ}->{First}; + my $s=$pdf->[$ObjStm]->{STREAM}; + $s=~s/\%.*?$//m; + my @o=split(' ',substr($s,0,$pos)); + substr($s,0,$pos)=''; + push(@o,-1,length($s)); + + for (my $j=0; $j<=$#o-2; $j+=2) + { + my @w=split(' ',substr($s,$o[$j+1],$o[$j+3]-$o[$j+1])); + $pdf->[$o[$j]]->{OBJ}=ObjMerge($pdf->[$o[$j]]->{OBJ},ParsePDFObj(\@w)); + } + + $pdf->[$ObjStm]=undef; + } + $pdf->[0]=$pdf->[$root] if !defined($pdf->[0]); my $catalog=${$pdf->[0]->{OBJ}->{Root}}; my $page=FindPage(1,$pdf); @@ -2530,6 +2533,22 @@ sub LoadPDF return([$xonm,$BBox] ); } +sub ObjMerge +{ + my $o1=shift; + my $o2=shift; + + return $o1 if !defined($o2); + return $o2 if !defined($o1); + + foreach my $k (keys %{$o2}) + { + $o1->{$k}=$o2->{$k}; + } + + return $o1; +} + sub LoadStream { my $o=shift; @@ -4736,7 +4755,7 @@ sub subs_call { $c[$#c-4]->[0]=MarkSub("#$c[$#c-4]->[0]") if ($c[$#c-4]->[1]); } - elsif ($n2==16) # seac + elsif ($n2==6) # seac { my $ch=$StdEnc{$c[$#c-2]->[0]}; my $chf; _______________________________________________ Groff-commit mailing list Groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit