%!PS % PostScript's Internaldict, Superexec & the PDF Mark Instruction Set GuruGram #10 % ====================================================== % by Don Lancaster % Copyright c 2002 by Don Lancaster & Synergetics, Box 809, Thatcher, AZ, 85552 % (928) 428-4073 Email: don@tinaja.com Website: http://www.tinaja.com % Consulting services available http://www.tinaja.com/info01.html % Linking welcome. Reposting expressly forbidden. % All commercial rights and all electronic media rights ~fully~ reserved. % Linking usually welcome. Reposting expressly forbidden. Version 1.5 % A tutorial review of PostScript's internaldict access with a check of the % pdfmark instructin set. % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is required for this program. % After obvious location mods, uncomment ONE of the following two lines: (C:\\windows\\desktop\\gonzo\\gonzo.ps) run % use internal gonzo % (A:\\gonzo.ps) run % use external gonzo % NOTE THAT ALL PS FILENAME STRINGS !!!DEMAND!!! DOUBLE REVERSE SLASHES. % GONZO20A Guru Gonzo PostScript power tools (Interim release) % Includes gonzo justification and layout utilities. % Copyright c 1990, 1996, 2001 by Don Lancaster and Synergetics, Box 809, % Thatcher Arizona, 5552 (928) 428-4073 don@tinaja.com support % via http://www.tinaja.com All commercial rights and all electronic % media rights **FULLY** reserved. Reposting is expressly forbidden. %%%%%%%%%%% links menu directory %%%%%%%%%%%% % This code locks pdfmark commands out of a PostScript printer. /pdfmark where {pop}{userdict /pdfmark /cleartomark load put} ifelse % /surl "start url" marks the beginning of a text sequence to be urled. % It also paints the text blue... /surl {mark /blue cvx 0.33 /setgray cvx % change text to blue /currentpoint cvx % remember box start /urly /exch cvx /store cvx /urlx /exch cvx /store cvx ] cvx % complete deferred command printlist exch 3 index exch put % stuff into gonzo printlist exch 1 add exch % increment gonzo list count } def % /eurl "end url" unmarks the end of a text sequence and sets up % the pdfmark needed to define the Acrobat web link. /eurl {mark % start deferred proc exch % position url string % /black cvx 0 /setgray cvx % turn blue marker off % maintextcolor /setrgbcolor cvx % reset to main text color??? /aqua cvx /black cvx /makeurl cvx % defer call of url builder ] cvx % complete deferred proc printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch % increment gonzo list count } def % /makeurl generates the pdfmark, receiving a {(urlstring) makeurl}. % Note that it is not called until formatted printlist time... /urlover 0.2 def % fraction of hot area over bounds /makeurl { /cururlname exch store % save the url string mark % start pdfmark currentfont /ScaleMatrix get 3 get /fsize exch store % guess height /Rect [ urlx fsize urlover mul sub % set box left x urly fsize urlover mul sub % set box left y currentpoint exch fsize urlover mul add exch fsize add ] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def % /makeurlx generates the box specific pdfmark, receiving % a {(urlstring) makeurl}. % Note that it is not called until formatted printlist time... /makeurlx { /cururlnamex exch store % save the url string mark % start pdfmark /Rect [ xpos % set box left x ypos 0.9 sub % set box left y xpos 2.8 add % box right x ypos 0.9 sub 2.8 add % box right y ] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def /maintextcolor {0 0 0 } def % text link specific data -- use dictionary instead below { /cubic01 {(http://www.tinaja.com/cubic01.asp) eurl} def /hack62 {(http://www.tinaja.com/glib/hack62.pdf) eurl} def /increment {(http://www.tinaja.com/text/bezgen3.html) eurl} def /interpolate {(http://members.bellatlantic.net/~vze2vrva/design.html) eurl } def /bezmath {(http://www.tinaja.com/text/bezmath.html) eurl } def /table {(http://www.tinaja.com/psutils/imtable.psl) eurl } def } pop % dictionary method << %zzzzz %%%% unused links have been commented for gg9a simplicity /maildon (mailto:don@tinaja.com) /tinaja (http://www.tinaja.com) /adobe (http://www.adobe.com) /degub (http://www.tinaja.com/glib/degub.pdf) /ghostscript (http://www.artifex.com/pressreleases/GS70.htm) /demox.psl (http://www.tinaja.com/glib/g9demox.psl) /demox.pdf (http://www.tinaja.com/glib/g9demox.pdf) /demo.pdf (http://www.tinaja.com/glib/g9demo.pdf) /flatvue (http://www.tinaja.com/glib/flatvue.psl) /pdfrefman (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /psrefman (http://partners.adobe.com/asn/developer/technotes/postscript.html) /pdfmrm (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /tipdf (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /asdk (http://partners.adobe.com/asn/developer/acrosdk) /mtcr (http://support.adobe.com/devsup/devsup.nsf/docs/51864.htm) /flatvue1 (http://www.tinaja.com/psutils/flatvue1.psl) /acrob01 (http://www.tinaja.com/acrob01.asp) /post01 (http://www.tinaja.com/post01.asp) /info01 (http://www.tinaja.com/info01.asp) /gurgrm01 (http://www.tinaja.com/gurgrm01.asp) { /tilley (http://www.tilleyfoundation.com) /mnglobal (http://www.mnglobal.com/energy/pg2.htm) /keely (http://www.keelynet.com) /evolve (http://www.evolvedtechnology.com) /hack64 (http://www.tinaja.com/glib/hack64.pdf) /hackar3 (http://www.tinaja.com/glib/hackar3.pdf) /resbn58 (http://www.tinaja.com/glib/resbn58.pdf) /bppt (http://www.batterypoweronline.com) /muse112 (http://www.tinaja.com/glib/muse112.pdf) /muse113 (http://www.tinaja.com/glib/muse113.pdf) /energfun (http://www.tinaja.com/glib/energfun.pdf) /bashpseu (http://www.tinaja.com/glib/bashpseu.pdf) /adobe (http://www.adobe.com) /netscape (http://www.netscape.com) /gallypsl (http://www.tinaja.com/galley1.psl) /gallypdf (http://www.tinaja.com/galley1.pdf) /atn5150 (http://partners.adobe.com/asn/developer/acrosdk/docs/createpdfapi/pdfmarkReference.pdf) /nutour (http://www.tinaja.com/bargains/nutour02.pdf) /nutoursource (http://www.tinaja.com/bargains/nutour02.psl) /bwhistle (http://www.tinaja.com/glib/bwhistle.pdf) /gonzo1 (http://www.tinaja.com/post01.asp#gonzo) /barg01 (http://www.tinaja.com/barg01.asp) /weblib01 (http://www.tinaja.com/weblib01.asp) /gurgrm01 (http://www.tinaja.com/gurgrm01.asp) /z1 (http://www.tinaja.com/bargains/thumb/albradz2.jpg) /z2 (http://www.tinaja.com/bargains/sbtesteq.asp) /z3 (http://www.tinaja.com/images/bargs/albrad02.jpg) /z4 (http://www.tinaja.com/bargains/thumb/tutenaz2.jpg) /z5 (http://www.tinaja.com/bargains/sbphone.asp) /z6 (http://www.tinaja.com/images/bargs/tutena02.jpg) /sourceme (http://www.tinaja.com/glib/gallery.psl) /sourceme2 (http://www.tinaja.com/glib/autourl.psl) } pop >> {mark exch /eurl cvx ] cvx def} forall %%%%%%%%%%%%%%%% New colorizer patches %%%%%%%%%%%%%%%%%% /boxgrays 0.899 def /grayshade boxgrays def /mastergray boxgrays def /staytint {0.33 setgray} def /staytint1 {0.25 setgray} def /showadgrays true def /red {0 settint} def /Zmacro {staytint /ypos ypos 2 add def 72 300 div setlinewidth xpos ypos moveto txtwide 0 rlineto stroke /ypos ypos -2 add def tintoff} def % hair rule /amacro {(zy0) stringmacro /ypos ypos ypara add def 0.33 setgray } def % start drop cap /bmacro {(iFy1) stringmacro /ypos ypos ypara add def black} def % finish drop cap % Gonzo character colorizer /blueon {mark /blue cvx 0.33 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /blueoff {mark /beige cvx 0 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton {mark 0.33 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1 {mark 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1b {mark beige cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1a {mark /aqua cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1p {mark /burple cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1r {mark /red cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1b {mark /beige cvx % try for beige after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tintoff {mark 0 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def %%%%%%%%%%%%%% COMPACT VERSION OF COLORIZER II %%%%%%%%%%%%%%%%%%%%%% /settint {dup /currenttint exch store 5.999 mul dup floor cvi /&cbar exch store dup floor sub /&cwt exch store [ {/setgray [ /dup cvx 0.3 &cwt 0.59 mul add /ge cvx [1 /exch cvx &cwt 0.59 mul 0.30 add /sub cvx 1 &cwt sub 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx /exch cvx ] cvx [ &cwt 0.59 mul 0.3 add /div cvx /dup cvx &cwt /mul cvx 0] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 1 &cwt sub 0.3 mul add /ge cvx [1 &cwt sub 0.3 mul 0.59 add /sub cvx &cwt 0.3 mul 0.11 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx /exch cvx 1 /exch cvx] cvx [1 &cwt sub 0.3 mul 0.59 add /div cvx /dup cvx 1 &cwt sub /mul cvx /exch cvx 0] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 &cwt 0.11 mul add /ge cvx [&cwt 0.11 mul 0.59 add /sub cvx 1 &cwt sub 0.11 mul 0.30 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx 1 /exch cvx] cvx [0 /exch cvx &cwt 0.11 mul 0.59 add /div cvx /dup cvx &cwt /mul cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 1 &cwt sub mul 0.11 add /ge cvx [1 &cwt sub 0.59 mul 0.11 add /sub cvx &cwt 0.59 mul 0.30 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx 1] cvx [0 /exch cvx 1 &cwt sub 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul cvx /exch cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.11 &cwt 0.30 mul add /ge cvx[&cwt 0.30 mul 0.11 add /sub cvx 1 &cwt sub 0.30 mul 0.59 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx /exch cvx 1] cvx [ &cwt 0.30 mul 0.11 add /div cvx /dup cvx &cwt /mul cvx /exch cvx 0 /exch cvx ] cvx /ifelse cvx /setrgbcolor cvx ] cvx /def cvx} {/setgray [ /dup cvx 0.30 1 &cwt sub 0.11 mul add /ge cvx[ 1 /exch cvx 1 &cwt sub 0.11 mul 0.30 add /sub cvx &cwt 0.11 mul 0.59 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx ] cvx [ 1 &cwt sub 0.11 mul 0.30 add /div cvx /dup cvx 1 &cwt sub /mul cvx 0 /exch cvx] cvx /ifelse cvx /setrgbcolor cvx ] cvx /def cvx} ] &cbar get exec exec} bind def /beige {0.10 settint} def % examples of convenience operators /aqua {0.52 settint} def /blue {0.67 settint} def /lime {0.44 settint} def /burple {0.75 settint} def %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /guru { gonzo begin ps.util.1 begin printerror nuisance begin} def % guru % activate gonzo utilities 50 50 10 setgrid % create grid % 56 61 showgrid /setpagefonts { /cstretch 0.015 def /sstretch 0.015 def /font0 /StoneSans-Bold 1.6 gonzofont /font1 /StoneSans 0.95 gonzofont /font4 /StoneSans 0.85 gonzofont /font3 /StoneSans-Bold 0.85 gonzofont /font6 /StoneSans-Bold 0.85 gonzofont /font7 /StoneSans-Bold 1.05 gonzofont % subheaders /font8 /StoneSans-Bold [0.65 0 0 0.65 0 0.4] gonzofont /txtwide 36 store /yinc 1.2 store /kern 0.1 store /pm 1.5 store /tabs [7 -2] store aqua 0.33 setgray font1 black font2 /amacro { mark /aqua cvx 0.33 /setgray cvx ] cvx printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch } def /bmacro { mark /black cvx ] cvx printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch } def /shiftin {xpos /xposhold exch store /xpos xpos 3 add store} def /shiftout {/xpos xposhold store} def /texttop 51 store /textleft 3 store /cmacro {aqua 0.25 setgray (znhL7) stringmacro /xpos xpos 1.7 sub store /ypos ypos .1 sub def } def % left title /dmacro {black (pL1hz) stringmacro /xpos xpos 1.7 add store /ypos ypos .1 add def} def % normal text after centered title /fmacro % try and fake | {mark /gsave cvx /currentpoint cvx /moveto cvx 0.1 /setlinewidth cvx 0 0.65 /rlineto cvx /stroke cvx /grestore cvx ] cvx printlist exch 3 index exch put % stuff into gonzo printlist exch 1 add exch % increment gonzo list count } def } def setpagefonts % -2 50.5 (optional header here \274) cl %% Set document opening conventions. Note DOCVIEW limited. [/CropBox [0 0 520 620] % set the wierd size /PAGES pdfmark [ {Catalog} << /ViewerPreferences << /FitWindow true /CenterWindow true >> /PageLayout /OneColumn % continous /Pagemode /UseNone % no thumbs /View [/XYZ null null 1 ] % force 100% >> /PUT pdfmark %%%%%%%%%%%%%%%%% START DEMO ART (not in use) %%%%%%%%%%%%%%%% %%% Hand patching Info: % next available variable is /GS3 % transparency gstate is object 2 % contents stream is object 18 gets q /GS3 gs (xstuff) Q % be sure to q Q bracket to localize % resources stream is object 19 gets /GS3 2 0 R /transoverlay { % make a new graphics state [ /_objdef {newgsstate} /type /dict /OBJ pdfmark % fill the new overlay graphics state - See PDF manual for details [ {newgsstate} << /Type /ExtGState /ca 0.5 % fill transparency is 0.5 /CA 0.5 % stroke transparency is 0.5 /BM /Normal /AIS false /OP false /OPM 1 /op true >> /PUT pdfmark % start a Begin Picture graphics overlay subroutine... [ /BBox [0 0 1000 1000 ] /_objdef {overlaypix} /BP pdfmark % fill the Begin Picture graphics overlay Xobject subroutine... 0 0.5 1 setrgbcolor % on the aqua side of blue 4 4 6 6 rectfill % complete the Begin Picture graphics overlay Xobject... [ /EP pdfmark } def % Write a two squares program... /twosquares { gsave translate 1 0.5 0 setrgbcolor % red side of orange 2 2 6 6 rectfill % do background opaque box [ {overlaypix} /SP pdfmark % show foreground transparent box grestore} def % Distill the two squares program. Initially use a BARE Distiller Job % Options that has no compression, no embedded fonts, and little else save /snap1 exch store %%% transoverlay % create new objects %%% 14 17.5 twosquares snap1 restore %%%%%%%%%%%% END DEMO %%%%%%% /tabs [8 16.5] def aqua 0.33 setgray font0 20 47.3 0.7 add (PostScript's Internaldict, Superexec,) cc 20 45.3 0.7 add (& the pdfmark Instruction Set) cc black font2 textleft 43 (|3Don Lancaster Synergetics, Box 809, Thatcher, AZ 85552 copyright c2002 as |/surl |6GuruGram|1|/gurgrm01 |6#10 |/surl http://www.tinaja.com|/tinaja |/surl don@tinaja.com|/maildon (928) 428-4073 |h |a|0A|b|1 brief note here on some of the lesser known |/surl |6PostScript|1|/post01 and |/surl |6Acrobat Distiller|1|/acrob01 techniques and procedures. |/surl |6Adobe|1|/adobe has an internal dictionary in PostScript called, of all things, |/tinton1 |6internaldict|1|/tintoff . |h Originally, this dictionary was "protected" to prevent snooping into font formats or the lame |/tinton1 |6eexec|1|/tintoff encryption that any patient seventh grader could |/surl |6easily crack|1|/degub . These days, internaldict is more or less accessible, but Adobe still does not care for you messing around with the fundamental PostScript smoke and mirrors. |h The magic password is easily found, and internaldict can be opened by\274 |3|/shiftin |h|/burple |/staytint1 1183615869 internaldict begin |h|1|/shiftout |/aqua |/black Besides general snooping around, there's a most useful |/tinton1 |6superexec|1|/tintoff operator in internaldict. Superexec can sometimes override some system access restrictions and lockouts. The usual route is\274 |3|/shiftin |h|/burple |/staytint1 something_hidden {|ja_blocked_access_route|j} superexec |h|1|/shiftout |/aqua |/black Let's look at a specific and useful example. In |/surl |6GuruGram #9|1|/gurgrm01 we were (and still are) seeking a way for PostScript to have Distiller directly activate PDF graphic states. Especially those involving transparency. |h PostScript normally accesses Distiller |/tinton1 |6COS Object|1|/tintoff internals by way of the |/surl |6pdfmark|1|/pdfmrm operators. A reasonable question to ask is "How many actual pdfmark operators are there and how complete is their |/surl |6documentation|1|/pdfmrm ? |h Distiller has a hidden and blocked |/tinton1 |6pdfmarkInternalDict|1|/tintoff inside its internaldict dictionary. We can first use\274 |3|/shiftin |h|/burple |/staytint1 1183615869 internaldict begin pdfmarkInternalDict { length == } superexec |h|1|/shiftout |/aqua |/black \274 to find there are 46 entries in this dictionary. We can also surmise there are thus 46 pdfmark operators. ) cl black beige 0.35 setgray 21 -2.5 (|3\320|j1|j\320) cc aqua showpage %%%%%%%%% 222222222 %% start page two 50 50 10 setgrid % create grid setpagefonts /tabs [11.5] def textleft texttop (|1 To find out for sure, we can do a\274 |3|/shiftin |h|/burple |/staytint1 1183615869 internaldict begin pdfmarkInternalDict { {== ==} forall } superexec |h|1|/shiftout |/aqua |/black \274 to actually list all the operators. We see that each operator links a number 0-45 in an array and is thus a simple name to proc converter. |h The pdfmark names in alphabetical order are\274 |3|/shiftin |h|/burple |/staytint1 /ANN |t/PAGES /APPEND |t/__pdfmarkInternal_Max /ARTICLE |t/__pdfmarkInternal_Max_ArrayType /BDC |t/__pdfmarkInternal_Max_DictType /BMC |t/__pdfmarkInternal_Min /BP |t/PS /CLOSE |t/PUT /DEBUG |t/PUTINTERVAL /DEST |t/SP /DOCINFO |t/StAttr /DOCVIEW |t/StBDC /DP |t/StBMC /EMC |t/StBookmarkRoot /EP |t/StClassMap /LNK |t/StPNE /MP |t/StPop /NamespacePop |t/StOBJ /NamespacePush |t/StPopAll /NI |t/StPush /OBJ |t/StRetrieve /OUT |t/StRoleMap /PAGE |t/StStore /PAGELABEL |t/StUpdate |h|1|/shiftout |/aqua |/black The overwhelming majority of these appear to be |/surl |6fully documented|1|/pdfmrm . The |/tinton1 |6/GS|1|/tintoff set-to-the-named-graphics-state I was desperately hoping for does not yet seem available. Wonder what |/tinton1 |6/DEBUG|1|/tintoff does? |h Consulting services available per |/surl |6http://www.tinaja.com/info01.asp|1|/info01 . ) cl black beige 0.35 setgray 21 -2.5 (|3-|j2|j-) cc aqua showpage %%%%%%%%%%%%%%%%%%%% % EOF