You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

550 lines
22 KiB

1 month ago
  1. %!
  2. % Copyright (C) 2001-2023 Artifex Software, Inc.
  3. % All Rights Reserved.
  4. %
  5. % This software is provided AS-IS with no warranty, either express or
  6. % implied.
  7. %
  8. % This software is distributed under license and may not be copied,
  9. % modified or distributed except as expressly authorized under the terms
  10. % of the license contained in the file LICENSE in this distribution.
  11. %
  12. % Refer to licensing information at http://www.artifex.com or contact
  13. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  14. % CA 94129, USA, for further information.
  15. %
  16. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  17. %
  18. % ps2ai.ps - a postscript to editable adobe illustrator file filter
  19. %
  20. /vers {2.14} def % January 31, 1999
  21. % conditional def ( if the key is already defined before, don't
  22. % redefine it. This can be used by other programs to overwrite
  23. % some settings from externally
  24. %
  25. /cdef { 1 index where { pop pop pop } { def } ifelse } bind def
  26. %
  27. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  28. %
  29. % needs a postscript level 2 interpreter, like gnu ghostscript, to work
  30. %
  31. % Usage: gs -q -dNODISPLAY ps2ai.ps file.ps > file.aips
  32. % or (see below)
  33. % gs -q -dNODISPLAY ps2ai.ps file.ps
  34. % or
  35. % cat ps2ai.ps file.ps | lpr (then look in log file)
  36. %
  37. % or from within gsview via:
  38. % Edit->Convert to vector format
  39. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  40. % Options
  41. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  42. % Output Options: directly to a file or standard out
  43. %
  44. /jout false cdef % true=file false=stdout (default=false)
  45. /joutput (ps2ai.out.aips) cdef % Name of Output file
  46. %
  47. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  48. %
  49. % Other Options
  50. %
  51. /jtxt3 true cdef % output text in AI3 form (false=ai88)
  52. % for coreldraw/photoshop readable output
  53. /joutln false cdef % use font outline instead of font
  54. /jerr false def % use error handling (ie die gracefully)
  55. /jbiterr false def % attempt to handle bitmap fonts (kludge)
  56. /jMacGS false def % true if using MacGS (not fully implemented yet)
  57. /jMacfix true def % convert filled boxes to lines (only usefull with
  58. % laserwriter 8 postscript input)
  59. %
  60. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  61. % No options below here
  62. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  63. %
  64. % - Notes -
  65. % ai uses cmykcolor, so level 1 interpreters don't work
  66. % ai doesn't use image/imagemask - so bitmaps don't work correctly
  67. % the output file has a header so it is viewable/printable/reconvertable
  68. %
  69. % Comments, suggestions, bug-fixes, etc send to:
  70. %
  71. % Jason Olszewski (olszewsk@splash.princeton.edu)
  72. %
  73. % anonymous ftp: toby.princeton.edu /pub/olszewsk/ps2ai.ps
  74. % URL ftp://toby.princeton.edu/pub/olszewsk
  75. %
  76. % - Fix History -
  77. % 2.14 added cdef to allow overwriting of certain values from externally
  78. % 2.13 check for bitmap fonts, work better with TeX,WinPS,etc
  79. % 2.12 fixed initclip to US letter size page
  80. % 2.11 added header support for *u/*U compound paths
  81. % 2.1 option of font outline instead of text(gwhite@trevnx.bio.dfo.ca)
  82. % 2.0 major change to complex path handling
  83. % 1.9 fixed text leaking ascii (,),\
  84. % 1.85 added default font to handle no setfont (Courier)
  85. % 1.84 added even-odd fill/clip (D)
  86. % 1.83 undefined PPD PageSize printer specific info
  87. % 1.82 added kludge to save clipping status through a restore
  88. % 1.81 added custom color/gray support to header (x/X, g/G)
  89. % 1.8 added newpath if clippath is not consumed correctly(amiga)
  90. % 1.79 eliminated scientific notation of numbers less than 0.0001
  91. % 1.78 fixed transposed h & H
  92. % 1.77 made laserwriter 8 fixes optional
  93. % 1.76 added margin fix for unix AI (brown@wi.extrel.com)
  94. % 1.75 added kludge to handle bitmap font errors (TeX, Windows.ps)
  95. % 1.74 made grestore a little smarter
  96. % 1.73 included header handle encoded fontname (/_fontname)
  97. % 1.72 fixed problem with restore/clip info - (not enough Qs problem)
  98. % 1.71 filter font names to remove previous encoding (|,_,etc)
  99. % 1.7 change text format to AI3, works better with PS & CD
  100. % 1.67 deal with weird makefonts
  101. % 1.66 handle to many bad stroke/fills (s s s w/o paths)
  102. % 1.65 more useable with non-gs interpreters (defaultmatrix fix)
  103. % 1.64 fixed "smart grestore" repeat bug
  104. % 1.63 fixed ashow/awidthshow bug
  105. % 1.62 check if cmykcolor is understood otherwise rgb
  106. % 1.61 made grestore smarter (only print if different)
  107. % 1.6 add better compatibility to CorelDraw and PhotoShop
  108. % 1.53 make it more gs-backward compatible (clarke@lsl.co.uk)
  109. % 1.52 handle clipping paths a little better (Posted)
  110. % 1.51 improve mac lw8 output (lines instead of filled boxes)
  111. % 1.5 handle some level 2 stuff (mac lw8)
  112. % 1.4 fixed scaling of linewidth and dash
  113. % 1.31 made trailer more AI88 friendly
  114. % 1.3 add ablity to output to file directly
  115. % 1.21 print matrix cleaner
  116. % 1.2 fix rotated fonts, thanks to G.Cameron (g.cameron@biomed.abdn.ac.uk)
  117. % 1.1 fix stroke/fill color difference (k vs K)
  118. % 1.0 posted to comp.lang.postscript
  119. %
  120. % - To Do List -
  121. % find real %%BoundingBox: llx lly urx ury
  122. % make MacGS friendly (line-endings)
  123. % handle eps w/o showpage:(append to end)
  124. % write out image data to external file
  125. %
  126. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  127. % Nothing of Interest below here
  128. %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  129. matrix identmatrix setmatrix % make ctm [1 0 0 1 0 0]
  130. /bdef {bind def} bind def
  131. /oldgsave {} def /oldgrestore {} def
  132. /initgraphics {} def /initmatrix {} def
  133. % undefine PPD PageSizes to be more printer independant
  134. /letter {} def /legal {} def /a4 {} def /b5 {} def /lettersmall {} def
  135. /setpagedevice { pop } bdef % for level 2 PPD PageSizes
  136. /Courier findfont 12 scalefont setfont % handle no setfont
  137. /initclip {0 0 moveto 0 792 lineto 612 792 lineto 612 0 lineto closepath
  138. clip newpath } bdef
  139. /xdef {exch def} bdef
  140. /trx {transform exch} bdef
  141. /cbdef {cvx bind def} bdef
  142. /jltz {dup abs 0.0001 lt {pop 0} if} bdef % get rid of scientific notation bug
  143. /clstate false def % closepath state
  144. /dpth false def % destroy path (ie newpath)
  145. /fclp false def % first paint after clip
  146. /kscl {1.0} def % default current scale X-factor
  147. /gcnt {1} def % graphics state counter
  148. /spth {1} def % multiple paths on stack
  149. /jeol (\n) def % default end-of-line
  150. /jnump {0} def % number of paths on stack
  151. /jx {0} def /jy {0} def /j_ax {0} def
  152. /j3ftxt true def
  153. /clarry 10 array def
  154. 0 1 9 {clarry exch false put} for % initilize no clipping path
  155. %
  156. % handle cmyk color on level 1 interpreters
  157. /setcmykcolor where {pop}
  158. {/setcmykcolor {
  159. /blk exch def /yel exch def /mag exch def /cyan exch def
  160. /ccomp {add dup 1 gt {pop 1} if} def
  161. /red {1 cyan blk ccomp sub} def
  162. /green {1 mag blk ccomp sub} def
  163. /blue {1 yel blk ccomp sub} def
  164. red green blue setrgbcolor
  165. } bdef
  166. } ifelse
  167. /currentcmykcolor where {pop}
  168. {/currentcmykcolor {
  169. currentrgbcolor /bval xdef /gval xdef /rval xdef
  170. /rawC 1 rval sub def /rawM 1 gval sub def /rawY 1 bval sub def
  171. rawC rawM ge { rawY rawM ge { /blk rawM def} if } if
  172. rawC rawY ge { rawM rawY ge { /blk rawY def} if } if
  173. rawY rawC ge { rawM rawC ge { /blk rawC def} if } if
  174. rawY rawC eq { rawM rawC eq { /blk rawC def} if } if
  175. /cyan rawC blk sub def
  176. /mag rawM blk sub def
  177. /yel rawY blk sub def
  178. /blk blk def
  179. cyan mag yel blk
  180. } bdef
  181. } ifelse
  182. % If using Mac Ghostscript
  183. jMacGS {
  184. % /jeol {(\r) jp} def
  185. /jout true def
  186. (%%Note: Loading ps2ai.ps\n) print
  187. } if
  188. /jstr 40 string def
  189. jout {joutput (w) file /joutput xdef} if
  190. %
  191. % Output
  192. %
  193. jout {/jp { joutput exch writestring } bdef }{/jp {print} bdef} ifelse
  194. /jpnum {jltz ( ) jp =string cvs jp } bdef
  195. /jpmat { (\[) jp { jpnum } forall (\]) jp } bdef
  196. %
  197. % Stack to Paths converters
  198. %
  199. /ckpnt { % check which paint and clipping to use
  200. dpth { % if there are multiple paths on the stack
  201. clarry gcnt get fclp and {clstate {(h W\n) jp }{(H W\n) jp } ifelse} if
  202. spth 0 eq {clstate {(n\n) jp }{(N\n) jp } ifelse} if
  203. spth 1 eq {clstate {(s\n) jp }{(S\n) jp } ifelse} if
  204. spth 2 eq {clstate {(f\n) jp }{(F\n) jp } ifelse} if
  205. } if
  206. } bdef
  207. /jpm {
  208. ckpnt
  209. /dpth true def
  210. transform 2 copy /yst xdef /xst xdef exch jpnum jpnum ( m\n) jp } bdef
  211. /jpl { trx jpnum jpnum ( l\n) jp } bdef
  212. /jpc { 6 4 roll trx jpnum jpnum 4 2 roll trx jpnum jpnum trx
  213. jpnum jpnum ( c\n) jp } bdef
  214. /jpp {xst jpnum yst jpnum ( l\n) jp /clstate true def} bdef
  215. /cntpaths { % count paths on stack
  216. oldgsave
  217. {pop pop /jnump jnump 1 add def} {pop pop} {6 {pop} repeat}{} pathforall
  218. oldgrestore
  219. } bdef
  220. /ppforall {
  221. cntpaths % find out how many paths are on the stack
  222. jnump 1 gt { (*u\n) jp } if
  223. {jpm}{jpl}{jpc}{jpp} pathforall
  224. ckpnt
  225. jnump 1 gt { (*U\n) jp } if
  226. /jnump 0 def /clstate false def /dpth false def /fclp false def
  227. oldnewpath
  228. } bdef
  229. %
  230. % Painting Operators
  231. %
  232. /oldnewpath [/newpath load] cbdef
  233. /newpath { (\n) jp /spth 0 def ppforall} bdef
  234. /stroke { (\n) jp /spth 1 def ppforall } bdef
  235. /fill {(\n) jp /spth 2 def ppforall } bdef
  236. /eofill {(1 D\n) jp fill (0 D\n) jp} bdef
  237. /clip {clarry gcnt get {(Q\nq\n) jp}{(q\n) jp} ifelse
  238. /fclp true def clarry gcnt true put} bdef
  239. /eoclip {(1 D\n) jp clip (0 D\n) jp} bdef
  240. %
  241. % Text Operators
  242. %
  243. /oldshow [/show load] cbdef
  244. /curpt {stringwidth pop jx add jy} bdef
  245. /jNN {dup 0 eq {pop oldgsave currentfont /FontMatrix get setmatrix kscl
  246. oldgrestore} if
  247. } bdef
  248. /curftmatrix {
  249. currentfont /FontMatrix get dup 0 get jNN abs /norm exch def
  250. dup 0 get norm div exch dup
  251. 1 get norm div exch dup 2 get norm div exch dup 3 get norm div exch dup
  252. 4 get exch 5 get 6 array astore matrix currentmatrix matrix concatmatrix
  253. } bdef
  254. % AI does not support negitive font sizes
  255. /curftsize {currentfont /FontMatrix get 0 get jNN abs 1000 mul} bdef
  256. /hstr (X) def
  257. /vbar (|) 0 get def /undsc (_) 0 get def
  258. /ftnamefix { % handle font names with |,_ (previously encoded)
  259. jstr cvs
  260. { %forall
  261. dup vbar eq {pop}{ %ifelse
  262. dup undsc eq {pop}{ %ifelse
  263. hstr exch 0 exch put hstr jp
  264. } ifelse
  265. } ifelse
  266. } forall flush
  267. } bdef
  268. %/curftname {currentfont /FontName get ftnamefix} bdef
  269. /curftname { currentfont /FontName known {currentfont /FontName get}
  270. { (Times-Roman)} ifelse ftnamefix } bdef
  271. /lftpar (\() 0 get def
  272. /rhtpar (\)) 0 get def
  273. /bckslsh (\\) 0 get def
  274. /handft { % handle strings with (,),\
  275. (\() jp
  276. { %forall
  277. dup lftpar eq { (\\\() jp }{ %ifelse
  278. dup rhtpar eq { (\\\)) jp }{ %ifelse
  279. dup bckslsh eq { (\\\\) jp }{ %ifelse
  280. hstr exch 0 exch put hstr jp
  281. } ifelse
  282. } ifelse
  283. } ifelse
  284. } forall (\)) jp flush
  285. } bdef
  286. % AI 3 text format pieces
  287. jtxt3 {
  288. /j3txt { j3ftxt {(0 Ts 100 Tz 0 Tt 0 TA 0 0 5 TC 100 100 200 TW 0 0 0 Ti\n) jp
  289. (0 Ta 0 Tq 0 0 TI 0 Tc 0 Tw\n) jp} if } bdef
  290. /show {oldgsave (0 To\n) jp
  291. currentpoint 2 copy /jy exch def /jx exch def translate
  292. curftmatrix /jitm exch def
  293. 0 1 5 {jitm exch get jpnum} for ( 0 Tp\n) jp (TP\n) jp
  294. (0 Tr\n) jp (\/_) jp curftname curftsize jpnum ( Tf\n) jp
  295. (0) jp j_ax curftsize div 100 mul jpnum ( 100 TC\n) jp % percent(?)
  296. dup curpt moveto mark exch handft ( Tx\n) jp (TO\n) jp /j3ftxt false def
  297. cleartomark currentpoint oldgrestore moveto
  298. } bdef
  299. /ashow {exch pop exch /j_ax exch def show /j_ax {0} def } bdef
  300. }
  301. {
  302. /show {oldgsave (u\n) jp currentpoint 2 copy /jy exch def /jx exch def translate
  303. (\/) jp curftname jstr cvs jp
  304. curftsize dup jpnum jpnum ( 0 0 z\n) jp
  305. curftmatrix jpmat ( e\n) jp
  306. dup curpt moveto mark exch handft ( t T U\n) jp
  307. cleartomark currentpoint oldgrestore moveto} bdef
  308. /ashow {oldgsave (u\n) jp currentpoint translate (\/) jp curftname jstr cvs jp
  309. curftsize dup jpnum jpnum exch kscl mul jpnum ( 0 z\n) jp
  310. curftmatrix jpmat ( e\n) jp dup curpt moveto mark exch handft
  311. ( t T U\n) jp cleartomark currentpoint oldgrestore moveto} bdef
  312. } ifelse
  313. /widthshow { show pop pop pop} bdef
  314. /awidthshow {ashow pop pop pop} bdef
  315. /kshow {show pop} bdef
  316. %/show {true charpath fill} bdef % get outline of charactor
  317. joutln {/show { true charpath currentpoint
  318. /jy exch def /jx exch def fill jx jy moveto} bdef} if
  319. %/show {oldshow} bdef % do nothing different
  320. %
  321. % Color Operators
  322. %
  323. /oldsetcmykcolor [/setcmykcolor load] cbdef
  324. /setcmykcolor {oldsetcmykcolor
  325. currentcmykcolor 4 -1 roll jpnum 3 -1 roll jpnum 2 -1 roll jpnum jpnum ( k\n) jp
  326. currentcmykcolor 4 -1 roll jpnum 3 -1 roll jpnum 2 -1 roll jpnum jpnum ( K\n) jp
  327. } bdef
  328. /oldsetgray [/setgray load] cbdef
  329. /setgray {0 0 0 4 -1 roll 1 exch sub setcmykcolor} bdef
  330. /oldsethsbcolor [/sethsbcolor load] cbdef
  331. /sethsbcolor {oldsethsbcolor currentcmykcolor setcmykcolor} bdef
  332. /oldsetrgbcolor [/setrgbcolor load] cbdef
  333. /setrgbcolor {oldsetrgbcolor currentrgbcolor /bval xdef /gval xdef /rval xdef
  334. /rawC 1 rval sub def /rawM 1 gval sub def /rawY 1 bval sub def
  335. rawC rawM ge { rawY rawM ge { /blk rawM def} if } if
  336. rawC rawY ge { rawM rawY ge { /blk rawY def} if } if
  337. rawY rawC ge { rawM rawC ge { /blk rawC def} if } if
  338. rawY rawC eq { rawM rawC eq { /blk rawC def} if } if
  339. /cyan rawC blk sub def
  340. /mag rawM blk sub def
  341. /yel rawY blk sub def
  342. /blk blk def
  343. cyan mag yel blk setcmykcolor } bdef
  344. %
  345. % State Operators
  346. %
  347. /oldsetlinewidth [/setlinewidth load] cbdef
  348. /setlinewidth {kscl abs mul jltz oldsetlinewidth
  349. currentlinewidth jpnum ( w\n) jp } bdef
  350. /oldsetlinecap [/setlinecap load] cbdef
  351. /setlinecap {dup oldsetlinecap jpnum ( J\n) jp} bdef
  352. /oldsetlinejoin [/setlinejoin load] cbdef
  353. /setlinejoin {dup oldsetlinejoin jpnum ( j\n) jp} bdef
  354. /oldsetmiterlimit [/setmiterlimit load] cbdef
  355. /setmiterlimit {dup oldsetmiterlimit jpnum ( M\n) jp}bdef
  356. /oldsetdash [/setdash load] cbdef
  357. /setdash {exch [ exch {kscl abs mul} forall ] exch kscl abs mul oldsetdash
  358. currentdash exch jpmat jpnum ( d\n) jp } bdef
  359. /oldsetflat [/setflat load] cbdef
  360. /setflat {dup oldsetflat jpnum ( i\n) jp } bdef
  361. %
  362. % More State Operators
  363. %
  364. /kscl { % use just the x scale factor
  365. oldgsave
  366. matrix currentmatrix /jctm exch def
  367. jctm 4 0 put jctm 5 0 put jctm setmatrix
  368. 1 0 moveto currentpoint transform
  369. dup mul exch dup mul add sqrt 10000 mul round 10000 div
  370. oldgrestore
  371. } bdef
  372. /currentstate {currentcmykcolor setcmykcolor
  373. currentflat jpnum ( i) jp currentlinecap jpnum ( J) jp
  374. currentlinejoin jpnum ( j) jp currentlinewidth jpnum ( w) jp
  375. currentmiterlimit jpnum ( M ) jp currentdash exch jpmat jpnum ( d\n) jp
  376. } bdef
  377. /jdifG {
  378. currentcmykcolor /jok xdef /joy xdef /jom xdef /joc xdef
  379. currentflat /jof xdef currentlinecap /jolc xdef currentlinejoin /jolj xdef
  380. currentlinewidth /jolw xdef currentmiterlimit /joml xdef
  381. currentdash /jood xdef /joad xdef
  382. oldgrestore
  383. currentcmykcolor /jnk xdef /jny xdef /jnm xdef /jnc xdef
  384. currentflat /jnf xdef currentlinecap /jnlc xdef currentlinejoin /jnlj xdef
  385. currentlinewidth /jnlw xdef currentmiterlimit /jnml xdef
  386. currentdash /jnod xdef /jnad xdef
  387. % compare old gstate to new gstate
  388. joc jnc ne jom jnm ne joy jny ne jok jnk ne
  389. jof jnf ne jolc jnlc ne jolj jnlj ne jolw jnlw ne joml jnml ne
  390. false joad {true exit} forall {pop pop true}{false} ifelse
  391. false jnad {true exit} forall {pop pop true}{false} ifelse ne
  392. jood jnod ne 10 {or} repeat {currentstate} if
  393. } bdef
  394. /oldgsave [/gsave load] cbdef
  395. /gsave {oldgsave /gcnt gcnt 1 add def } bdef % clarry gcnt false put} bdef
  396. % (%%Note:gsave ) jp gcnt jpnum (\n) jp} bdef
  397. /oldgrestore [/grestore load] cbdef
  398. /grestore {dpth {newpath} if clarry gcnt get {(Q\n) jp clarry gcnt false put} if
  399. jdifG /gcnt gcnt 1 sub def } bdef
  400. % oldgrestore currentstate } bdef
  401. % (%%Note:grestore ) jp gcnt 1 add jpnum (\n) jp} bdef
  402. /oldrestore [/restore load] cbdef
  403. % a kludgy way of saving the clipping path status information
  404. /restore {clarry aload pop 11 -1 roll oldrestore clarry astore pop} bdef
  405. /showpage { 0 1 9 {clarry exch get {(Q\n) jp} if } for
  406. (%%Note: If Error, make sure there are matched pairs of 'q's and 'Q's\n) jp
  407. (%%Note: in the file. Add 'Q's before '%%Trailer' until equal\n) jp
  408. (%%Trailer\n) jp
  409. jtxt3 {(Adobe_IllustratorA_AI3 /terminate get exec\n) jp
  410. (Adobe_typography_AI3 /terminate get exec\n) jp
  411. (Adobe_customcolor /terminate get exec\n) jp
  412. (Adobe_cshow /terminate get exec\n) jp
  413. (Adobe_cmykcolor /terminate get exec\n) jp
  414. (Adobe_packedarray /terminate get exec\n) jp
  415. }{
  416. (Adobe_Illustrator881 /terminate get exec\n) jp
  417. (Adobe_customcolor /terminate get exec\n) jp
  418. (Adobe_cshow /terminate get exec\n) jp
  419. (Adobe_cmykcolor /terminate get exec\n) jp
  420. (Adobe_packedarray /terminate get exec\n) jp
  421. } ifelse
  422. ( showpage\n%EOF\n%%EndDocument\n) jp
  423. jout {joutput closefile} if jMacGS not {quit} if /j3ftxt true def } bdef
  424. %
  425. % Error handling
  426. %
  427. errordict begin
  428. % Attempt to handle the error caused by bitmap fonts (TeX,Windows.ps,etc)
  429. % this is a big-time kludge
  430. jbiterr {
  431. /undefined {pop pop (Times-Roman)} bdef
  432. /typecheck {pop pop} bdef
  433. } if
  434. jerr {
  435. /handleerror {
  436. (%%Note: ps2ai error, aborting rest of conversion\n) jp showpage
  437. } bdef
  438. } if
  439. end
  440. %
  441. % Mac LW 8 improvements
  442. %
  443. /jmacimp { % stroked line instead of thin filled boxes
  444. /@a { 3 -1 roll 2 div dup 3 -1 roll add exch 3 -1 roll add exch moveto
  445. 3 -1 roll 2 div dup 3 -1 roll add exch 3 -1 roll exch sub exch lineto
  446. abs setlinewidth stroke pop pop} bdef
  447. /@b { 3 -1 roll 2 div dup 3 -1 roll add exch 3 -1 roll add exch moveto
  448. pop
  449. 3 -1 roll 2 div dup 3 -1 roll add exch 3 -1 roll add exch lineto
  450. abs setlinewidth stroke} bdef
  451. /endp {showpage pm restore} bdef % because the restore stops clean up
  452. } bdef
  453. %
  454. % Handle (some) PS Level 2
  455. %
  456. /rectstroke { 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto
  457. closepath stroke} bdef
  458. /rectfill { 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto
  459. fill } bdef
  460. /rectclip { 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto
  461. closepath clip newpath jMacfix {jmacimp} if } bdef
  462. %
  463. % Add a header prolog to the output file so it is still view/print-able
  464. %
  465. (%!PS-Adobe-2.0 EPSF-1.2\n%%BoundingBox: 0 0 612 792\n) jp
  466. (%%Title: Adobe Illustator 3 Editable Document\n) jp
  467. (%%Creator: ps2ai.ps vers.) jp vers jpnum ( \(C\) 1993-94 Jason Olszewski\n) jp
  468. (%%TemplateBox: 0 0 612 792\n) jp
  469. jtxt3 {(%%AI3_Margin:0 0 0 0\n) jp } if
  470. (%%EndComments\n) jp
  471. (%%BeginProlog\n) jp
  472. (/m {moveto} def /l {lineto} def /c {curveto} def\n) jp
  473. (/S {stroke} def /F {fill} def\n) jp
  474. (/s {closepath S} def /f {closepath F} def\n) jp
  475. (/q {gsave} def /Q {grestore} def /W {clip} def /k {setcmykcolor} def\n) jp
  476. (/i {setflat} def /J {setlinecap} def /j {setlinejoin} def\n) jp
  477. (/w {setlinewidth} def /M {setmiterlimit} def /d {setdash} def\n) jp
  478. (/u {gsave} def /U {grestore} def /K {k} def\n) jp
  479. (/N {newpath} def /n {closepath N} def\n) jp
  480. (/g {setgray} def /G {g} def\n) jp
  481. (/x {pop pop k} def /X {x} def\n) jp
  482. (/H {} def /h {H closepath} def /D {pop} def\n) jp
  483. (/*u { /N {/spth 0 def}def /S{/spth 1 def}def /F {/spth 2 def} def} def\n) jp
  484. (/*U { spth 0 eq {newpath} if spth 1 eq {stroke} if spth 2 eq {fill} if\n) jp
  485. ( /N {newpath} def /S {stroke} def /F {fill} def } def\n) jp
  486. %(\n) jp
  487. jtxt3 {
  488. (/TC {pop pop pop} def /Tr {pop} def\n) jp
  489. (/To {pop gsave} def /TO {grestore} def\n) jp
  490. (/Tp {pop matrix astore concat} def /TP {0 0 moveto} def\n) jp
  491. (/a_str 40 string def /cnt 0 def /h_str (X) def /undsc (_) 0 get def\n) jp
  492. (/fntfix {a_str cvs dup length 1 sub /f_str exch string def\n) jp
  493. ( {dup undsc eq {pop}{f_str cnt 3 -1 roll put /cnt cnt 1 add def\n) jp
  494. ( } ifelse } forall flush /cnt 0 def f_str cvn } bind def\n) jp
  495. (/Tf {exch fntfix findfont exch scalefont setfont} def /Tx {show} def\n) jp
  496. }{
  497. (/z {pop pop pop exch findfont exch scalefont setfont} def\n) jp
  498. (/e {concat 0 0 m} def /t {show} def /T {} def\n) jp
  499. } ifelse
  500. (\n) jp
  501. jtxt3 {
  502. (userdict /Adobe_packedarray 2 dict dup begin put\n) jp
  503. (/initialize {} def /terminate {} def\n) jp
  504. (userdict /Adobe_cmykcolor 2 dict dup begin put\n) jp
  505. (/initialize {} def /terminate {} def\n) jp
  506. (userdict /Adobe_cshow 2 dict dup begin put\n) jp
  507. (/initialize {} def /terminate {} def\n) jp
  508. (userdict /Adobe_customcolor 2 dict dup begin put\n) jp
  509. (/initialize {} def /terminate {} def\n) jp
  510. (userdict /Adobe_typography_AI3 2 dict dup begin put\n) jp
  511. (/initialize {} def /terminate {} def\n) jp
  512. (userdict /Adobe_IllustratorA_AI3 2 dict dup begin put\n) jp
  513. (/initialize {} def /terminate {} def\n) jp
  514. }{
  515. (userdict /Adobe_packedarray 2 dict dup begin put\n) jp
  516. (/initialize {} def /terminate {} def\n) jp
  517. (userdict /Adobe_cmykcolor 2 dict dup begin put\n) jp
  518. (/initialize {} def /terminate {} def\n) jp
  519. (userdict /Adobe_cshow 2 dict dup begin put\n) jp
  520. (/initialize {} def /terminate {} def\n) jp
  521. (userdict /Adobe_customcolor 2 dict dup begin put\n) jp
  522. (/initialize {} def /terminate {} def\n) jp
  523. (userdict /Adobe_Illustrator881 2 dict dup begin put\n) jp
  524. (/initialize {} def /terminate {} def\n) jp
  525. } ifelse
  526. (%%EndProlog\n) jp
  527. (%%BeginSetup\n) jp
  528. jtxt3 {
  529. (Adobe_packedarray /initialize get exec\n) jp
  530. (Adobe_cmykcolor /initialize get exec\n) jp
  531. (Adobe_cshow /initialize get exec\n) jp
  532. (Adobe_customcolor /initialize get exec\n) jp
  533. (Adobe_typography_AI3 /initialize get exec\n) jp
  534. (Adobe_IllustratorA_AI3 /initialize get exec\n) jp
  535. }{
  536. (Adobe_packedarray /initialize get exec\n) jp
  537. (Adobe_cmykcolor /initialize get exec\n) jp
  538. (Adobe_cshow /initialize get exec\n) jp
  539. (Adobe_customcolor /initialize get exec\n) jp
  540. (Adobe_Illustrator881 /initialize get exec\n) jp
  541. } ifelse
  542. (%%EndSetup\n) jp
  543. 0 0 0 1 oldsetcmykcolor
  544. currentstate
  545. jout {(%%Note: Load Postscript file to be converted now\n) print} if