% Copyright (C) 1994, 1996 Aladdin Enterprises. All rights reserved. % % This file is part of Aladdin Ghostscript. % % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author % or distributor accepts any responsibility for the consequences of using it, % or for whether it serves any particular purpose or works at all, unless he % or she says so in writing. Refer to the Aladdin Ghostscript Free Public % License (the "License") for full details. % % Every copy of Aladdin Ghostscript must include a copy of the License, % normally in a plain ASCII text file named PUBLIC. The License grants you % the right to copy, modify and redistribute Aladdin Ghostscript, but only % under certain conditions described in the License. Among other things, the % License requires that the copyright notice and this notice be preserved on % all copies. % pdf_2ps.ps % PDF to PostScript additions to PDF reader. GS_PDF_ProcSet begin pdfdict begin /.setlanguagelevel where { pop 2 .setlanguagelevel } if .currentglobal true .setglobal userdict /pdf2psdict 30 dict put pdf2psdict begin % Generate a sufficiently unique name (at least unique within the current % save/restore environment). /uniqueid# { userdict length { dup neg =string cvs dup 0 (_) putinterval cvn userdict 1 index known not { exch pop exit } if pop 1 add } loop } bdef % "Wrap" all the runtime operators so they call #exec. % Make sure we have enough room in the current dictionary for this. currentdict dup maxlength numargsdict length add .setmaxlength numargsdict { 1 index load exch 2 index exch /#exec cvx 4 packedarray cvx def } forall /pdfmark /pdfmark load dup type /operatortype eq { 1 packedarray cvx } if { /pdfmark counttomark 1 sub #exec } bind aload length 1 add packedarray cvx def % Define #exec so it also prints out its arguments. /dictwrite# % dictwrite# - { dup length 240 le { 1 index (mark ) writestring { exch 2 index exch write# 1 index ( ) writestring 1 index exch write# 2 index (\n) writestring } forall dup (.dicttomark) writestring } { 2 copy length write=only 1 index ( dict\n) writestring { exch 2 index dup (dup ) writestring exch write# 1 index dup ( ) writestring exch write# dup ( put\n) writestring } forall } ifelse pop } bdef /fontwrite# % fontwrite# - { % Find the named font and then modify it. 2 copy /FontName get =string cvs { dup dup length 1 sub 1 getinterval (%) ne { exit } if 0 1 index length 1 sub getinterval } loop cvn write===only 1 index ( findfont ) writestring % Load the appropriate Encoding, by name if possible. dup /Encoding get dup dup StandardEncoding eq exch ISOLatin1Encoding eq or % Stack: file font encoding stdbool { StandardEncoding eq { (StandardEncoding) } { (ISOLatin1Encoding) } ifelse 2 index exch writestring } { 2 index exch write# } ifelse % Check for modified Metrics. dup /Metrics .knownget { 2 index ( ) writestring 2 index exch write# } { 1 index ( null) writestring } ifelse 1 index ( .updatefont { /_ exch definefont } if\n) writestring pop pop } bdef /write#dict 10 dict dup begin /arraytype { dup xcheck { (}) ({) } { (]) ([) } ifelse 2 index length 0 eq { 3 index exch writestring exch } { 3 -1 roll { 3 index 2 index writestring 3 index exch write# pop (\n) } forall } ifelse pop writestring } bdef /dicttype { null userdict { 3 index eq { exch pop exit } if pop } forall dup null eq { pop 2 copy dup /FID known { fontwrite# } { dictwrite# } ifelse 1 index ( userdict ) writestring uniqueid# 2 index 1 index write# 2 index ( 2 index put) writestring userdict exch 3 -1 roll put pop } { exch pop cvx write===only } ifelse } bdef /filetype { % Convert all files into currentfile, on the theory that % any file-based data will be copied in-line. pop (currentfile) writestring } bdef /marktype { pop ([) writestring } bdef /packedarraytype /arraytype load def /realtype { dup abs 16#ffffff le { dup dup cvi eq { cvi } if } if write=only } bdef end def /write# { dup type //write#dict exch .knownget { exec } { write===only } ifelse } bind def % Rebind the procedures that conditionally write out PostScript. /# % ... # - { 1 index load 3 1 roll #exec } bdef /#? % - #? { /PSout where { pop true } { false } ifelse } bdef /defined# % defined# { dup where { exch get } { pop false } ifelse } bdef /#exec % ... #exec - { /PSout where { pop dup ([) eq { pop counttomark 1 sub } if -1 1 { 1 add index PSout exch write# PSout ( ) writestring } for PSout exch write= } { pop pop } ifelse exec } bdef /#dsc % mark ... #dsc - { /PSout where { pop counttomark { counttomark -1 roll PSout exch write=only } repeat pop PSout (\n) writestring } { cleartomark } ifelse } bdef /copyfile# % copyfile# - { findlibfile { exch pop } { (r) file } % let the error happen ifelse { dup =string readline pop (%BEGIN) eq { exit } if } loop { dup =string readline not { pop exit } if dup (%END) eq { pop exit } if { ( ) anchorsearch { pop } { (\t) anchorsearch { pop } { exit } ifelse } ifelse } loop dup () eq { true } { dup 0 1 getinterval (%) eq } ifelse { pop } { (%) search { exch pop exch pop } if mark exch #dsc } ifelse } loop closefile } bdef /#dscfile % #dscfile - { /PSout where { pop /PSNoProcSet defined# { PSout exch write===only PSout ( runlibfile\n) writestring } { copyfile# } ifelse } { pop } ifelse } bdef % Rebind Is, which constructs a data source for an image. % pdf_draw defined it to simply retrieve the stream. /ID_draw /ID load def /Is_draw /Is load def /EI_draw /EI load def userdict /Is_string null put % establish a binding userdict /Is_data null put % ditto /ID_proc1 {/ASCIIHexDecode filter} def % no bind /ID_proc2 {/ASCII85Decode filter /RunLengthDecode filter} def % no bind /ID { /PSout where { pop dup length 1 add dict copy dup /FilterProc PSLevel1 { /ID_proc1 } { /ID_proc2 } ifelse load /PSBinaryOK defined# { dup length 2 sub 2 exch getinterval } if dup length 0 eq { pop pop pop } { put } ifelse } if ID_draw } bdef /Is % Is { /PSout where { pop dup /DataSource get string /Is_string exch store /Is_data [ PSout PSLevel1 { /PSBinaryOK defined# { /NullEncode } { /ASCIIHexEncode } ifelse filter } { /PSBinaryOK defined# { Is_string length /RunLengthEncode filter } { /ASCII85Encode filter dup Is_string length /RunLengthEncode filter exch } ifelse } ifelse ] store Is_draw { Is_string readstring pop Is_data 0 get 1 index writestring } aload length 1 add packedarray cvx } { Is_draw } ifelse } bdef /EI { /PSout where { pop Is_data { closefile } forall } { EI_draw } ifelse } bdef % Rebind readfontfilter, which constructs the filter that % reads the text of an embedded Type 1 (and eventually Type 3) font. /readfontfilter_orig /readfontfilter load def /readfontfilter { % readfontfilter dup type /filetype eq { cvlit 100 string /readstring cvx /pop cvx 4 array astore cvx } if /copyfontdata cvx 2 array astore cvx 0 () /SubFileDecode filter } bdef /copyfontdata { % copyfontdata exec /PSout where { pop PSout 1 index writestring } if } bdef currentdict readonly pop end % pdf2psdict .setglobal end % pdfdict end % GS_PDF_ProcSet .