summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlgs/lib/pdf_main.ps
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlgs/lib/pdf_main.ps')
-rw-r--r--Master/tlpkg/tlgs/lib/pdf_main.ps147
1 files changed, 113 insertions, 34 deletions
diff --git a/Master/tlpkg/tlgs/lib/pdf_main.ps b/Master/tlpkg/tlgs/lib/pdf_main.ps
index a71a4dad5c4..efe74533d2f 100644
--- a/Master/tlpkg/tlgs/lib/pdf_main.ps
+++ b/Master/tlpkg/tlgs/lib/pdf_main.ps
@@ -13,7 +13,7 @@
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
-% $Id: pdf_main.ps 8159 2007-08-01 17:19:50Z ray $
+% $Id: pdf_main.ps 8486 2008-01-17 03:12:45Z alexcher $
% pdf_main.ps
% PDF file- and page-level operations.
@@ -136,7 +136,7 @@ systemdict begin
currentdict /runpdfstring .undef
-/runpdfbegin { % <file> runpdf -
+/runpdfbegin { % <file> runpdfbegin -
userdict begin
% It turns out that the PDF interpreter uses memory more
% effectively if it is run under at least one level of save.
@@ -151,6 +151,9 @@ currentdict /runpdfstring .undef
GS_PDF_ProcSet begin
pdfdict begin
pdfopen begin
+} bind def
+
+/runpdfpagerange { % - runpdfpagerange <firstpage#> <lastpage#>
/FirstPage where
{ pop FirstPage dup pdfpagecount gt
{ (\nRequested FirstPage is greater than the number of pages in the file: ) print
@@ -172,15 +175,13 @@ currentdict /runpdfstring .undef
} bind def
/dopdfpages { % firstpage# lastpage# dopdfpages -
- << /PDFScanRules true >> setuserparams % set scanning rules for PDF vs. PS
- true .setaccuratecurves % unlike PS, PDF seems to need this
+ << /PDFScanRules //true >> setuserparams % set scanning rules for PDF vs. PS
1 exch
{ dup /Page# exch store
QUIET not { (Page ) print dup == flush } if
pdfgetpage pdfshowpage
} for
- false .setaccuratecurves % restore accuratecurves behaviour
- << /PDFScanRules null >> setuserparams % restore scanning rules for PS
+ << /PDFScanRules //null >> setuserparams % restore scanning rules for PS
} bind def
/runpdfend {
@@ -194,12 +195,68 @@ currentdict /runpdfstring .undef
2 vmreclaim % couldn't hurt
} bind def
+% - pdf_collection_files [temp_files] show_container
+/pdf_collection_files {
+ {} //true
+ Trailer /Root oget /Collection knownoget {
+ /D knownoget { % We have default document in the collection
+ Trailer /Root oget /Names knownoget {
+ /EmbeddedFiles knownoget {
+ exch nameoget dup //null ne {
+ /EF knownoget {
+ /F knownoget {
+ //true resolvestream % {} true strm
+ //null (w) .tempfile % {} true strm (name) file
+ 3 -1 roll % {} true (name) file strm
+ 32768 string % {} true (name) file strm (buf)
+ { 3 copy readstring % {} true (name) file strm (buf) file (data) bool
+ 3 1 roll % {} true (name) file strm (buf) bool file (data)
+ writestring % {} true (name) file strm (buf) bool
+ not { exit } if
+ } loop
+ pop closefile % {} true (name) file
+ closefile % {} true (name)
+ 3 1 roll pop pop % (name)
+ .currentglobal //true .setglobal
+ exch dup length string copy 1 array astore
+ exch .setglobal //false
+ } if
+ } if
+ } {
+ pop
+ } ifelse
+ } {
+ pop
+ } ifelse
+ } {
+ pop
+ } ifelse
+ } if
+ } if
+} bind def
+
/runpdf { % <file> runpdf -
- runpdfbegin
- dopdfpages
- runpdfend
+ //runpdfbegin exec
+ //pdf_collection_files exec {
+ copy_trailer_attrs
+ //runpdfpagerange exec
+ //dopdfpages exec
+ } if
+ //runpdfend exec
+ {
+ dup (r) file
+ //runpdfbegin exec
+ copy_trailer_attrs
+ //runpdfpagerange exec
+ //dopdfpages exec
+ //runpdfend exec
+ deletefile
+ } forall
} bind def
+currentdict /runpdfpagerange .undef
+currentdict /pdf_collection_files .undef
+
end % systemdict
% Redefine the procedure that the C code uses for running piped input.
% It is OK to use { (%stdin) run } here, because a startjob cannot occur.
@@ -215,18 +272,19 @@ pdfdict begin
% Read the cross-reference and trailer sections.
/traileropdict mark
- (<<) cvn { mark } bind
+ (<<) cvn { /dictlevelcount dictlevelcount 1 add store mark } bind
(>>) cvn { { .dicttomark } stopped {
( **** File has unbalanced >> in trailer.\n) pdfformaterror
- } if } bind
+ } if
+ /dictlevelcount dictlevelcount 1 sub def
+ dictlevelcount 0 eq { exit } if
+ } bind
([) cvn { mark } bind % ditto
(]) cvn dup load
% /true true % see .pdfexectoken in pdf_base.ps
% /false false % ibid.
% /null null % ibid.
/R { /resolveR cvx 3 packedarray cvx } bind % see Objects below
- /startxref /exit load
- /startref /exit load % Some application (unknown) misspells startxref
.dicttomark readonly def
% Because of EOL conversion, lines with fixed contents might be followed
@@ -277,11 +335,9 @@ pdfdict begin
pop % Stack: <err count> <obj#> <loc> <gen#> <tag>
dup /n eq { % xref line tag is /n
pop % pop dup of line tag
- Objects 3 index lget null eq { % later update might have set it
- 0 3 1 roll % Set ObjectStream object number = 0
- setxrefentry % Save xref entry
- 3 -1 roll pop % Remove ObjectStream object onumber
- } if
+ 0 3 1 roll % Set ObjectStream object number = 0
+ //false setxrefentry % Save xref entry, don't change existing entries
+ 3 -1 roll pop % Remove ObjectStream object onumber
}
{ % xref line tag was not /n
/f ne % verify that the tag was /f
@@ -298,6 +354,7 @@ pdfdict begin
( **** Warning: length of some xref entries is not equal to 20 bytes.\n)
pdfformaterror
} if
+ /dictlevelcount 0 def
PDFfile traileropdict .pdfrun
} bind def
@@ -341,7 +398,7 @@ pdfdict begin
% (loc: ) print 1 index pdfstring cvs print ( ) print
% (gen: ) print dup === flush
0 3 1 roll % set stream number = 0
- setxrefentry
+ //false setxrefentry
3 -1 roll pop % remove stream number
} bind
% XRef entry type 2 - compressed object type xref entry
@@ -350,7 +407,7 @@ pdfdict begin
% (obj num: ) print 2 index pdfstring cvs print ( ) print
% (field 2: ) print 1 index pdfstring cvs print ( ) print
% (field 3: ) print dup === flush
- 0 setxrefentry pop % set generation number = 0
+ 0 //false setxrefentry pop % set generation number = 0
} bind
] def
@@ -437,7 +494,14 @@ pdfdict begin
% non-compliant PDF files that we have to do this too.
PDFfile pdfstring 0 4 getinterval readstring pop
(xref) eq
- { readorigxref } % 'xref' -> original xref table
+ {
+ readorigxref % 'xref' -> original xref table
+ % if hybrid-reference PDF, also fetch the entries
+ % found in the XRef stream pointed by /XRefStm
+ dup /XRefStm knownoget {
+ readpdf15xref pop
+ } if
+ }
{ readpdf15xref } % otherwise assume PDF 1.5 xref stream
ifelse
} bind def
@@ -469,6 +533,10 @@ pdfdict begin
if
pdfopenfile begin
pdfopencache
+ currentdict end
+} bind def
+
+/copy_trailer_attrs { % - copy_trailer_attrs -
writeoutputintents
.writepdfmarks {
% Copy bookmarks (outline) to the output.
@@ -478,7 +546,6 @@ pdfdict begin
} if
} if
} if % end .writepdfmarks
- currentdict end
} bind def
% Verify that each entry in the xref table is pointing at an object with
@@ -559,7 +626,7 @@ pdfdict begin
/PDFsource PDFfile def
/Repaired false def
currentglobal true .setglobal globaldict begin
- /TTFWarnList 0 dict def /UndefProcList 0 dict def
+ /UndefProcList 0 dict def
end .setglobal
PDFfile dup 0 setfileposition
0 () /SubFileDecode filter % to avoid file closure
@@ -750,18 +817,9 @@ pdfdict begin
( <<<<\n) stderrprint
} ifelse
} bind def
-% The TTFWarnList is the list of all TrueType fonts that were not embedded.
% The UndefProcList collects noisy warnings.
% This gets rid of many multiple warnings from pdf_font.ps
/printCollectedWarnings {
- TTFWarnList length 0 gt {
- (\n **** Warning: Fonts with Subtype = /TrueType should be embedded.\n)
- stderrprint
- ( The following fonts were not embedded:\n)
- stderrprint
- [ TTFWarnList { pop .namestring (\t\t\t) exch concatstrings (\n) concatstrings } forall ]
- { lt } .sort { stderrprint } forall
- } if
UndefProcList length 0 gt {
(\n **** Embedded font uses undefined procedure\(s\): ) stderrprint
UndefProcList {
@@ -797,7 +855,26 @@ pdfdict begin
{ 2 index /Count knownoget { 0 lt { neg } if } if
/Count exch 3 index
}
- ifelse { linkdest } stopped
+ ifelse
+ {
+ dup /A knownoget {
+ dup /URI known {
+ /A mark 3 2 roll % <<>> /A [ <<action>>
+ { oforce } forall
+ .dicttomark
+ 3 2 roll
+ } {
+ dup /D knownoget {
+ exch pop exch dup length dict copy dup /Dest 4 -1 roll put
+ } {
+ /N knownoget { % Assume /S /Named
+ namedactions exch .knownget { exec } if
+ } if
+ } ifelse
+ } ifelse
+ } if
+ linkdest
+ } stopped
{
cleartomark % ignore this link
( **** Warning: Outline has invalid link that was discarded.\n)
@@ -1453,7 +1530,9 @@ currentdict /PDF2PS_matrix_key undef
} ifelse
grestore
% Draw the annotations
- /Annots knownoget { { oforce drawannot } forall } if
+ //systemdict /ShowAnnots .knownget not { //true } if {
+ /Annots knownoget { { oforce drawannot } forall } if
+ } if
//systemdict /ShowAcroForm .knownget { //true eq } { //false } ifelse {
Trailer /Root oget /AcroForm knownoget { draw_acro_form } if
} if