%!PS-Adobe-2.0%% Copyright (C) 2002 artofcode LLC. All rights reserved.% % This software is provided AS-IS with no warranty, either express or% implied.% % This software is distributed under license and may not be copied,% modified or distributed except as expressly authorized under the terms% of the license contained in the file LICENSE in this distribution.% % For more information about licensing, please refer to% http://www.ghostscript.com/licensing/. For information on% commercial licensing, go to http://www.artifex.com/licensing/ or% contact Artifex Software, Inc., 101 Lucas Valley Road #110,% San Rafael, CA 94903, U.S.A., +1(415)492-9861. % $Id: opdfread.ps,v 1.84 2005/09/07 20:43:36 leonardo Exp $% pdfread.ps - A procset for interpreting an ordered PDF 1.3 file. % This module defines routines for interpreting a PDF file with% a Postscript interpreter. To convert a PDF file into Postscript % just pre-contcatenate this file. The PDF file must satisfy % few constraints :%% 1. It must contain only Postscript level 2 objects encoded with% the PDF 1.3 language. Higher PDF levels must be re-distilled% with CompatibilityLevel=1.3 .%% 2. Objects must be ordered so that any resource be defined before% its usage.%% 3. The PDF file must not include other PDF files.% Consequently we have a single instance of the PDF reader.% We use this fact to simplify binding of the routines.% % 4. The PDF root object must always have the object id 1.% % 5. Generations besides 0 are not allowed.%% 6. xref must appear after all objects.%% Assuming the currentfile isn't positionable.% As a consequence, the reader fully ignores xref. true setglobal % ====================== Error handler =======================% A general error handler prints an error to page. 10 dict begin % A dictionary for local binding /this currentdict def/y 720 def/ebuf 200 string def /prnt { 36 //this /y get moveto //ebuf cvs show //this /y 2 copy get 12 sub put} bind def /newline { 36 //this /y get moveto //this /y 2 copy get 12 sub put} bind def errordict /handleerror{ systemdict begin $error begin newerror { (%%[ Error handled by opdfread.ps : ) print errorname //ebuf cvs print (; OffendingCommand: ) print /command load //ebuf cvs print ( ]%%) = flush /newerror false store vmstatus pop pop 0 ne { grestoreall } if errorname (VMerror) ne { showpage } if initgraphics 0 720 moveto errorname (VMerror) eq { //this /ehsave known { clear //this /ehsave get restore 2 vmreclaim } if vmstatus exch pop exch pop } /Courier 12 selectfont { (ERROR: ) //prnt exec errorname //prnt exec (OFFENDING COMMAND: ) //prnt exec /command load //prnt exec $error /ostack known { (%%[STACK:) = (STACK:) //prnt exec $error /ostack get aload length { //newline exec dup mark eq { (-mark-) dup = show } { dup type /nametype eq { dup xcheck not { (/) show (/) print } if } if dup = //ebuf cvs show } ifelse } repeat } if } ifelse (%%]%) = //systemdict /showpage get exec quit } if end end} bind readonly put end % A dictionary for local binding 50 dict begin % ===================== Debugging ========================================= /DefaultSwitch % <name> DefaultSwitch -{ dup where { pop pop } { false def } ifelse} bind def /=string 256 string def /=only { //=string cvs print} bind def /HexDigits (0123456789ABCDEF) readonly def /PrintHex % <int> PrintHex -{ 8 { dup -28 bitshift //HexDigits exch 1 getinterval //=only exec 4 bitshift } repeat pop} bind def /PDFR_DEBUG DefaultSwitch/PDFR_DUMP DefaultSwitch/PDFR_STREAM DefaultSwitch/TTFDEBUG DefaultSwitch/RotatePages DefaultSwitch/FitPages DefaultSwitch/SetPageSize DefaultSwitch /error % mark <object> .... error -{ % A stub for a while. counttomark 1 sub -1 0 { index dup type /arraytype eq { == } { =only } ifelse } for () = cleartomark % Assuming ....Undefined is never defined. % Use it to emit an error. ....Undefined} bind def //SetPageSize { //RotatePages //FitPages or { mark (/RotatePages, /FitPages are not allowed with /SetPageSize) //error exec } if} if % ===================== Utilities ========================================= /knownget % <dict> <key> knownget <value> true % <dict> <key> knownget false{ 2 copy known { get true } { pop pop false } ifelse} bind def /IsUpper % <int> IsUpper <bool>{ dup (A) 0 get ge exch (Z) 0 get le and} bind def % ===================== Work Data ========================================= /BlockBuffer 65535 string def % Make it big to load entire TrueType font/PDFReader currentdict def/ObjectRegistry 50 array def % may grow later/CurrentObject null def/DoneDocumentStructure false def/GraphicState 20 dict begin /InitialTextMatrix matrix def /InitialMatrix matrix currentmatrix defcurrentdict end def/TempMatrix matrix def/GraphicStateStack 20 array def/GraphicStateStackPointer 0 def/PDFColorSpaces 50 dict def/InstalledFonts 50 dict def/MacRomanEncodingInverse null def % We need some structures in local VM, put then into the userdict :currentglobal false setglobaluserdict /PDFR_InitialGS gstate putuserdict /PDFR_Patterns 50 dict putuserdict /FuncDataReader 10 dict putsetglobal % ===================== Constants ========================================= /InitialExtGState 20 dict begin /BG2 currentblackgeneration def /UCR2 currentundercolorremoval def /TR2 [ currentcolortransfer ] def /HT currenthalftone defcurrentdict end readonly def /InitialGraphicState 20 dict begin /FontSize 0 def /CharacterSpacing 0 def /TextLeading 0 def /TextRenderingMode 0 def /WordSpacing 0 defcurrentdict end readonly def /SimpleColorSpaceNames 15 dict begin /DeviceGray true def /DeviceRGB true def /DeviceCMYK true def currentdict end readonly def /1_24_bitshift_1_sub 1 24 bitshift 1 sub def /ReadFontProcs 10 dict def % Will be filled below. % ===================== Reading PDF objects =============================== /Register % <DefaultDaemon> <id> <obj> Register -{ exch dup % d obj id id //PDFReader /ObjectRegistry get length ge { dup dup 2 idiv add array dup % d obj id [n] [n] //PDFReader /ObjectRegistry get dup length % d obj id [n] [n] [o] l 3 2 roll exch % d obj id [n] [o] [n] l 0 exch getinterval copy pop % d obj id [n] //PDFReader exch /ObjectRegistry exch put % d obj id } if exch //PDFReader /ObjectRegistry get % d id obj r 3 1 roll % d r id obj 3 copy pop get % d r id obj e dup xcheck { % d r id obj e 5 4 roll pop % r id obj e //PDFR_DEBUG { (Have a daemon for ) print 2 index = } if % We've got a definition daemon, execute it : exec } { % d r id obj e dup null ne { % d r id obj e mark (The object ) 4 index ( already defined : ) 4 index //error exec } { pop } ifelse 4 3 roll % r id obj d % Execute the default daemon : exec } ifelse % r id obj put %} bind def /IsRegistered % <id> GetRegistered <bool>{ //PDFReader /ObjectRegistry get % id r dup length % id r l 2 index le { % id r pop pop false } { exch get % id e null ne } ifelse} bind def /GetRegistered % <id> GetRegistered <obj>{ //PDFReader /ObjectRegistry get % id r dup length % id r l 2 index le { % id r exch mark exch (Object ) exch ( isn't defined before needed (1).) //error exec } if 1 index get % id e dup xcheck { exch mark exch (Object ) exch ( isn't defined before needed (2).) //error exec } { dup null eq { exch mark exch (Object ) exch ( isn't defined before needed (3).) //error exec } if exch pop % e } ifelse} bind def /StandardFontNames << /Times-Roman true /Helvetica true /Courier true /Symbol true /Times-Bold true /Helvetica-Bold true /Courier-Bold true /ZapfDingbats true /Times-Italic true /Helvetica-Oblique true /Courier-Oblique true /Times-BoldItalic true /Helvetica-BoldOblique true /Courier-BoldOblique true>> def /CleanAllResources % - CleanAllResources -{ //PDFR_DEBUG { (CleanAllResources beg) = } if //PDFReader /ObjectRegistry get dup length 0 exch 1 exch 1 sub { % R i 2 copy get dup xcheck { % Don't clean a daemon. pop pop } { dup null eq { pop pop } { dup type /dicttype eq { /.Global known } { pop false } ifelse { pop } { //PDFR_DEBUG { (Dropping ) print dup = } if 1 index exch /DroppedObject put } ifelse } ifelse } ifelse } for pop FontDirectory length dict begin FontDirectory { pop dup //StandardFontNames exch known not { dup null def } if pop } forall currentdict end { pop //PDFR_DEBUG { (Undefining font ) print dup = } if undefinefont } forall //PDFR_DEBUG { (CleanAllResources end) = } if} bind def /PrintReference % <array> PrintReference <array>{ //PDFR_DEBUG { ({ ) print dup { =only ( ) print } forall ( }) = } if} bind def /R % <id> <gen> R <daemon>{ % Make a reference daemon. 0 ne { exch mark exch (A referred object generation ) exch ( isn't 0.) //error exec } if % id [ % <id> proc <obj> exch //GetRegistered /exec load ] cvx //PrintReference exec} bind def /IsObjRef % <any> IsObjRef <bool>{ dup type /arraytype eq { dup length 3 eq { dup xcheck exch dup 0 get type /integertype eq 3 2 roll and exch dup 1 get //GetRegistered eq 3 2 roll and exch 2 get /exec load eq and } { pop false } ifelse } { pop false } ifelse} bind def /DoNothing {} def /RunTypeDaemon % <id> <obj> RunTypeDaemon <id> <obj>{ dup type /dicttype eq { dup /Type //knownget exec { //PDFReader /TypeDaemons get exch //knownget exec { exec } if } if } if} bind def /obj % <id> <generation> obj <id>{ //PDFR_DEBUG { (Defining ) print 1 index =only ( ) print dup =only ( obj) = } if 0 ne { exch mark exch (An object generation ) exch ( isn't 0.) //error exec } if} bind def /endobj % <id> <obj> endobj -{ //PDFR_DEBUG { (endobj ) = } if dup type /dicttype eq { dup /.endobj_daemon //knownget exec { //PDFR_DEBUG { (.endobj_daemon for ) print 2 index = } if exec } if } if dup type /dicttype eq { dup /ImmediateExec known } { false } ifelse { pop pop } { //PDFR_DEBUG { (Storing ) print 1 index = } if //RunTypeDaemon exec //DoNothing 3 1 roll //Register exec } ifelse} bind def /StoreBlock % <buf> StoreBlock -{ % Stores a (encoded) stream data block to the current object. //PDFR_DEBUG { (StoreBlock ) print //PDFReader /BlockCount get =only (, Length = ) print dup length = } if dup length string copy //PDFReader /BlockCount get exch % i s //PDFReader /CurrentObject get 3 1 roll % o i s put % //PDFReader /BlockCount get 1 add //PDFReader exch /BlockCount exch put} bind def /CheckLength % <val> CheckNumber <val>{ dup type /integertype ne { mark (Object length isn't an integer.) //error exec } if} bind def /ResolveD % <dict> <key> <check> ResolveD <value>{ 3 copy pop get % <> key {} e dup //IsObjRef exec { % We've got a reference daemon, execute it : //PDFR_DEBUG { (Resolving ) print //PrintReference exec } if exec % <> key {} val exch exec % <> key val } { exch pop } ifelse dup 4 1 roll % val <> key val put % val} bind def /ResolveA % <array> <index> <check> ResolveA <value>{ 2 index 2 index get dup //IsObjRef exec { exec exch execLines 1–500 of 3621. Load more
%!PS-Adobe-2.0 % % Copyright (C) 2002 artofcode LLC. All rights reserved. % % This software is provided AS-IS with no warranty, either express or % implied. % % This software is distributed under license and may not be copied, % modified or distributed except as expressly authorized under the terms % of the license contained in the file LICENSE in this distribution. % % For more information about licensing, please refer to % http://www.ghostscript.com/licensing/. For information on % commercial licensing, go to http://www.artifex.com/licensing/ or % contact Artifex Software, Inc., 101 Lucas Valley Road #110, % San Rafael, CA 94903, U.S.A., +1(415)492-9861. % $Id: opdfread.ps,v 1.84 2005/09/07 20:43:36 leonardo Exp $ % pdfread.ps - A procset for interpreting an ordered PDF 1.3 file. % This module defines routines for interpreting a PDF file with % a Postscript interpreter. To convert a PDF file into Postscript % just pre-contcatenate this file. The PDF file must satisfy % few constraints : % % 1. It must contain only Postscript level 2 objects encoded with % the PDF 1.3 language. Higher PDF levels must be re-distilled % with CompatibilityLevel=1.3 . % % 2. Objects must be ordered so that any resource be defined before % its usage. % % 3. The PDF file must not include other PDF files. % Consequently we have a single instance of the PDF reader. % We use this fact to simplify binding of the routines. % % 4. The PDF root object must always have the object id 1. % % 5. Generations besides 0 are not allowed. % % 6. xref must appear after all objects. % % Assuming the currentfile isn't positionable. % As a consequence, the reader fully ignores xref. true setglobal % ====================== Error handler ======================= % A general error handler prints an error to page. 10 dict begin % A dictionary for local binding /this currentdict def /y 720 def /ebuf 200 string def /prnt { 36 //this /y get moveto //ebuf cvs show //this /y 2 copy get 12 sub put } bind def /newline { 36 //this /y get moveto //this /y 2 copy get 12 sub put } bind def errordict /handleerror { systemdict begin $error begin newerror { (%%[ Error handled by opdfread.ps : ) print errorname //ebuf cvs print (; OffendingCommand: ) print /command load //ebuf cvs print ( ]%%) = flush /newerror false store vmstatus pop pop 0 ne { grestoreall } if errorname (VMerror) ne { showpage } if initgraphics 0 720 moveto errorname (VMerror) eq { //this /ehsave known { clear //this /ehsave get restore 2 vmreclaim } if vmstatus exch pop exch pop } /Courier 12 selectfont { (ERROR: ) //prnt exec errorname //prnt exec (OFFENDING COMMAND: ) //prnt exec /command load //prnt exec $error /ostack known { (%%[STACK:) = (STACK:) //prnt exec $error /ostack get aload length { //newline exec dup mark eq { (-mark-) dup = show } { dup type /nametype eq { dup xcheck not { (/) show (/) print } if } if dup = //ebuf cvs show } ifelse } repeat } if } ifelse (%%]%) = //systemdict /showpage get exec quit } if end end } bind readonly put end % A dictionary for local binding 50 dict begin % ===================== Debugging ========================================= /DefaultSwitch % <name> DefaultSwitch - { dup where { pop pop } { false def } ifelse } bind def /=string 256 string def /=only { //=string cvs print } bind def /HexDigits (0123456789ABCDEF) readonly def /PrintHex % <int> PrintHex - { 8 { dup -28 bitshift //HexDigits exch 1 getinterval //=only exec 4 bitshift } repeat pop } bind def /PDFR_DEBUG DefaultSwitch /PDFR_DUMP DefaultSwitch /PDFR_STREAM DefaultSwitch /TTFDEBUG DefaultSwitch /RotatePages DefaultSwitch /FitPages DefaultSwitch /SetPageSize DefaultSwitch /error % mark <object> .... error - { % A stub for a while. counttomark 1 sub -1 0 { index dup type /arraytype eq { == } { =only } ifelse } for () = cleartomark % Assuming ....Undefined is never defined. % Use it to emit an error. ....Undefined } bind def //SetPageSize { //RotatePages //FitPages or { mark (/RotatePages, /FitPages are not allowed with /SetPageSize) //error exec } if } if % ===================== Utilities ========================================= /knownget % <dict> <key> knownget <value> true % <dict> <key> knownget false { 2 copy known { get true } { pop pop false } ifelse } bind def /IsUpper % <int> IsUpper <bool> { dup (A) 0 get ge exch (Z) 0 get le and } bind def % ===================== Work Data ========================================= /BlockBuffer 65535 string def % Make it big to load entire TrueType font /PDFReader currentdict def /ObjectRegistry 50 array def % may grow later /CurrentObject null def /DoneDocumentStructure false def /GraphicState 20 dict begin /InitialTextMatrix matrix def /InitialMatrix matrix currentmatrix def currentdict end def /TempMatrix matrix def /GraphicStateStack 20 array def /GraphicStateStackPointer 0 def /PDFColorSpaces 50 dict def /InstalledFonts 50 dict def /MacRomanEncodingInverse null def % We need some structures in local VM, put then into the userdict : currentglobal false setglobal userdict /PDFR_InitialGS gstate put userdict /PDFR_Patterns 50 dict put userdict /FuncDataReader 10 dict put setglobal % ===================== Constants ========================================= /InitialExtGState 20 dict begin /BG2 currentblackgeneration def /UCR2 currentundercolorremoval def /TR2 [ currentcolortransfer ] def /HT currenthalftone def currentdict end readonly def /InitialGraphicState 20 dict begin /FontSize 0 def /CharacterSpacing 0 def /TextLeading 0 def /TextRenderingMode 0 def /WordSpacing 0 def currentdict end readonly def /SimpleColorSpaceNames 15 dict begin /DeviceGray true def /DeviceRGB true def /DeviceCMYK true def currentdict end readonly def /1_24_bitshift_1_sub 1 24 bitshift 1 sub def /ReadFontProcs 10 dict def % Will be filled below. % ===================== Reading PDF objects =============================== /Register % <DefaultDaemon> <id> <obj> Register - { exch dup % d obj id id //PDFReader /ObjectRegistry get length ge { dup dup 2 idiv add array dup % d obj id [n] [n] //PDFReader /ObjectRegistry get dup length % d obj id [n] [n] [o] l 3 2 roll exch % d obj id [n] [o] [n] l 0 exch getinterval copy pop % d obj id [n] //PDFReader exch /ObjectRegistry exch put % d obj id } if exch //PDFReader /ObjectRegistry get % d id obj r 3 1 roll % d r id obj 3 copy pop get % d r id obj e dup xcheck { % d r id obj e 5 4 roll pop % r id obj e //PDFR_DEBUG { (Have a daemon for ) print 2 index = } if % We've got a definition daemon, execute it : exec } { % d r id obj e dup null ne { % d r id obj e mark (The object ) 4 index ( already defined : ) 4 index //error exec } { pop } ifelse 4 3 roll % r id obj d % Execute the default daemon : exec } ifelse % r id obj put % } bind def /IsRegistered % <id> GetRegistered <bool> { //PDFReader /ObjectRegistry get % id r dup length % id r l 2 index le { % id r pop pop false } { exch get % id e null ne } ifelse } bind def /GetRegistered % <id> GetRegistered <obj> { //PDFReader /ObjectRegistry get % id r dup length % id r l 2 index le { % id r exch mark exch (Object ) exch ( isn't defined before needed (1).) //error exec } if 1 index get % id e dup xcheck { exch mark exch (Object ) exch ( isn't defined before needed (2).) //error exec } { dup null eq { exch mark exch (Object ) exch ( isn't defined before needed (3).) //error exec } if exch pop % e } ifelse } bind def /StandardFontNames << /Times-Roman true /Helvetica true /Courier true /Symbol true /Times-Bold true /Helvetica-Bold true /Courier-Bold true /ZapfDingbats true /Times-Italic true /Helvetica-Oblique true /Courier-Oblique true /Times-BoldItalic true /Helvetica-BoldOblique true /Courier-BoldOblique true >> def /CleanAllResources % - CleanAllResources - { //PDFR_DEBUG { (CleanAllResources beg) = } if //PDFReader /ObjectRegistry get dup length 0 exch 1 exch 1 sub { % R i 2 copy get dup xcheck { % Don't clean a daemon. pop pop } { dup null eq { pop pop } { dup type /dicttype eq { /.Global known } { pop false } ifelse { pop } { //PDFR_DEBUG { (Dropping ) print dup = } if 1 index exch /DroppedObject put } ifelse } ifelse } ifelse } for pop FontDirectory length dict begin FontDirectory { pop dup //StandardFontNames exch known not { dup null def } if pop } forall currentdict end { pop //PDFR_DEBUG { (Undefining font ) print dup = } if undefinefont } forall //PDFR_DEBUG { (CleanAllResources end) = } if } bind def /PrintReference % <array> PrintReference <array> { //PDFR_DEBUG { ({ ) print dup { =only ( ) print } forall ( }) = } if } bind def /R % <id> <gen> R <daemon> { % Make a reference daemon. 0 ne { exch mark exch (A referred object generation ) exch ( isn't 0.) //error exec } if % id [ % <id> proc <obj> exch //GetRegistered /exec load ] cvx //PrintReference exec } bind def /IsObjRef % <any> IsObjRef <bool> { dup type /arraytype eq { dup length 3 eq { dup xcheck exch dup 0 get type /integertype eq 3 2 roll and exch dup 1 get //GetRegistered eq 3 2 roll and exch 2 get /exec load eq and } { pop false } ifelse } { pop false } ifelse } bind def /DoNothing { } def /RunTypeDaemon % <id> <obj> RunTypeDaemon <id> <obj> { dup type /dicttype eq { dup /Type //knownget exec { //PDFReader /TypeDaemons get exch //knownget exec { exec } if } if } if } bind def /obj % <id> <generation> obj <id> { //PDFR_DEBUG { (Defining ) print 1 index =only ( ) print dup =only ( obj) = } if 0 ne { exch mark exch (An object generation ) exch ( isn't 0.) //error exec } if } bind def /endobj % <id> <obj> endobj - { //PDFR_DEBUG { (endobj ) = } if dup type /dicttype eq { dup /.endobj_daemon //knownget exec { //PDFR_DEBUG { (.endobj_daemon for ) print 2 index = } if exec } if } if dup type /dicttype eq { dup /ImmediateExec known } { false } ifelse { pop pop } { //PDFR_DEBUG { (Storing ) print 1 index = } if //RunTypeDaemon exec //DoNothing 3 1 roll //Register exec } ifelse } bind def /StoreBlock % <buf> StoreBlock - { % Stores a (encoded) stream data block to the current object. //PDFR_DEBUG { (StoreBlock ) print //PDFReader /BlockCount get =only (, Length = ) print dup length = } if dup length string copy //PDFReader /BlockCount get exch % i s //PDFReader /CurrentObject get 3 1 roll % o i s put % //PDFReader /BlockCount get 1 add //PDFReader exch /BlockCount exch put } bind def /CheckLength % <val> CheckNumber <val> { dup type /integertype ne { mark (Object length isn't an integer.) //error exec } if } bind def /ResolveD % <dict> <key> <check> ResolveD <value> { 3 copy pop get % <> key {} e dup //IsObjRef exec { % We've got a reference daemon, execute it : //PDFR_DEBUG { (Resolving ) print //PrintReference exec } if exec % <> key {} val exch exec % <> key val } { exch pop } ifelse dup 4 1 roll % val <> key val put % val } bind def /ResolveA % <array> <index> <check> ResolveA <value> { 2 index 2 index get dup //IsObjRef exec { exec exch exec