diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2013-05-27 09:23:35 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2013-05-27 09:23:35 +0100 |
commit | c00e028429fa7bbbe1f3902286d5b3710b670815 (patch) | |
tree | 572ac329436bf63ce25630924a0e5e12d4c63449 | |
parent | 3282874fbe636652df435fdacef4ebc3f3ee426b (diff) | |
download | ghostpdl-c00e028429fa7bbbe1f3902286d5b3710b670815.tar.gz |
pdfwrite - better support for PageLabels
Bug #693929 " Regression: Error: /undefined in --run--"
This code now properly flattens a PageLabels number tree into a single node
tree, which it converts to a string for inclusion in the output.
In addition to flattening the tree we also perform considerable error checking
on the tree construction, and we limit the number of page elements to 1000.
This is because PostScript strings are limited to 64k and we use a string to
pass the data to the device for inclusion. If we exceed 1000 elements then
we simply abort the PageLabels (and print a warning on the back channel)
No differences expected, this is not a printing eleent
-rw-r--r-- | gs/Resource/Init/gs_pdfwr.ps | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/gs/Resource/Init/gs_pdfwr.ps b/gs/Resource/Init/gs_pdfwr.ps index 1308c45a6..557d706c5 100644 --- a/gs/Resource/Init/gs_pdfwr.ps +++ b/gs/Resource/Init/gs_pdfwr.ps @@ -467,6 +467,56 @@ userdict /.pdfcvstring () put .systemvar exch signalerror } bind def +/.CountLeafs { + 0 exch + { + oforce dup type /dicttype eq { + /Limits knownoget { + dup type /arraytype eq { + 1 get 2 copy lt { + exch pop + }{ + pop + }ifelse + }{ + (invalid number tree, /Limits not an array\n) print + pop pop 0 exit + } ifelse + }{ + (invalid number tree, /Limits not defined in intermediate or leaf node\n) print + pop pop 0 exit + }ifelse + } { + (invalid number tree, /Kids entry not a dictionary\n) print + pop pop 0 exit + } ifelse + } forall +} bind def + +/.ExtractLeafs +{ + { + oforce /Nums knownoget { + dup length 1 sub 0 2 3 -1 roll { + %% dict array index + dup %% dict array index index + 2 index exch get %% dict array index + 20 string cvs cvn %% dict array index name + exch 1 add %% dict array name index+1 + 2 index exch oget %% dict array name object + 3 index %% dict array name object dict + 3 1 roll %% dict array dict name object + put %% dict array + } for + pop %% array + }{ + /Kids knownoget { + .ExtractLeafs + } if + } ifelse + } forall +} bind def + /.pdfpagelabels { dup type /dicttype eq { dup /Nums knownoget { @@ -486,7 +536,28 @@ userdict /.pdfcvstring () put } if cleartomark }{ /Kids knownoget { - (PageLabel tree too complex, ignoring PageLabels\n) print flush + dup .CountLeafs dup 1000 ge { + (PageLabel tree too complex, ignoring PageLabels\n) print flush + pop pop + }{ + dict exch .ExtractLeafs mark exch dup length 0 1 3 -1 roll { + dup 20 string cvs cvn %% mark dict index name + 2 index exch .knownget{ + %% mark ... dict index object + 3 -1 roll %% mark ... index object dict + }{ + pop + }ifelse + } for + pop + counttomark array astore + 1 dict dup begin exch /Nums exch def end + .pdfcvs + mark /pdfpagelabels 3 -1 roll .pdfputparams + dup type /booleantype ne { + /pdfpagelabels .pdfparamerror + } if cleartomark + }ifelse }{ (Invalid number tree in PageLabels, ignoring PageLabels\n) print flush }ifelse |