home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / doc / idraw.pro < prev    next >
Text File  |  1995-07-03  |  10KB  |  521 lines

  1. %% Idraw 2.5 Prolog
  2. %% Modified by colas July 19 89 (naming of the dictionnary)
  3. %% + xpr dict (July 21 89 colas)
  4.  
  5. /IdrawDict 50 dict def
  6. IdrawDict begin
  7.  
  8. /arrowHeight 8 def
  9. /arrowWidth 4 def
  10. /none null def
  11. /numGraphicParameters 17 def
  12. /stringLimit 65535 def
  13.  
  14. /Begin {
  15. save
  16. numGraphicParameters dict begin
  17. } def
  18.  
  19. /End {
  20. end
  21. restore
  22. } def
  23.  
  24. /SetB {
  25. dup type /nulltype eq {
  26. pop
  27. false /brushRightArrow idef
  28. false /brushLeftArrow idef
  29. true /brushNone idef
  30. } {
  31. /brushDashOffset idef
  32. /brushDashArray idef
  33. 0 ne /brushRightArrow idef
  34. 0 ne /brushLeftArrow idef
  35. /brushWidth idef
  36. false /brushNone idef
  37. } ifelse
  38. } def
  39.  
  40. /SetCFg {
  41. /fgblue idef
  42. /fggreen idef
  43. /fgred idef
  44. } def
  45.  
  46. /SetCBg {
  47. /bgblue idef
  48. /bggreen idef
  49. /bgred idef
  50. } def
  51.  
  52. /SetF {
  53. /printSize idef
  54. /printFont idef
  55. } def
  56.  
  57. /SetP {
  58. dup type /nulltype eq {
  59. pop true /patternNone idef
  60. } {
  61. /patternGrayLevel idef
  62. patternGrayLevel -1 eq {
  63. /patternString idef
  64. } if
  65. false /patternNone idef
  66. } ifelse
  67. } def
  68.  
  69. /BSpl {
  70. 0 begin
  71. storexyn
  72. newpath
  73. n 1 gt {
  74. 0 0 0 0 0 0 1 1 true subspline
  75. n 2 gt {
  76. 0 0 0 0 1 1 2 2 false subspline
  77. 1 1 n 3 sub {
  78. /i exch def
  79. i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
  80. } for
  81. n 3 sub dup n 2 sub dup n 1 sub dup 2 copy false subspline
  82. } if
  83. n 2 sub dup n 1 sub dup 2 copy 2 copy false subspline
  84. patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
  85. brushNone not { istroke } if
  86. 0 0 1 1 leftarrow
  87. n 2 sub dup n 1 sub dup rightarrow
  88. } if
  89. end
  90. } dup 0 4 dict put def
  91.  
  92. /Circ {
  93. newpath
  94. 0 360 arc
  95. patternNone not { ifill } if
  96. brushNone not { istroke } if
  97. } def
  98.  
  99. /CBSpl {
  100. 0 begin
  101. dup 2 gt {
  102. storexyn
  103. newpath
  104. n 1 sub dup 0 0 1 1 2 2 true subspline
  105. 1 1 n 3 sub {
  106. /i exch def
  107. i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
  108. } for
  109. n 3 sub dup n 2 sub dup n 1 sub dup 0 0 false subspline
  110. n 2 sub dup n 1 sub dup 0 0 1 1 false subspline
  111. patternNone not { ifill } if
  112. brushNone not { istroke } if
  113. } {
  114. Poly
  115. } ifelse
  116. end
  117. } dup 0 4 dict put def
  118.  
  119. /Elli {
  120. 0 begin
  121. newpath
  122. 4 2 roll
  123. translate
  124. scale
  125. 0 0 1 0 360 arc
  126. patternNone not { ifill } if
  127. brushNone not { istroke } if
  128. end
  129. } dup 0 1 dict put def
  130.  
  131. /Line {
  132. 0 begin
  133. 2 storexyn
  134. newpath
  135. x 0 get y 0 get moveto
  136. x 1 get y 1 get lineto
  137. brushNone not { istroke } if
  138. 0 0 1 1 leftarrow
  139. 0 0 1 1 rightarrow
  140. end
  141. } dup 0 4 dict put def
  142.  
  143. /MLine {
  144. 0 begin
  145. storexyn
  146. newpath
  147. n 1 gt {
  148. x 0 get y 0 get moveto
  149. 1 1 n 1 sub {
  150. /i exch def
  151. x i get y i get lineto
  152. } for
  153. patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
  154. brushNone not { istroke } if
  155. 0 0 1 1 leftarrow
  156. n 2 sub dup n 1 sub dup rightarrow
  157. } if
  158. end
  159. } dup 0 4 dict put def
  160.  
  161. /Poly {
  162. 3 1 roll
  163. newpath
  164. moveto
  165. -1 add
  166. { lineto } repeat
  167. closepath
  168. patternNone not { ifill } if
  169. brushNone not { istroke } if
  170. } def
  171.  
  172. /Rect {
  173. 0 begin
  174. /t exch def
  175. /r exch def
  176. /b exch def
  177. /l exch def
  178. newpath
  179. l b moveto
  180. l t lineto
  181. r t lineto
  182. r b lineto
  183. closepath
  184. patternNone not { ifill } if
  185. brushNone not { istroke } if
  186. end
  187. } dup 0 4 dict put def
  188.  
  189. /Text {
  190. ishow
  191. } def
  192.  
  193. /idef {
  194. dup where { pop pop pop } { exch def } ifelse
  195. } def
  196.  
  197. /ifill {
  198. 0 begin
  199. gsave
  200. patternGrayLevel -1 ne {
  201. fgred bgred fgred sub patternGrayLevel mul add
  202. fggreen bggreen fggreen sub patternGrayLevel mul add
  203. fgblue bgblue fgblue sub patternGrayLevel mul add setrgbcolor
  204. eofill
  205. } {
  206. eoclip
  207. originalCTM setmatrix
  208. pathbbox /t exch def /r exch def /b exch def /l exch def
  209. /w r l sub ceiling cvi def
  210. /h t b sub ceiling cvi def
  211. /imageByteWidth w 8 div ceiling cvi def
  212. /imageHeight h def
  213. bgred bggreen bgblue setrgbcolor
  214. eofill
  215. fgred fggreen fgblue setrgbcolor
  216. w 0 gt h 0 gt and {
  217. l b translate w h scale
  218. w h true [w 0 0 h neg 0 h] { patternproc } imagemask
  219. } if
  220. } ifelse
  221. grestore
  222. end
  223. } dup 0 8 dict put def
  224.  
  225. /istroke {
  226. gsave
  227. brushDashOffset -1 eq {
  228. [] 0 setdash
  229. 1 setgray
  230. } {
  231. brushDashArray brushDashOffset setdash
  232. fgred fggreen fgblue setrgbcolor
  233. } ifelse
  234. brushWidth setlinewidth
  235. originalCTM setmatrix
  236. stroke
  237. grestore
  238. } def
  239.  
  240. /ishow {
  241. 0 begin
  242. gsave
  243. printFont findfont printSize scalefont setfont
  244. fgred fggreen fgblue setrgbcolor
  245. /vertoffset printSize neg def {
  246. 0 vertoffset moveto show
  247. /vertoffset vertoffset printSize sub def
  248. } forall
  249. grestore
  250. end
  251. } dup 0 3 dict put def
  252.  
  253. /patternproc {
  254. 0 begin
  255. /patternByteLength patternString length def
  256. /patternHeight patternByteLength 8 mul sqrt cvi def
  257. /patternWidth patternHeight def
  258. /patternByteWidth patternWidth 8 idiv def
  259. /imageByteMaxLength imageByteWidth imageHeight mul
  260. stringLimit patternByteWidth sub min def
  261. /imageMaxHeight imageByteMaxLength imageByteWidth idiv patternHeight idiv
  262. patternHeight mul patternHeight max def
  263. /imageHeight imageHeight imageMaxHeight sub store
  264. /imageString imageByteWidth imageMaxHeight mul patternByteWidth add string def
  265. 0 1 imageMaxHeight 1 sub {
  266. /y exch def
  267. /patternRow y patternByteWidth mul patternByteLength mod def
  268. /patternRowString patternString patternRow patternByteWidth getinterval def
  269. /imageRow y imageByteWidth mul def
  270. 0 patternByteWidth imageByteWidth 1 sub {
  271. /x exch def
  272. imageString imageRow x add patternRowString putinterval
  273. } for
  274. } for
  275. imageString
  276. end
  277. } dup 0 12 dict put def
  278.  
  279. /min {
  280. dup 3 2 roll dup 4 3 roll lt { exch } if pop
  281. } def
  282.  
  283. /max {
  284. dup 3 2 roll dup 4 3 roll gt { exch } if pop
  285. } def
  286.  
  287. /arrowhead {
  288. 0 begin
  289. transform originalCTM itransform
  290. /taily exch def
  291. /tailx exch def
  292. transform originalCTM itransform
  293. /tipy exch def
  294. /tipx exch def
  295. /dy tipy taily sub def
  296. /dx tipx tailx sub def
  297. /angle dx 0 ne dy 0 ne or { dy dx atan } { 90 } ifelse def
  298. gsave
  299. originalCTM setmatrix
  300. tipx tipy translate
  301. angle rotate
  302. newpath
  303. 0 0 moveto
  304. arrowHeight neg arrowWidth 2 div lineto
  305. arrowHeight neg arrowWidth 2 div neg lineto
  306. closepath
  307. patternNone not {
  308. originalCTM setmatrix
  309. /padtip arrowHeight 2 exp 0.25 arrowWidth 2 exp mul add sqrt brushWidth mul
  310. arrowWidth div def
  311. /padtail brushWidth 2 div def
  312. tipx tipy translate
  313. angle rotate
  314. padtip 0 translate
  315. arrowHeight padtip add padtail add arrowHeight div dup scale
  316. arrowheadpath
  317. ifill
  318. } if
  319. brushNone not {
  320. originalCTM setmatrix
  321. tipx tipy translate
  322. angle rotate
  323. arrowheadpath
  324. istroke
  325. } if
  326. grestore
  327. end
  328. } dup 0 9 dict put def
  329.  
  330. /arrowheadpath {
  331. newpath
  332. 0 0 moveto
  333. arrowHeight neg arrowWidth 2 div lineto
  334. arrowHeight neg arrowWidth 2 div neg lineto
  335. closepath
  336. } def
  337.  
  338. /leftarrow {
  339. 0 begin
  340. y exch get /taily exch def
  341. x exch get /tailx exch def
  342. y exch get /tipy exch def
  343. x exch get /tipx exch def
  344. brushLeftArrow { tipx tipy tailx taily arrowhead } if
  345. end
  346. } dup 0 4 dict put def
  347.  
  348. /rightarrow {
  349. 0 begin
  350. y exch get /tipy exch def
  351. x exch get /tipx exch def
  352. y exch get /taily exch def
  353. x exch get /tailx exch def
  354. brushRightArrow { tipx tipy tailx taily arrowhead } if
  355. end
  356. } dup 0 4 dict put def
  357.  
  358. /midpoint {
  359. 0 begin
  360. /y1 exch def
  361. /x1 exch def
  362. /y0 exch def
  363. /x0 exch def
  364. x0 x1 add 2 div
  365. y0 y1 add 2 div
  366. end
  367. } dup 0 4 dict put def
  368.  
  369. /thirdpoint {
  370. 0 begin
  371. /y1 exch def
  372. /x1 exch def
  373. /y0 exch def
  374. /x0 exch def
  375. x0 2 mul x1 add 3 div
  376. y0 2 mul y1 add 3 div
  377. end
  378. } dup 0 4 dict put def
  379.  
  380. /subspline {
  381. 0 begin
  382. /movetoNeeded exch def
  383. y exch get /y3 exch def
  384. x exch get /x3 exch def
  385. y exch get /y2 exch def
  386. x exch get /x2 exch def
  387. y exch get /y1 exch def
  388. x exch get /x1 exch def
  389. y exch get /y0 exch def
  390. x exch get /x0 exch def
  391. x1 y1 x2 y2 thirdpoint
  392. /p1y exch def
  393. /p1x exch def
  394. x2 y2 x1 y1 thirdpoint
  395. /p2y exch def
  396. /p2x exch def
  397. x1 y1 x0 y0 thirdpoint
  398. p1x p1y midpoint
  399. /p0y exch def
  400. /p0x exch def
  401. x2 y2 x3 y3 thirdpoint
  402. p2x p2y midpoint
  403. /p3y exch def
  404. /p3x exch def
  405. movetoNeeded { p0x p0y moveto } if
  406. p1x p1y p2x p2y p3x p3y curveto
  407. end
  408. } dup 0 17 dict put def
  409.  
  410. /storexyn {
  411. /n exch def
  412. /y n array def
  413. /x n array def
  414. n 1 sub -1 0 {
  415. /i exch def
  416. y i 3 2 roll put
  417. x i 3 2 roll put
  418. } for
  419. } def
  420.  
  421. end
  422.  
  423. %% Xpr dictionnary
  424.  
  425. /XprDict 50 dict def
  426. XprDict begin
  427.  
  428. /bitgen
  429.     {
  430.         /nextpos 0 def
  431.         currentfile bufspace readhexstring pop % get a chunk of input
  432.         % interpret each byte of the input
  433.         {
  434.             flag { % if the previous byte was FF
  435.                 /len exch def % this byte is a count
  436.                 result
  437.                 nextpos
  438.                 FFstring 0 len getinterval % grap a chunk of FF's
  439.                     putinterval % and stuff them into the result
  440.                 /nextpos nextpos len add def
  441.                 /flag false def
  442.             }{ % otherwise
  443.                 dup 255 eq { % if this byte is FF
  444.                     /flag true def % just set the flag
  445.                     pop % and toss the FF
  446.                 }{ % otherwise
  447.                     % move this byte to the result
  448.                     result nextpos
  449.                         3 -1 roll % roll the current byte back to the top
  450.                         put
  451.                     /nextpos nextpos 1 add def
  452.                 } ifelse
  453.             } ifelse
  454.         } forall
  455.         % trim unused space from end of result
  456.         result 0 nextpos getinterval
  457.     } def
  458.  
  459.  
  460. /bitdumpcomp % stk: width, height, iscale
  461.     % dump a bit image with lower left corner at current origin,
  462.     % scaling by iscale (iscale=1 means 1/300 inch per pixel)
  463.     {
  464.         % read arguments
  465.         /iscale exch def
  466.         /height exch def
  467.         /width exch def
  468.  
  469.         % scale appropriately
  470.         width iscale mul height iscale mul scale
  471.  
  472.         % data structures:
  473.  
  474.         % allocate space for one line of input
  475.         /bufspace 36 string def
  476.  
  477.         % string of FF's
  478.         /FFstring 256 string def
  479.         % for all i FFstring[i]=255
  480.         0 1 255 { FFstring exch 255 put } for
  481.  
  482.         % 'escape' flag
  483.         /flag false def
  484.  
  485.         % space for a chunk of generated bits
  486.         /result 1000 string def
  487.  
  488.         % read and dump the image
  489.         width height 1 [width 0 0 height neg 0 height]
  490.             { bitgen }
  491.             image
  492.     } def
  493.  
  494. /bitdump % stk: width, height, iscale
  495. % dump a bit image with lower left corner at current origin,
  496. % scaling by iscale (iscale=1 means 1/300 inch per pixel)
  497. {
  498.     % read arguments
  499.     /iscale exch def
  500.     /height exch def
  501.     /width exch def
  502.  
  503.     % scale appropriately
  504.     width iscale mul height iscale mul scale
  505.  
  506.     % allocate space for one scanline of input
  507.     /picstr % picstr holds one scan line
  508.         width 7 add 8 idiv % width of image in bytes = ceiling(width/8)
  509.         string
  510.         def
  511.  
  512.     % read and dump the image
  513.     width height 1 [width 0 0 height neg 0 height]
  514.     { currentfile picstr readhexstring pop }
  515.     image
  516. } def
  517.  
  518. end
  519.  
  520. %%EndProlog
  521.