[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 01/01: Handle pdfs > v1.4 loaded by \X'pdf: pdfpic.
From: |
Deri James |
Subject: |
[groff] 01/01: Handle pdfs > v1.4 loaded by \X'pdf: pdfpic. |
Date: |
Sun, 10 Oct 2021 14:39:05 -0400 (EDT) |
deri pushed a commit to branch master
in repository groff.
commit 7a5d3ee0974568265901edff398dc20466df2ab5
Author: Deri James <deri@chuzzlewit.myzen.co.uk>
AuthorDate: Sun Oct 10 19:34:32 2021 +0100
Handle pdfs > v1.4 loaded by \X'pdf: pdfpic.
* src/devices/gropdf/gropdf.pl: Improve loading of pdfs above
version 1.4, i.e. handle compressed nodes in /ObjStm. Also improve
code in \X'pdf: import'.
---
ChangeLog | 8 ++++
src/devices/gropdf/gropdf.pl | 94 ++++++++++++++++++++++++++++++--------------
2 files changed, 73 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f56cd1d..338d58a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2021-10-10 Deri James <deri@chuzzlewit.myzen.co.uk>
+ Handle pdfs > v1.4 loaded by \X'pdf: pdfpic.
+
+ * src/devices/gropdf/gropdf.pl: Improve loading of pdfs above
+ version 1.4, i.e. handle compressed nodes in /ObjStm. Also improve
+ code in \X'pdf: import'.
+
+2021-10-10 Deri James <deri@chuzzlewit.myzen.co.uk>
+
Add new background boxes to gropdf.
* src/devices/gropdf/gropdf.pl: New \X'pdf background' command.
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 3374d07..ac333a8 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -1015,8 +1015,8 @@ sub do_x
my $lly=$xprm[4];
my $urx=$xprm[5];
my $ury=$xprm[6];
- my $wid=$xprm[7];
- my $hgt=$xprm[8]||-1;
+ my $wid=GetPoints($xprm[7]);
+ my $hgt=GetPoints($xprm[8])||-1;
my $mat=[1,0,0,1,0,0];
if (!exists($incfil{$fil}))
@@ -1101,11 +1101,11 @@ sub do_x
if ($flag eq '-C' and $ll > $wid)
{
- $xpos=int(($ll-$wid)/2);
+ $xpos+=int(($ll-$wid)/2);
}
elsif ($flag eq '-R' and $ll > $wid)
{
- $xpos=$ll-$wid;
+ $xpos+=$ll-$wid;
}
$ypos+=$hgt;
@@ -1275,16 +1275,16 @@ sub do_x
else
{
$bgstack[$sptr]->[5]=GraphY($ypos);
- $bgbox=DrawBox(pop(@bgstack)).$bgbox;
- }
+ $bgbox=DrawBox(pop(@bgstack)).$bgbox;
}
}
+ }
elsif (lc($type) eq 'footnote')
{
my $t=GetPoints($xprm[0]);
$boxmax=($t<0)?abs($t):GraphY($t);
}
- else
+ else
{
my $bgtype=0;
@@ -1320,12 +1320,12 @@ sub do_x
}
else
{
-
push(@bgstack,[$bgtype,$strkcol,$fillcol,$bg,GraphY($ypos),GraphY($bg[3]||0),$bgwt
|| 0.4]);
- }
+
push(@bgstack,[$bgtype,$strkcol,$fillcol,$bg,GraphY($ypos),GraphY($bg[3]||0),$bgwt
|| 0.4]);
}
}
}
}
+ }
elsif (lc(substr($xprm[0],0,9)) eq 'papersize')
{
my ($px,$py)=split(',',substr($xprm[0],10));
@@ -1661,6 +1661,7 @@ sub LoadPDF
# $pdftxt=~s/\]/ \]/g;
my (@pdfwds)=split(' ',$pdftxt);
my $wd;
+ my $root;
while ($wd=nextwd(\@pdfwds),length($wd))
{
@@ -1670,6 +1671,27 @@ sub LoadPDF
shift(@pdfwds); shift(@pdfwds);
unshift(@pdfwds,$1) if defined($1) and length($1);
$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;
+ }
+
+ $root=$curobj if ref($o->{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}))
{
@@ -1681,6 +1703,7 @@ sub LoadPDF
}
}
+ $pdf->[0]=$pdf->[$root] if !defined($pdf->[0]);
my $catalog=${$pdf->[0]->{OBJ}->{Root}};
my $page=FindPage(1,$pdf);
my $xobj=++$objct;
@@ -1689,25 +1712,10 @@ sub LoadPDF
foreach my $o (@{$pdf})
{
- if (exists($o->{STREAMPOS}))
- {
- my $l;
-
- $l=$o->{OBJ}->{Length} if exists($o->{OBJ}->{Length});
-
- $l=$pdf->[$$l]->{OBJ} if (defined($l) && ref($l) eq 'OBJREF');
-
- Msg(1,"Unable to determine length of stream
\@$o->{STREAMPOS}->[0]") if !defined($l);
-
- sysseek(PD,$o->{STREAMPOS}->[0],0);
- Msg(0,'Failed to read all the stream') if $l !=
sysread(PD,$o->{STREAM},$l);
-
- if ($gotzlib and exists($o->{OBJ}->{'Filter'}) and
$o->{OBJ}->{'Filter'} eq '/FlateDecode')
- {
- $o->{STREAM}=Compress::Zlib::uncompress($o->{STREAM});
- delete($o->{OBJ }->{'Filter'});
- }
- }
+ if (exists($o->{STREAMPOS}) and !exists($o->{STREAM}))
+ {
+ LoadStream($o,$pdf);
+ }
}
close(PD);
@@ -1716,7 +1724,7 @@ sub LoadPDF
my $BBox;
my $insmap={};
- foreach my $k (qw( MediaBox ArtBox TrimBox BleedBox CropBox ))
+ foreach my $k (qw( ArtBox TrimBox BleedBox CropBox MediaBox ))
{
$BBox=FindKey($pdf,$page,$k);
last if $BBox;
@@ -1758,12 +1766,40 @@ sub LoadPDF
($mat->[4],$mat->[5])=split(' ',PutXY($xpos,$ypos));
$pages->{'Resources'}->{'XObject'}->{$xonm}=BuildObj($xobj,{'Type' =>
'/XObject', 'BBox' => $BBox, 'Name' => "/$xonm", 'FormType' => 1, 'Subtype' =>
'/Form', 'Length' => 0, 'Type' => "/XObject", 'Resources' => \%incres});
+ if ($BBox->[0] != 0 or $BBox->[1] != 0)
+ {
+ my (@matrix)=(1,0,0,1,-$BBox->[0],-$BBox->[1]);
+ $obj[$xobj]->{DATA}->{Matrix}=\@matrix;
+ }
+
BuildStream($xobj,$pdf,$pdf->[$page]->{OBJ}->{Contents});
$/=$keepsep;
return([$xonm,$BBox] );
}
+sub LoadStream
+{
+ my $o=shift;
+ my $pdf=shift;
+ my $l;
+
+ $l=$o->{OBJ}->{Length} if exists($o->{OBJ}->{Length});
+
+ $l=$pdf->[$$l]->{OBJ} if (defined($l) && ref($l) eq 'OBJREF');
+
+ Msg(1,"Unable to determine length of stream \@$o->{STREAMPOS}->[0]") if
!defined($l);
+
+ sysseek(PD,$o->{STREAMPOS}->[0],0);
+ Msg(0,'Failed to read all the stream') if $l !=
sysread(PD,$o->{STREAM},$l);
+
+ if ($gotzlib and exists($o->{OBJ}->{'Filter'}) and $o->{OBJ}->{'Filter'}
eq '/FlateDecode')
+ {
+ $o->{STREAM}=Compress::Zlib::uncompress($o->{STREAM});
+ delete($o->{OBJ }->{'Filter'});
+ }
+}
+
sub BuildStream
{
my $xobj=shift;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 01/01: Handle pdfs > v1.4 loaded by \X'pdf: pdfpic.,
Deri James <=