fix offset calculation bug when writing object streams

git-svn-id: svn+q:///qpdf/trunk@657 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-03-08 18:58:34 +00:00
parent 8bd0911281
commit 1c7c6dd161
1 changed files with 30 additions and 10 deletions

View File

@ -72,6 +72,7 @@ my $st_done = ++$cur_state;
my @ostream = ();
my @ostream_offsets = ();
my @ostream_discarded = ();
my $ostream_idx = 0;
my $ostream_id = 0;
my $ostream_extends = "";
@ -130,14 +131,18 @@ while (defined($line = get_line()))
}
elsif ($state == $st_in_ostream_dict)
{
if ($line =~ m,/Extends (\d+ 0 R),)
{
$ostream_extends = $1;
}
elsif ($line =~ m/^stream/)
if ($line =~ m/^stream/)
{
$state = $st_in_ostream_offsets;
}
else
{
push(@ostream_discarded, $line);
if ($line =~ m,/Extends (\d+ 0 R),)
{
$ostream_extends = $1;
}
}
# discard line
}
elsif ($state == $st_in_ostream_offsets)
@ -149,6 +154,10 @@ while (defined($line = get_line()))
$state = $st_in_ostream_outer;
push(@ostream, $line);
}
else
{
push(@ostream_discarded, $line);
}
# discard line
}
elsif ($state == $st_in_ostream_outer)
@ -327,16 +336,20 @@ sub write_ostream
++$onum;
$offsets .= "$onum $_\n";
}
my $offset_adjust = length($offsets);
$first += length($offsets);
$stream_length += length($offsets);
print " /Length $stream_length\n";
print " /N $n\n";
print " /First $first\n";
my $dict_data = "";
$dict_data .= " /Length $stream_length\n";
$dict_data .= " /N $n\n";
$dict_data .= " /First $first\n";
if ($ostream_extends)
{
print " /Extends $ostream_extends\n";
$dict_data .= " /Extends $ostream_extends\n";
}
print ">>\n";
$dict_data .= ">>\n";
$offset_adjust += length($dict_data);
print $dict_data;
print "stream\n";
print $offsets;
foreach (@ostream)
@ -344,9 +357,16 @@ sub write_ostream
print $_;
}
for (@ostream_discarded)
{
$offset -= length($_);
}
$offset += $offset_adjust;
$ostream_idx = 0;
$ostream_id = 0;
@ostream = ();
@ostream_offsets = ();
@ostream_discarded = ();
$ostream_extends = "";
}