home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / libs / import.prolog next >
Text File  |  2006-11-23  |  32KB  |  1,394 lines

  1. %
  2. % psi.prolog
  3. %
  4. % Copyright (C) 1996-2000 by vhf computer GmbH + vhf interservice GmbH
  5. % Author:   Georg Fleischmann
  6. %
  7. % created:  2000-09-09
  8. % modified: 
  9. %
  10.  
  11. %%% this file also contains a section taken from GPL Ghostscript 8.50 "traceimg.ps", see below
  12.  
  13. % this PostScript code writes a file with the structure below.
  14. % # # # # l        (x0 y0 x1 y1) line
  15. % # # # # # # # #c    (x0 y0 x1 y1 x2 y2 x3 y3) curve
  16. % # w            (width) width
  17. % # # # # # co        (c m y k a) color
  18. % n            new list
  19. % f            list is a filled polygon
  20. % s            list is a group
  21. % cl            list is a clip list (clip with old clip list and use it)
  22. % gs            save current clip list and width to top of stack
  23. % gr            use last clip list (on top of stack) and width
  24. % # # # # # # # # # #    (x y a b c d e f text font) text
  25. %
  26. % Adapted for Scribus by Franz Schmid 15.05.2004
  27. % Also removed the hardcoded Output Filename
  28. % and changed it in a way the -sOutputFile Option of Ghostscript can be used
  29. % Speeded up the flattening of Text by removing unneeded calculations.
  30. % Changed the Output slightly to ease parsing
  31. % m                 moveto  
  32. % l # # # #         (x0 y0 x1 y1) line
  33. % c # # # # # # # # (x0 y0 x1 y1 x2 y2 x3 y3) curve
  34. % w #               (width) Linewidth
  35. % co # # # # #      (c m y k a) color
  36. % n                 new list
  37. % f                 list is a filled polygon
  38. % s                 list is a stroke path
  39. % cp                close current subpath
  40. % ci                list is a clip list (clip with old clip list and use it)
  41. % sp                end of page
  42. % lj #              linejoin
  43. % lc #              linecap
  44. % ld # # #n         linedash count offset d1, d2, dx
  45. % im #              image <name>
  46. % pat # #           makepattern params tmpfilename
  47. % mask                imagemask, followed by b/w image
  48. % fill-evenodd        set fill rule
  49. % fill-winding        - " -
  50. % 15.05.2004 Added the Glyphshow Operator.
  51. % 17.05.2004 Made clipping working.
  52. % 20.05.2004 kshow is working now.
  53. % 22.02.2006 added image and colorimage ops -- av
  54. % 02.03.2006 added code to divide reported coordinates by (device resolution/72) -- av
  55. % 23.03.2006 added code to trace PDF commands
  56.  
  57. % some hacks to get access to PDF operators, needs -sDELAYBIND
  58.  
  59. currentglobal true setglobal
  60. GS_PDF_ProcSet begin
  61. currentdict /setshowstate
  62. {
  63.     dup WordSpacing 0 32 TextSpacing 0 6 -1 roll awidthshow
  64.     //setshowstate exec
  65. } .forceput 
  66. currentdict /endpage {
  67.     (sp\n) print
  68.     //endpage exec
  69. } .forceput
  70. end
  71. setglobal
  72. .bindnow
  73.  
  74. /cfile TraceFile (w) file def
  75. /print { cfile exch writestring } bind def
  76.  
  77.  
  78. /==write  % any ==write -
  79.     dup type dup /arraytype eq exch /packedarraytype eq or
  80.     { 
  81.         i_file ([) writestring 
  82.             { ==write i_file ( ) writestring } forall 
  83.         i_file (]) writestring
  84.     } {
  85.     dup type /nametype eq
  86.     {
  87.         i_file (/) writestring i_file exch i_str cvs writestring
  88.     } {
  89.     dup type /stringtype eq
  90.     {
  91.         true 1 index { 32 ge and } forall
  92.         {
  93.             i_file (\() writestring i_file exch writestring i_file (\)) writestring
  94.         }
  95.         {
  96.             i_file (<) writestring
  97.             i_file /ASCIIHexEncode filter dup
  98.             3 -1 roll
  99.             writestring closefile % close filter 
  100.             i_file (\n) writestring            
  101.         } ifelse
  102.     } {
  103.     dup type /dicttype eq
  104.     {
  105.         i_file (<<) writestring
  106.         { ==write ( ) =write ==write (\n) =write } forall
  107.         i_file (>>) writestring
  108.     } {
  109.         i_file exch i_str cvs
  110.         dup dup length 1 sub get (-) 0 get eq { pop (null) } if 
  111.         writestring
  112.     } ifelse } ifelse } ifelse } ifelse
  113. } def
  114.  
  115. /=write  % any =write -
  116.     dup type dup /arraytype eq exch /packedarraytype eq or
  117.     { 
  118.             { =write i_file ( ) writestring } forall 
  119.     } {
  120.     dup type /nametype eq
  121.     {
  122.         i_file exch i_str cvs writestring
  123.     } {
  124.     dup type /stringtype eq
  125.     {
  126.         i_file exch writestring
  127.     } {
  128.     dup type /dicttype eq
  129.     {
  130.         i_file (<<) writestring
  131.         { =write ( ) =write =write (\n) =write } forall
  132.         i_file (>>) writestring
  133.     } {
  134.         i_file exch i_str cvs writestring
  135.     } ifelse } ifelse } ifelse } ifelse
  136. } def
  137.  
  138.  
  139. % flag to deactivate our substitutions
  140. /i_shortcut false def
  141.  
  142. % defines an overloaded function     name proc i_shortcutOverload -
  143. % equvalent to /name { i_shortcut { //name } { proc } ifelse } bind def
  144. /i_shortcutOverload
  145. {
  146.     [ /i_shortcut /load load [ 5 index load ] cvx 4 index /ifelse load ] cvx 
  147.     exch pop 
  148.     bind def
  149. } def
  150.  
  151. % whether we have to flatten the text
  152. /flattenText 1 def
  153.  
  154. % is a Clipping there
  155. /clipCnt 0 def
  156.  
  157. % remember the current point
  158. /currentX 0 def
  159. /currentY 0 def
  160.  
  161. % 1st point of path to close the path
  162. /beginX 0 def
  163. /beginY 0 def
  164.  
  165. % dummy for converting strings
  166. /i_str 50 string def
  167.  
  168. % 0 = mirror at
  169. /mirror 0 def
  170.  
  171. % mirror a at 0
  172. /mir
  173. {
  174.     mirror 0 ne
  175.     {    0 exch sub
  176.     }if
  177. } bind def
  178.  
  179. % scale
  180.  
  181. currentpagedevice /HWResolution get aload pop
  182. 72 div /i_vscale exch def
  183. 72 div /i_hscale exch def
  184.  
  185. /m_a 1 def
  186. /m_b 0 def
  187. /m_c 0 def
  188. /m_d 1 def
  189. /m_x 0 def
  190. /m_y 0 def
  191. /matrix_x    % x y
  192. {
  193.     % ax + cy + tx
  194.     m_c mul exch m_a mul add m_x add i_hscale div
  195. } bind def
  196. /matrix_y    % x y
  197. {
  198.     % bx + dy + ty
  199.     m_d mul exch m_b mul add m_y add i_vscale div
  200. } bind def
  201.  
  202.  
  203. /concatenate   % str1 str2 concatenate str12
  204. {
  205.     dup length 2 index length add string
  206.     dup 3 index length 3 index putinterval
  207.     dup 0 4 index putinterval
  208.     exch pop exch pop
  209. } bind def 
  210.  
  211. % this is like search but returns the last match in string
  212. /rsearch    % string seek  rsearch  post match pre true // string false
  213. {
  214.     2 copy search    % string seek post1 match1 pre1 true
  215.     {
  216.         2 index 4 index rsearch        % string seek post1 match1 pre1 post2 match2 pre2 true
  217.         {
  218.             6 -1 roll pop            % string seek match1 pre1 post2 match2 pre2 
  219.             % combine (pre1 match1 pre2) into one string
  220.             5 -1 roll exch concatenate    % string seek pre1 post2 match2 (match1+pre2)
  221.             4 -1 roll exch concatenate    % string seek post2 match2 (pre1+match1+pre2)
  222.         } {        % string seek post1 match1 pre1 post1
  223.             pop
  224.         } ifelse
  225.         % string seek post match pre
  226.         5 -2 roll pop pop
  227.         true
  228.     } {        % string seek string 
  229.         pop pop false
  230.     } ifelse
  231. } bind def
  232.  
  233.  
  234. % returns a unique filename for the given extension
  235. /i_exportfilename   % string i_exportfilename string
  236. {
  237.     /ExportFiles where { /ExportFiles get (.) rsearch { exch pop exch pop } if } { (imagefile) } ifelse
  238.         (-) concatenate dup /i_basename exch def i_filecount 9 string cvs concatenate
  239.         {
  240.             i_filecount 1 add /i_filecount exch store
  241.             dup 2 index concatenate status not { exit } if
  242.             pop pop pop pop pop
  243.             i_basename i_filecount 9 string cvs concatenate
  244.         } loop
  245.     exch pop
  246. } bind def
  247.  
  248. /makepattern { % dict matrix  makepattern patterndict
  249. %/makepattern =
  250.     % we will do some real painting here:
  251.     /i_shortcut true store
  252.     % params:
  253.     /i_m exch def
  254.     /i_dict exch def
  255.     % define export filename    
  256.     /i_basename (.png) i_exportfilename (.png) concatenate def
  257.     i_dict /BBox get
  258.         dup 0 get /i_x exch def
  259.         dup 1 get /i_y exch def
  260.         dup 2 get i_x sub /i_w exch def
  261.         3 get i_y sub /i_h exch def
  262.     % we want those in devspace:
  263.         i_x i_y i_m itransform matrix currentmatrix transform
  264.             i_vscale div /i_y exch def i_hscale div /i_x exch def
  265.         i_w i_h i_m idtransform matrix currentmatrix dtransform
  266.             i_vscale div /i_h exch def i_hscale div /i_w exch def
  267.         % i_h < 0 ?
  268.         i_h 0 le
  269.         {
  270.             /i_y i_h i_y add def
  271.             /i_h i_h neg def
  272.         } if
  273.         % i_w < 0 ?
  274.         i_w 0 le
  275.         {
  276.             /i_x i_w i_x add def
  277.             /i_w i_w neg def
  278.         } if
  279.     % now we can use the current matrix as pattern matrix, but with (0,0) origin
  280.     i_m ==
  281.     i_x i_y matrix currentmatrix translate /i_m exch def
  282.     i_m ==
  283.     i_dict /BBox [ 0 0 i_w i_h ] put 
  284.     (w x h =) = i_w = i_h =
  285.     % paint pattern to png file
  286.     gsave
  287.     currentcolor currentcolorspace
  288.     << 
  289.         /OutputFile i_basename
  290.         /OutputDevice (pngalpha)
  291.         /TextAlphaBits 4
  292.         /GraphicsAlphaBits 4
  293. %        /BackgroundColor 16777215
  294. %        /BackgroundColor 0
  295.         /PageUsesTransparency true
  296.         /HWResolution [ 72 72 ]
  297.         /ProcessColorModel /DeviceRGB
  298.         /PageSize [i_w i_h]
  299.     /pngalpha finddevice putdeviceprops setdevice 
  300.     setcolorspace setcolor
  301. %    matrix currentmatrix ==
  302. %    0 0 transform exch = =
  303. %    1 1 transform exch = =
  304.     i_dict i_w i_h matrix identmatrix scale 
  305.             %matrix identmatrix 
  306.             //makepattern setpattern
  307.     0 0 i_w i_h rectfill
  308.     showpage
  309.     grestore
  310.     % create pattern with our extensions:
  311.     i_dict dup /ExportFile i_basename put
  312.     dup /Origin [ 0 0 transform ] put
  313.     i_m //makepattern
  314.     /i_shortcut false store
  315. %/makepatternE =
  316. } i_shortcutOverload
  317.  
  318. /writecurrentpattern
  319. {
  320.     currentcolor
  321.     (pat ) print
  322.     dup /Origin get
  323.     dup 0 get i_hscale div i_str cvs print ( ) print
  324.         1 get i_vscale div i_str cvs print ( ) print
  325.     /ExportFile get print
  326.     (\n) print
  327. } bind def
  328.  
  329. /writecurrentcmykcolor
  330. {
  331.     currentcmykcolor    % -> c m y k
  332.     (co )print
  333.     3 index i_str cvs print
  334.     ( ) print
  335.     2 index i_str cvs print
  336.     ( ) print
  337.     1 index i_str cvs print
  338.     ( ) print
  339.     i_str cvs print
  340.     ( ) print
  341.     pop pop pop
  342.     .currentopacityalpha    % a
  343.     i_str cvs print
  344.     (\n) print
  345. } bind def
  346.  
  347.  
  348. /writecurrentrgbcolor
  349. {
  350.     currentrgbcolor    % -> r g b
  351.     (corgb )print
  352.     2 index i_str cvs print
  353.     ( ) print
  354.     1 index i_str cvs print
  355.     ( ) print
  356.     i_str cvs print
  357.     ( ) print
  358.     pop pop
  359.     .currentopacityalpha    % a
  360.     i_str cvs print
  361.     (\n) print
  362. } bind def
  363.  
  364.  
  365. /writecurrentcolor
  366. {
  367.     currentcolorspace 0 get 
  368.  
  369.     % try to find a base colorspace first
  370.     dup    /Indexed eq
  371.     {
  372.         pop
  373.         currentcolorspace 1 get
  374.         dup type /arraytype eq { 0 get } if
  375.     } if
  376.  
  377.     dup dup /DeviceN eq exch /Separation eq or
  378.     {
  379.         pop
  380.         currentcolorspace 2 get
  381.         dup type /arraytype eq { 0 get } if
  382.     } if
  383.  
  384.     % now write values
  385.     dup /CIEBasedABC eq
  386.     { % this must be a hack....
  387.         gsave
  388.         currentcolor setrgbcolor
  389.         writecurrentrgbcolor
  390.         grestore
  391.     } {
  392.      dup /DeviceRGB eq
  393.     {
  394.         writecurrentrgbcolor
  395.     } {
  396.     dup dup /DeviceCMYK eq exch /DeviceGray eq or
  397.     {
  398.         writecurrentcmykcolor
  399.     } { 
  400.     dup /Pattern eq
  401.     {
  402.         writecurrentpattern
  403.     } {
  404.         % TODO: other CIE
  405.         writecurrentrgbcolor % will always be 0
  406.     }
  407.     ifelse } ifelse } ifelse } ifelse
  408.     pop
  409. } bind def
  410.  
  411. /writecurrentlinecap
  412. {
  413.     (lc ) print
  414.     currentlinecap i_str cvs print
  415.     (\n) print
  416. } bind def
  417.  
  418. /writecurrentlinejoin
  419. {
  420.     (lj ) print
  421.     currentlinejoin i_str cvs print
  422.     (\n) print
  423. } bind def
  424.  
  425. /writecurrentdash
  426. {
  427.     (ld ) print
  428.     currentdash 1 index length i_str cvs print ( ) print i_str cvs print ( ) print
  429.     0 1 2 index length 1 sub
  430.     {
  431.         1 index exch get 
  432.         storeMatrix
  433.         dup dup dup m_b abs mul exch m_d abs mul add  exch m_a abs mul add  exch m_c abs mul add  2 div  abs
  434.         i_hscale div
  435.         i_str cvs print ( ) print
  436.     } for
  437.     pop
  438.     (\n) print
  439. } bind def
  440.  
  441. /writecurrentlinewidth
  442. {
  443.     userdict begin
  444.     currentlinewidth    % w
  445.     storeMatrix
  446.  
  447.     % (wb + wd + wa + wc) / 2
  448. %??    
  449.     dup dup dup m_b abs mul exch m_d abs mul add  exch m_a abs mul add  exch m_c abs mul add  2 div  abs
  450.     i_hscale div
  451.     % transform (w,w) and take length
  452. %av-test:    dup dtransform i_vscale div dup mul exch i_hscale div dup mul add sqrt
  453.     (w ) print
  454.     i_str cvs print
  455.     (\n) print
  456.     end
  457. } bind def
  458.  
  459. /i_move    % x y
  460. {
  461.     userdict begin
  462.     (m\n) print
  463.     /currentY exch def
  464.     /currentX exch def
  465.     /beginX currentX def
  466.     /beginY currentY def
  467.     end
  468. } bind def
  469.  
  470. /i_line
  471. {
  472.     userdict begin
  473.     /y1 exch def
  474.     /x1 exch def
  475.  
  476.     % x x1 ne y y1 ne or
  477.     currentX x1 sub abs 0.001 gt  currentY y1 sub abs 0.001 gt or
  478.     {
  479.         (l ) print
  480.         currentX currentY matrix_x i_str cvs print
  481.         ( ) print
  482.         currentX currentY matrix_y i_str cvs print
  483.         ( ) print
  484.  
  485.         x1 y1 matrix_x i_str cvs print
  486.         ( ) print
  487.         x1 y1 matrix_y i_str cvs print
  488.         (\n) print
  489.         /currentX x1 def
  490.         /currentY y1 def
  491.     }if
  492.     end
  493. } bind def
  494.  
  495. /i_curve
  496. {
  497.     userdict begin
  498.     % x1 y1 x2 y2 x3 y3
  499.     (c ) print
  500.     currentX currentY matrix_x i_str cvs print
  501.     ( ) print
  502.     currentX currentY matrix_y i_str cvs print
  503.     ( ) print
  504.     5 index 5 index matrix_x i_str cvs print
  505.     ( ) print
  506.     5 index 5 index matrix_y i_str cvs print
  507.     ( ) print
  508.     3 index 3 index matrix_x i_str cvs print
  509.     ( ) print
  510.     3 index 3 index matrix_y i_str cvs print
  511.     ( ) print
  512.  
  513.     /currentY exch def
  514.     /currentX exch def
  515.  
  516.     currentX currentY matrix_x i_str cvs print
  517.     ( ) print
  518.     currentX currentY matrix_y i_str cvs print
  519.     (\n)print
  520.     pop pop pop pop
  521.     end
  522. } bind def
  523.  
  524. % modified: 18.10.96
  525. /i_close
  526. {
  527.     (cp\n) print
  528.     beginX beginY i_line
  529. } bind def
  530.  
  531. /storeMatrix
  532. {
  533.     userdict begin
  534.     matrix currentmatrix
  535.     dup 0 get /m_a exch def
  536.     dup 1 get /m_b exch def
  537.     dup 2 get /m_c exch def
  538.     dup 3 get /m_d exch def
  539.     dup 4 get /m_x exch def
  540.     5 get /m_y exch def
  541.     end
  542. } bind def
  543.  
  544. /pathClipAndClose % this is not nice: closes all open paths & flattens the path :-(
  545. {
  546.     clipsave 
  547.     clip                % combine clippath and path
  548.     newpath clippath    % copy (closed) clippath to path
  549.     cliprestore
  550. } bind def
  551.  
  552.  
  553. % find out if the point is within the clipping area
  554. /i_in_clip                    % x y  i_in_clip  bool
  555. {
  556.     gsave
  557.     newpath clippath
  558.     infill
  559.     grestore
  560. } bind def
  561.  
  562.  
  563. % find out if two points are within the clipping area
  564. /i_in_clip2                    % x1 y1 x2 y2 i_in_clip  bool1 bool2
  565. {
  566.     gsave
  567.     newpath clippath
  568.     infill                    % x1 y1 bool2
  569.     3 1 roll                % bool2 x1 y1
  570.     infill                    % bool2 bool1
  571.     exch
  572.     grestore
  573. } bind def
  574.  
  575.  
  576. /i_clip_move
  577. {
  578.     /beginY exch store 
  579.     /beginX exch store 
  580.     /currentX beginX store
  581.     /currentY beginY store
  582.     % test if within cliparea
  583.     currentX currentY i_in_clip
  584.     {
  585.         currentX currentY /moveto load
  586.     } if
  587. } bind def
  588.  
  589.  
  590. % find intersection with line x1,y1 -> x2,y2 with clip path.
  591. % x1,y2 is outside the clip area, x2, y2, x3, y3 inside
  592.  
  593. /i_find_clip_intersect        % x1 y1 x2 y2  i_find_clip_intersect  x3 y3
  594. {
  595.     3 index 2 index sub        % x1 y1 x2 y2 dx
  596.     3 index 2 index sub        % x1 y1 x2 y2 dx dy
  597.     gsave
  598.     newpath clippath
  599.     {
  600.         2 div exch 2 div exch                % half interval
  601.         2 copy abs 0.01 lt exch abs 0.01 lt and
  602.             { exit } if                        % done
  603.         2 copy 4 index add exch                % x1 y1 x2 y2 dx dy (y2+dy) dx
  604.                5 index add exch                % x1 y1 x2 y2 dx dy (x2+dx) (y2+dy)
  605. %        /Intersect = 7 index = 6 index = 5 index = 4 index = 3 index = 2 index = 1 index = 0 index = 
  606.         2 copy infill
  607.         {                                    % replace x2,y2
  608.             6 -2 roll pop pop
  609.             4 2 roll
  610.         } {
  611.             8 -2 roll pop pop                % replace x1,y1
  612.             6 2 roll
  613.         } ifelse
  614.     } loop
  615.     grestore
  616.     6 -2 roll                                % return x2,y2
  617.     4 { pop } repeat
  618. } bind def
  619.  
  620. /i_clip_line
  621. {
  622.     /endY exch store
  623.     /endX exch store
  624.     currentX currentY endX endY i_in_clip2 
  625.     { % end in
  626.         {  
  627.             % both in. just draw it. FIXME check if line leaves cliparea
  628.             endX endY /lineto load
  629.         } {
  630.             % current not in
  631.             % find new current point
  632.             currentX currentY endX endY i_find_clip_intersect 
  633.             /moveto load
  634.             endX endY /lineto load
  635.         } ifelse
  636.     } { % end not in
  637.         {   % current in
  638.             % find new endpoint
  639.             endX endY currentX currentY i_find_clip_intersect 
  640.             /lineto load
  641.         } {
  642.             % both not in
  643.             % try to find a point within cliparea
  644.             currentX currentY endX endY i_find_clip_intersect
  645.             2 copy i_in_clip
  646.             {
  647.                 % yeah
  648.                 /moveto load
  649.                 % now find point from other end
  650.                 endX endY currentX currentY i_find_clip_intersect
  651.                 /lineto load
  652.             } {
  653.                 pop pop
  654.             } ifelse
  655.         } ifelse
  656.     } ifelse
  657.     /currentX endX store
  658.     /currentY endY store
  659. } bind def
  660.  
  661.  
  662. /pathClipForStroke 
  663. {
  664.     % only lines
  665.     flattenpath
  666.     % create a userpath from currentpath
  667.     userdict begin
  668.     /beginX 0 def /beginY 0 def
  669.     /currentX 0 def /currentY 0 def
  670.     /endX 0 def /endY 0 def
  671.     systemdict begin                            % some EPS redefine moveto & Co :-(
  672.     [
  673.             { i_clip_move }                        % remember last move
  674.             { i_clip_line }                        % clip lines individually
  675.             { 6 {pop} repeat /OOPS = }            % won't happen
  676.             { beginX beginY i_clip_line }        % close with line
  677.         pathforall
  678.     ] cvx 
  679. %    dup ==
  680.     newpath % uappend % userpaths SUCK!
  681.     end end
  682.     exec
  683. } bind def
  684.  
  685. /rectfill
  686. {
  687.     userdict begin
  688.     (n\n)print            % start polygon
  689.     writecurrentcolor
  690.     writecurrentlinewidth
  691.     writecurrentlinecap
  692.     writecurrentlinejoin
  693.     writecurrentdash
  694.     storeMatrix
  695.  
  696.     % x y width height
  697.     dup type /arraytype ne
  698.     {
  699.         /hr exch def
  700.         /wr exch def
  701.         /yr exch def
  702.         /xr exch def
  703.         xr yr i_move
  704.         xr wr add yr i_line
  705.         xr wr add yr hr add i_line
  706.         xr yr hr add i_line
  707.         xr yr i_line
  708.     }
  709.     % numarray
  710.     % numstring
  711.     {
  712.         /ar exch def
  713.         0 4 ar length 1 sub
  714.         {
  715.             /n exch def
  716.             ar n get /xr exch def
  717.             ar n 1 add get /yr exch def
  718.             ar n 2 add get /wr exch def
  719.             ar n 3 add get /hr exch def
  720.             xr yr i_move
  721.             xr wr add yr i_line
  722.             xr wr add yr hr add i_line
  723.             xr yr hr add i_line
  724.             xr yr i_line
  725.         } for
  726.     }ifelse
  727.  
  728.     (f\n)print            % close polygon
  729.     end
  730. } i_shortcutOverload
  731.  
  732. /rectstroke
  733. {
  734.     userdict begin
  735.     (n\n)print            % start rect
  736.     writecurrentcolor
  737.     writecurrentlinewidth
  738.     writecurrentlinecap
  739.     writecurrentlinejoin
  740.     writecurrentdash
  741.     storeMatrix
  742.  
  743.     % x y width height
  744.     dup type dup /arraytype ne exch /stringtype ne and
  745.     {
  746.         /hr exch def
  747.         /wr exch def
  748.         /yr exch def
  749.         /xr exch def
  750.         xr yr i_move
  751.         xr wr add yr i_line
  752.         xr wr add yr hr add i_line
  753.         xr yr hr add i_line
  754.         xr yr i_line
  755.     }
  756.     % numarray
  757.     % numstring
  758.     {
  759.         /ar exch def
  760.         0 4 ar length 1 sub
  761.         {
  762.             /n exch def
  763.             ar n get /xr exch def
  764.             ar n 1 add get /yr exch def
  765.             ar n 2 add get /wr exch def
  766.             ar n 3 add get /hr exch def
  767.             xr yr i_move
  768.             xr wr add yr i_line
  769.             xr wr add yr hr add i_line
  770.             xr yr hr add i_line
  771.             xr yr i_line
  772.         } for
  773.     }ifelse
  774.     (n\n)print            % stroke rect
  775.     end
  776. } i_shortcutOverload
  777.  
  778. /stroke
  779. {
  780.     (n\n) print
  781.     writecurrentcolor
  782.     writecurrentlinewidth
  783.     writecurrentlinecap
  784.     writecurrentlinejoin
  785.     writecurrentdash
  786.     clipCnt 1 eq 
  787.         { pathClipForStroke } if
  788.     storeMatrix
  789.  
  790.     {i_move} {i_line} {i_curve} {i_close} pathforall
  791.     (s\n)print            % stroke path
  792.     newpath
  793. } i_shortcutOverload
  794.  
  795. /eofill
  796. {
  797.     (n\n) print            % start polygon
  798.     writecurrentcolor    % write color
  799.     writecurrentlinewidth
  800.     writecurrentlinecap
  801.     writecurrentlinejoin
  802.     writecurrentdash
  803.     clipCnt 1 eq
  804.         { pathClipAndClose } if
  805.     storeMatrix            % take transformation, scaling, rotation from PostScript
  806.     {i_move} {i_line} {i_curve} {i_close} pathforall
  807.     (f\n)print            % close polygon
  808.  
  809.     newpath                % clear stack
  810. } i_shortcutOverload
  811.  
  812. /fill 
  813. {
  814.     (fill-winding\n) print
  815.     eofill 
  816.     (fill-evenodd\n) print
  817. } i_shortcutOverload
  818.  
  819. /clip
  820. {
  821.     userdict begin
  822.     (n\n)print            % start clip polygon
  823.  
  824. % FIXME: pathClipAndClose first?
  825.  
  826.     storeMatrix            % take transformation, scaling, rotation from PostScript
  827.     {i_move} {i_line} {i_curve} {i_close} pathforall
  828.  
  829.     (ci\n)print            % close clip polygon begin path
  830.                         % we have to close the path!!
  831.     clip
  832.     /clipCnt 1 def
  833.     newpath                % clear stack
  834.     end
  835. } i_shortcutOverload
  836.  
  837. % we don't clip
  838. % because this doesn't work for flattening text (show, charpath) with NeXT PostScript Code
  839. /rectclip
  840. {
  841.     % let Scribus decide what to do with ci; was: pop pop pop pop
  842.     userdict begin
  843.     (n\n)print            % start clip polygon
  844.  
  845.     storeMatrix            % take transformation, scaling, rotation from PostScript
  846.     dup type dup /arraytype ne exch /stringtype ne and
  847.     {
  848.         4 copy
  849.         /i_h exch def
  850.         /i_w exch def
  851.         /i_y exch def
  852.         /i_x exch def
  853.         i_x i_y i_move
  854.         i_x i_w add i_y i_line
  855.         i_x i_w add i_y i_h add i_line
  856.         i_x i_y i_h add i_line
  857.     } {
  858.         % array or string
  859.         0 4 dup length 1 sub 
  860.         {
  861.             1 index 1 index get /i_x exch def
  862.             1 add
  863.             1 index 1 index get /i_y exch def
  864.             1 add
  865.             1 index 1 index get /i_w exch def
  866.             1 add
  867.             1 index 1 index get /i_y exch def
  868.             i_x i_y i_move
  869.             i_x i_w add i_y i_line
  870.             i_x i_w add i_y i_h add i_line
  871.             i_x i_y i_h add i_line
  872.         } for
  873.     } ifelse
  874.     
  875.     (ci\n)print            % close clip polygon begin path
  876.                         % we have to close the path!!
  877.     rectclip
  878.     /clipCnt 1 def
  879.     newpath                % clear stack
  880.     end
  881. } i_shortcutOverload
  882.  
  883.  
  884. %    Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
  885. % This software is provided AS-IS with no warranty, either express or
  886. % implied.
  887. % This software is distributed under license and may not be copied,
  888. % modified or distributed except as expressly authorized under the terms
  889. % of the license contained in the file LICENSE in this distribution.
  890. % For more information about licensing, please refer to
  891. % http://www.ghostscript.com/licensing/. For information on
  892. % commercial licensing, go to http://www.artifex.com/licensing/ or
  893. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  894. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  895.  
  896. % $Id: import.prolog,v 1.4.2.18.2.1 2006/11/23 13:45:38 fschmid Exp $
  897. % traceimg.ps
  898. % Trace the data supplied to the 'image' operator.
  899.  
  900. % This code currently handles only the (Level 2) dictionary form of image,
  901. % with a single data source and 8-bit pixels.
  902.  
  903. % changed for Scribus image import by Andreas Vox, 2006-2-21
  904. % added support for colorimage and other image variant
  905.  
  906. /i_image            % <dict> i_image -
  907. {
  908. /i_image =
  909.     begin 
  910.         /i_left Width Height mul Decode length 2 idiv mul BitsPerComponent mul 8 idiv dup /i_size exch store store 
  911.         /i_dict currentdict store 
  912.         /i_nsources 1 store 
  913.         /i_source 0 store 
  914.         /i_datasource currentdict /DataSource get store
  915.         currentdict /MultipleDataSources known not 
  916.             { /MultipleDataSources false def } if
  917.         MultipleDataSources
  918.         {
  919.             /i_nsources  DataSource length store
  920.             /i_datasource DataSource 0 get store
  921.         } if
  922.     end
  923.     storeMatrix 
  924.     i_dict /ImageMatrix get matrix invertmatrix matrix currentmatrix matrix concatmatrix /i_m exch def
  925.     i_dict /Width get  0 i_m dtransform dup mul exch dup mul add sqrt /i_w exch def 
  926.     0 i_dict /Height get i_m dtransform dup mul exch dup mul add sqrt /i_h exch def
  927.     0  0 i_m transform  /i_y exch def /i_x exch def 
  928.     i_dict /Width get i_dict /Height get i_m transform
  929.     /i_hflip -1 def /i_vflip 1 def 
  930.     dup i_y le { /i_y exch def } { pop /i_vflip -1 def } ifelse
  931.     dup i_x le { /i_x exch def } { pop /i_hflip  1 def } ifelse
  932.     0 i_dict /Height get i_m dtransform atan
  933.     /i_angle exch def
  934.     (.dat) i_exportfilename
  935.         (im ) print                                                % im x y w h angle ...
  936.         i_x i_hscale div i_str cvs print ( ) print
  937.         i_y i_vscale div i_str cvs print ( ) print
  938.         i_w i_hscale div i_str cvs print ( ) print
  939.         i_h i_vscale div i_str cvs print ( ) print
  940.         i_angle i_str cvs print ( ) print
  941.         i_dict /Width get  i_str cvs print ( ) print            % ... hpix vpix ...
  942.         i_dict /Height get i_str cvs print ( ) print
  943.         currentcolorspace 0 get /DeviceRGB eq
  944.             { (tiff24nc ) print } 
  945.         { currentcolorspace 0 get /DeviceCMYK eq
  946.             { (psdcmyk ) print } 
  947.         { currentcolorspace 0 get /DeviceGray eq
  948.             { (tiffgray ) print } 
  949.             { (tiff32nc ) print }
  950.         ifelse } ifelse } ifelse
  951.         dup  (.tif) concatenate print (\n) print flush            % ... dev filename
  952.         (.dat) concatenate (w) file /i_file exch store            % temp file
  953.     currentcolorspace ==write ( setcolorspace\n) =write
  954.     (<<\n) =write 
  955.     i_dict { exch
  956.           dup /DataSource eq 
  957.             { pop pop (/DataSource currentfile\n) =write }
  958.           {
  959.             dup /ImageMatrix eq 
  960.                 { pop pop (/ImageMatrix [) =write
  961.                     i_hflip ==write ( 0 0 ) =write i_vflip ==write 
  962.                     ( ) =write 
  963.                     i_hflip 0 lt { i_dict /Width get } { 0 } ifelse ==write 
  964.                     ( ) =write 
  965.                     i_vflip 0 lt { i_dict /Height get} { 0 } ifelse ==write 
  966.                     (]\n) =write }
  967.                 { ==write ( ) =write ==write (\n) =write }
  968.             ifelse 
  969.           } ifelse 
  970.         } forall 
  971.     (>>\nimage\n) =write i_file flushfile
  972.  
  973.     { %loop
  974.       i_left 0 le 
  975.       { 
  976.         i_source 1 add /i_source exch def
  977.         i_source i_nsources ge { exit } if
  978.         i_dict /DataSource get i_source get /i_datasource exch def
  979.         /i_left i_size def
  980.       } if
  981.       /i_datasource load exec
  982.       dup type /filetype eq
  983.        { i_buf 0 i_left 32 .min getinterval readstring pop
  984.        } if
  985.       dup i_file exch writestring 
  986.       i_left exch length sub /i_left exch def
  987.     } loop
  988.     i_file flushfile
  989. /i_imageE =
  990.  } bind def
  991.  
  992. /colorimage
  993. {
  994. /colorimage =
  995.     % width height bits/sample matrix datasource0..n-1 multi ncomp
  996.     /tmpN exch def
  997.     /tmpMulti exch def
  998.     tmpMulti
  999.     {
  1000.         /tmpN load array astore
  1001.     } if
  1002.     /tmpN load 6 add dict
  1003.     dup 7 -1 roll /Width exch put 
  1004.     dup 6 -1 roll /Height exch put 
  1005.     dup 5 -1 roll /BitsPerComponent exch put 
  1006.     dup 4 -1 roll /ImageMatrix exch put 
  1007.     dup 3 -1 roll /DataSource exch put 
  1008.     tmpMulti
  1009.     {
  1010.         dup /MultipleDataSources true put
  1011.     } if
  1012.     dup /ImageType 1 put
  1013.     gsave
  1014.     /tmpN load
  1015.         dup 1 eq
  1016.         {
  1017.             1 index /Decode [0 1] /Decode put
  1018.             /DeviceGray setcolorspace
  1019.         } if
  1020.         dup 3 eq
  1021.         {
  1022.             1 index /Decode [0 1 0 1 0 1] put
  1023.             /DeviceRGB setcolorspace
  1024.         } if
  1025.         dup 4 eq
  1026.         {
  1027.             1 index /Decode [0 1 0 1 0 1 0 1]  put
  1028.             /DeviceCMYK setcolorspace
  1029.         } if
  1030.     pop
  1031.     i_image
  1032.     grestore
  1033. /colorimageE =
  1034. } i_shortcutOverload
  1035.  
  1036. /image {
  1037. /image =
  1038.     gsave
  1039.     dup type /dicttype ne 
  1040.     {
  1041.         % width height bits/sample matrix datasource
  1042.         7 dict
  1043.         dup 7 -1 roll /Width exch put
  1044.         dup 6 -1 roll /Height exch put
  1045.         dup 5 -1 roll /BitsPerComponent  exch put
  1046.         dup 4 -1 roll /ImageMatrix exch put
  1047.         dup 3 -1 roll /DataSource exch put
  1048.         dup 1 /ImageType exch put
  1049.         dup [0 1] /Decode exch put
  1050.         /DeviceGray setcolorspace
  1051.     } if
  1052.     i_image
  1053.     grestore
  1054. /imageE =
  1055. } i_shortcutOverload
  1056.  
  1057. /imagemask
  1058. {
  1059. /imagemask =
  1060.     writecurrentcolor
  1061.     (mask\n) print
  1062.     gsave
  1063.     dup type /dicttype ne 
  1064.     {
  1065.         % width height pol matrix datasource
  1066.         7 dict
  1067.         dup 7 -1 roll /Width exch put
  1068.         dup 6 -1 roll /Height exch put
  1069.         dup 5 -1 roll { [0 1] } { [1 0] } ifelse /Decode exch put
  1070.         dup 4 -1 roll /ImageMatrix exch put
  1071.         dup 3 -1 roll /DataSource exch put
  1072.     } if
  1073.     dup 1 /ImageType exch put
  1074.     dup 1 /BitsPerComponent exch put
  1075.     /DeviceGray setcolorspace
  1076.     i_image
  1077.     grestore
  1078. /imagemaskE =
  1079. } i_shortcutOverload
  1080.  
  1081.  
  1082. % declare some global vars
  1083.  
  1084. /i_left 0 def
  1085. /i_size 0 def
  1086. /i_dict null def
  1087. /i_buf 32 string def
  1088. /i_nsources 1 def
  1089. /i_source 0 def
  1090. /i_datasource { (x) } def
  1091. /i_file null def
  1092. /i_filecount 1 def
  1093.  
  1094. %%%% End of traceimage code
  1095.  
  1096.  
  1097. /stateArray 500 array def
  1098. /stateTop 0 def
  1099. /gsave
  1100. {
  1101.     userdict begin
  1102. %    (gs\n) print
  1103.     stateArray stateTop gstate currentgstate put
  1104.     /stateTop stateTop 1 add def
  1105.     end
  1106. } i_shortcutOverload
  1107.  
  1108. /grestore
  1109. {
  1110.     userdict begin
  1111.     stateTop 1 lt
  1112.     {
  1113.     }
  1114.     {
  1115. %        (gr\n) print
  1116.         stateArray stateTop 1 sub get setgstate
  1117.         /stateTop stateTop 1 sub def
  1118.         stateArray stateTop 0 put
  1119.     }ifelse
  1120.     end
  1121. } i_shortcutOverload
  1122.  
  1123. % a bind def of the show operator doesn't work,
  1124. % so this is our way to get a charpath entry for flattening text
  1125. /root_charpath
  1126. {
  1127.     charpath
  1128. } bind def
  1129.  
  1130. /i_kerningI
  1131. {
  1132.     exch 1 getinterval stringwidth
  1133. } bind def
  1134.  
  1135. % find kerning value
  1136. /i_kerningII        % index string   i_kerning   dx dy 
  1137. {
  1138.     % stringwidth( [n..n+1] ) - stringwidth( [n+1] )
  1139.     /i_pstring exch def
  1140.     /i_pindex exch def
  1141.     i_pstring i_pindex 2 getinterval stringwidth exch    % y2 x2
  1142.     i_pstring i_pindex 1 add 1 getinterval stringwidth        % y2 x2 x1 y1
  1143.     4 1 roll sub                                            % y1 y2 (x2-x1)
  1144.     3 1 roll exch sub                                        % (x2-x1) (y2-y1)
  1145. } bind def
  1146.  
  1147.  
  1148. /i_kerningIII        % index string   i_kerning   dx dy 
  1149. {
  1150.     % stringwidth( [n..n+1] ) - stringwidth( [n+1] )
  1151.     /i_pstring exch def
  1152.     /i_pindex exch def
  1153.     i_pstring i_pindex 2 getinterval (l) exch concatenate stringwidth exch    % y2 x2
  1154.     i_pstring i_pindex 1 add 1 getinterval (l) exch concatenate stringwidth        % y2 x2 x1 y1
  1155.     4 1 roll sub                                            % y1 y2 (x2-x1)
  1156.     3 1 roll exch sub                                        % (x2-x1) (y2-y1)
  1157. } bind def
  1158.  
  1159. /i_kerning /i_kerningII load def
  1160.  
  1161. /show % string show -
  1162.     userdict begin
  1163.     storeMatrix
  1164.     currentfont /FontName known
  1165.     % stack: string
  1166.     {
  1167.         currentpoint /ycur exch def /xcur exch def
  1168.         currentpoint    % x y
  1169.         newpath
  1170.         /clipCnt 0 def
  1171.         moveto
  1172.         /completeString exch def
  1173.         % we process each char separately to get smaller paths
  1174.         0 1 completeString length 1 sub
  1175.         {
  1176.             (n\n)print            % start polygon
  1177.             writecurrentcolor    % write color
  1178.             storeMatrix
  1179.             dup completeString length 1 sub eq 
  1180.             { dup completeString exch 1 getinterval stringwidth } 
  1181.             { dup completeString i_kerning } ifelse 
  1182.             /curwidthy exch def /curwidthx exch def
  1183.             completeString exch 1 getinterval dup /curstr exch def
  1184.             false root_charpath
  1185.             {i_move} {i_line} {i_curve} {i_close} pathforall
  1186.             (f\n)print            % close polygon
  1187.             newpath
  1188.             curwidthx xcur add curwidthy ycur add moveto
  1189.             currentpoint /ycur exch def /xcur exch def
  1190.             newpath            % clear graphic stack
  1191.             xcur ycur moveto
  1192.         } for
  1193.         currentpoint    % x y
  1194.         newpath                % clear graphic stack (and current point)
  1195.         moveto
  1196.     } {
  1197.         pop        % string
  1198.     } ifelse
  1199.     end
  1200. } i_shortcutOverload
  1201.  
  1202. /ashow
  1203. {
  1204.     % ax ay string
  1205.     exch /ydist exch def
  1206.     exch /xdist exch def
  1207.     userdict begin
  1208.     storeMatrix
  1209.     currentfont /FontName known
  1210.     % stack: string
  1211.     {
  1212.         currentpoint /ycur exch def /xcur exch def
  1213.         currentpoint    % x y
  1214.         newpath
  1215.         /clipCnt 0 def
  1216.         moveto
  1217.         /completeString exch def
  1218.         % we process each char separately to get smaller paths
  1219.         0 1 completeString length 1 sub
  1220.         {
  1221.             (n\n)print            % start polygon
  1222.             writecurrentcolor    % write color
  1223.             storeMatrix
  1224.             dup completeString length 1 sub eq 
  1225.             { dup completeString exch 1 getinterval stringwidth } 
  1226.             { dup completeString i_kerning } ifelse 
  1227.             /curwidthy exch def /curwidthx exch def
  1228.             completeString exch 1 getinterval dup /curstr exch def 
  1229.             false root_charpath
  1230.             {i_move} {i_line} {i_curve} {i_close} pathforall
  1231.             (f\n)print            % close polygon
  1232.             newpath
  1233.             curwidthx xcur add curwidthy ycur add
  1234.             exch xdist add exch ydist add moveto
  1235.             currentpoint /ycur exch def /xcur exch def
  1236.             newpath            % clear graphic stack
  1237.             xcur ycur moveto
  1238.         } for
  1239.         currentpoint    % x y
  1240.         newpath                % clear graphic stack (and current point)
  1241.         moveto
  1242.     } {
  1243.         pop
  1244.     } ifelse
  1245.     end
  1246. } i_shortcutOverload
  1247.  
  1248. /awidthshow        % cx cy char ax ay string
  1249. {
  1250.     % ax ay string
  1251.     exch /ydist exch def
  1252.     exch /xdist exch def
  1253.     % cx cy char string
  1254.     exch /char exch def
  1255.     exch /cydist exch def
  1256.     exch /cxdist exch def
  1257.     userdict begin
  1258.     storeMatrix
  1259.     currentfont /FontName known
  1260.     % stack: string
  1261.     {
  1262.         currentpoint /ycur exch def /xcur exch def
  1263.         currentpoint    % x y
  1264.         newpath
  1265.         /clipCnt 0 def
  1266.         moveto
  1267.         /completeString exch def
  1268.         % we process each char separately to get smaller paths
  1269.         0 1 completeString length 1 sub
  1270.         {
  1271.             (n\n)print            % start polygon
  1272.             writecurrentcolor    % write color
  1273.             storeMatrix
  1274.             dup completeString length 1 sub eq 
  1275.             { dup completeString exch 1 getinterval stringwidth } 
  1276.             { dup completeString i_kerning } ifelse 
  1277.             /curwidthy exch def /curwidthx exch def
  1278.             completeString exch 1 getinterval dup /curstr exch def 
  1279.             false root_charpath
  1280.             {i_move} {i_line} {i_curve} {i_close} pathforall
  1281.             (f\n)print            % close polygon
  1282.             newpath
  1283.             curwidthx xcur add curwidthy ycur add
  1284.             exch xdist add exch ydist add moveto
  1285.             curstr 0 get char eq
  1286.             {
  1287.                 currentpoint exch cxdist add exch cydist add moveto
  1288.             } if
  1289.             currentpoint /ycur exch def /xcur exch def
  1290.             newpath            % clear graphic stack
  1291.             xcur ycur moveto
  1292.         } for
  1293.         currentpoint    % x y
  1294.         newpath                % clear graphic stack (and current point)
  1295.         moveto
  1296.     } {
  1297.         pop
  1298.     } ifelse
  1299.     end
  1300. } i_shortcutOverload
  1301.  
  1302. /widthshow    % cx cy char string
  1303. {
  1304.     0 exch
  1305.     0 exch
  1306.     awidthshow
  1307. } bind def
  1308.  
  1309. /cshow    % proc string
  1310. {
  1311.     exch pop
  1312.     show
  1313. } i_shortcutOverload
  1314.  
  1315. /kshow    % proc string
  1316. {
  1317.     dup length 1 sub 
  1318.     dup 0 ne
  1319.     {
  1320.         1 index 0 1 getinterval
  1321.         show
  1322.         1 sub
  1323.         dup 0 ne
  1324.         {
  1325.             1 add
  1326.             1 exch 1 exch
  1327.             {
  1328.                 dup 1 sub
  1329.                 2 index exch get
  1330.                 2 index 2 index get
  1331.                 4 index exec
  1332.                 1 index exch 1 getinterval
  1333.                 show
  1334.             } for
  1335.         } if
  1336.     }
  1337.     {
  1338.         pop dup show
  1339.     } ifelse
  1340.     pop pop
  1341. } i_shortcutOverload
  1342.  
  1343. /xshow    % string array
  1344. {
  1345.     pop %FIXME
  1346.     show
  1347. } i_shortcutOverload
  1348.  
  1349. /xyshow    % string array
  1350. {
  1351.     pop %FIXME
  1352.     show
  1353. } i_shortcutOverload
  1354.  
  1355. /yshow    % string array
  1356. {
  1357.     pop %FIXME
  1358.     show
  1359. } i_shortcutOverload
  1360.  
  1361. /i_reencode % newfontname reencodevector origfontdict -> i_reencode -> newfontdict
  1362. {
  1363.     userdict begin
  1364.  dup begin dup maxlength dict begin
  1365.   { 1 index /FID ne {def} {pop pop} ifelse
  1366.   } forall
  1367.   /Encoding exch def
  1368.   currentdict
  1369.   end end
  1370.   definefont
  1371.     end
  1372. } bind def
  1373.  
  1374. /glyphshow {
  1375.     save % So can reclaim VM from reencoding
  1376.     currentfont /Encoding get dup length array copy dup 0 5 -1 roll put
  1377.     /GlyphShowTempFont exch currentfont i_reencode
  1378.     setfont
  1379.     (\000) show 
  1380.     restore
  1381. } i_shortcutOverload
  1382.  
  1383. /showpage
  1384. {
  1385.     (sp\n) print
  1386. } i_shortcutOverload
  1387.  
  1388.