home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 September / PCWK996.iso / sharewar / 95 / narzedzi / ambra / ambr32a1.exe / FILE / ARCHIVE.Z / ACROBAT / VIEWER32.EXE / PSPROCSET / 5 < prev    next >
Text File  |  1996-02-22  |  14KB  |  613 lines

  1. %%BeginFile: pdf.prc
  2. %%Copyright: Copyright 1987-1996 Adobe Systems Incorporated. All Rights Reserved.
  3. % general operators for PDF
  4.  
  5. % initialization
  6. /initialize {            % - initialize -
  7.     PDF begin
  8.     PDFVars begin
  9.     newpath
  10. } bd
  11. /terminate {            % - terminate -
  12.     end
  13.     end
  14. } bd
  15.  
  16. % path construction operators
  17. Level2? StartLoad
  18. {    /m/moveto ld
  19.     /l/lineto ld
  20.     /c/curveto ld
  21.     /setSA/setstrokeadjust ld
  22.     /setOP/setoverprint ld
  23. } EndLoad
  24.  
  25. Level2? not StartLoad
  26. {    % In L1, simulate stroke adjustment before each moveto,
  27.     % lineto, and curveto, but only if stroke adjustment is on.
  28.     % (It's set via 'gs' operator.) Default at top of page: it's on.
  29.     /pl {            % x y => x y
  30.         transform
  31.         0.25 sub round 0.25 add exch
  32.         0.25 sub round 0.25 add exch
  33.         itransform
  34.     } bd
  35.     /m { _sa? { pl } if moveto } bd
  36.     /l { _sa? { pl } if lineto } bd
  37.     /c { _sa? { pl } if curveto } bd
  38.     /setSA { /_sa? xdd } bd
  39.     /setOP/pop ld        % Ignore setoverprint in L1.
  40. } EndLoad
  41.  
  42. % x2 y2 x3 y3 v -
  43. /v { currentpoint 6 2 roll c } bd
  44.  
  45. % x1 y1 x2 y2 y -
  46. /y { 2 copy c } bd
  47.  
  48. /h/closepath ld
  49.  
  50. % graphic state operators
  51. /d/setdash ld                
  52. /j/setlinejoin ld
  53. /J/setlinecap ld
  54. /M/setmiterlimit ld
  55. /w/setlinewidth ld
  56. /cf    currentflat def            % default flatness
  57. /i {                        % flatness i -
  58.     dup 0 eq { pop cf } if    % use default flatness if arg is 0
  59.     setflat
  60. } bd
  61.  
  62. % path painting operators
  63.  
  64. % init _lp - force setting of color
  65. /ilp { /_lp /none dd } bd
  66.  
  67. % set color before fill or stroke
  68. /sfc {                        % setfillcolor
  69.     _lp /fill ne {            % if fill not set
  70.         _sfcs                % set colorspace
  71.         _sfc                % set color
  72.         /_lp /fill dd        % fill now set
  73.     } if
  74. } bd
  75. /ssc {                        % setstrokecolor
  76.     _lp /stroke ne {        % if stroke not set
  77.         _sscs                % set colorspace
  78.         _ssc                % set color
  79.         /_lp /stroke dd        % stroke now set
  80.     } if
  81. } bd
  82.  
  83. % endpath w/o painting
  84. /n {                % - n -
  85.     _doClip 1 ge {
  86.         _doClip 1 eq { clip } { eoclip } ifelse
  87.         /_doClip 0 dd
  88.     } if 
  89.     newpath
  90. } bd
  91.  
  92. % fill
  93. /f {                % - f -
  94.     _doClip 1 ge
  95.         {
  96.             gsave sfc fill grestore 
  97.             _doClip 1 eq { clip } { eoclip } ifelse
  98.             newpath
  99.             ilp 
  100.             /_doClip 0 dd
  101.         }
  102.         { sfc fill }
  103.     ifelse
  104. } bd
  105.  
  106. % eofill
  107. /f*    {                % - f* -
  108.     _doClip 1 ge
  109.         {
  110.             gsave sfc eofill grestore 
  111.             _doClip 1 eq { clip } { eoclip } ifelse
  112.             newpath
  113.             ilp
  114.             /_doClip 0 dd
  115.         }
  116.         { sfc eofill }
  117.     ifelse
  118. } bd
  119.  
  120. % stroke
  121. /S {                % - S -
  122.     _doClip 1 ge
  123.         {
  124.             gsave ssc stroke grestore 
  125.             _doClip 1 eq { clip } { eoclip } ifelse
  126.             newpath
  127.             ilp
  128.             /_doClip 0 dd
  129.         }
  130.         { ssc stroke }
  131.     ifelse
  132. } bd
  133. /s { h S } bd        % - s -
  134.  
  135. % fill, stroke, and clip
  136. /B {                % - B -
  137.     _doClip dup 1 ge     % f clears _doClip
  138.         gsave f grestore 
  139.         {
  140.             gsave S grestore 
  141.             1 eq { clip } { eoclip } ifelse
  142.             newpath
  143.             ilp
  144.             /_doClip 0 dd
  145.         }
  146.         { pop S }
  147.     ifelse
  148. } bd
  149. /b { h B } bd        % - b -
  150.  
  151. % fill, stroke, and eoclip
  152. /B* {                % - B -
  153.     _doClip dup 1 ge     % f* clears _doClip
  154.         gsave f* grestore 
  155.         {
  156.             gsave S grestore 
  157.             1 eq { clip } { eoclip } ifelse
  158.             newpath
  159.             ilp
  160.             /_doClip 0 dd
  161.         }
  162.         { pop S }
  163.     ifelse
  164. } bd
  165. /b* { h B* } bd        % - b* -
  166.  
  167. % remember to clip
  168. /W { /_doClip 1 dd } bd
  169. /W* { /_doClip 2 dd } bd
  170.  
  171. % gsave/grestore
  172. /q/save ld
  173. /Q { restore ilp } bd
  174.  
  175. % Categories and Resources for PDF 1.2
  176. % All we use are "define' and "find". For Level 1, we simply store these in a
  177. % global dictionary, _categories. This code is not currently used for the /Font category.
  178.  
  179. Level2? StartLoad
  180. {    /defineRes/defineresource ld
  181.     /findRes/findresource ld    
  182.     currentglobal
  183.     true setglobal
  184.     [/Function /ExtGState /Form]
  185.     { /Generic /Category findresource dup length dict copy /Category defineresource pop }
  186.     forall
  187.     setglobal
  188. } EndLoad
  189.  
  190. Level2? not StartLoad
  191. {   /AlmostFull?    % dict => boolean
  192.     { dup maxlength exch length sub 2 le
  193.     } bind def
  194.  
  195.     /Expand    % dict factor => dict'
  196.     { 1 index maxlength mul cvi dict    % create a bigger dictionary
  197.       dup begin exch { def } forall end    % copy all the elements 
  198.     } bind def
  199.  
  200.     % Avoid 'dictfull' errors by expanding dictionaries as needed.
  201.     /xput % dict key val => dict' ("Expanding put")
  202.     { 3 2 roll
  203.         dup 3 index known not
  204.         { dup AlmostFull? { 1.5 Expand } if
  205.         } if
  206.         dup 4 2 roll put
  207.     } bind def
  208.  
  209.     /defineRes    % resourceName resource categoryName => resource
  210.     { _categories 1 index known not
  211.         { /_categories _categories 2 index 10 dict xput store
  212.         } if
  213.       _categories exch 2 copy get 5 -1 roll 4 index xput put
  214.     } bind def
  215. } EndLoad
  216.  
  217. % Set up the colorspace that will be installed the next time we fill.
  218. /cs                                        % name cs -
  219. {    
  220.     dup where { pop load } if            % load if not standard name
  221.     dup /_fcs xdd                        % save fill colorspace
  222.     % Now set up array to save color components.
  223.     ucs                                    % Get the underlying colorspace.
  224.     _cpcf exch get                        % Get the component vector.
  225.     /_fc xdd                            % Store that in _fc.
  226.     /_fp { } dd                            % No 'fill pattern' argument.
  227. } bd
  228.  
  229. % Set up the colorspace that will be installed the next time we stroke.
  230. /CS 
  231.     dup where { pop load } if            % load if not standard name
  232.     dup /_scs xdd ucs _cpcs exch get /_sc xdd /_sp { } dd
  233. } bd
  234.  
  235. % Get the underlying colorspace, so we know how many color components
  236. % to pass to setcolor. 
  237. % The colorspace [/Pattern base] can be used for both
  238. % colored patterns, which take no color values (just the pattern), and uncolored patterns,
  239. % which take 1, 3, or 4 color values PLUS the pattern. scn/SCN
  240. % stores the pattern in _fp (_sp), which is pushed onto the stack before the
  241. % call to setcolor. sc/SC set it to the null procedure.
  242. %
  243. % Since we support [/Pattern [/Indexed ...]] and
  244. % [/Pattern [/Separation ...]], it's easiest just to make ucs recursive.
  245.  
  246. /ucs {                                    % colorspace => name
  247.     dup type /arraytype eq
  248.       { dup 0 get
  249.         dup /Indexed eq                    % [/Indexed ...]
  250.           { pop 0 get }
  251.           { /Pattern eq
  252.               { dup length 2 eq            % [/Pattern colorspace]
  253.                   { 1 get ucs }            % Recurse.
  254.                   { 0 get }                % [/Pattern]: 1 component
  255.                 ifelse }
  256.               { 0 get }                    % [/Separation ...]: 1 component
  257.             ifelse }
  258.         ifelse }
  259.     if }
  260. bd
  261.  
  262. /_cpcf  % components per color (fill).  colorspace => components-vector
  263.     15 dict dup begin
  264.         /DefaultGray _f1 def
  265.       /DeviceGray _f1 def
  266.       /DefaultRGB _f3 def
  267.       /DeviceRGB _f3 def
  268.       /DeviceCMYK _f4 def
  269.       /CalGray _f1 def
  270.       /CalRGB _f3 def
  271.       /CalCMYK _f4 def
  272.       /Lab _f3 def
  273.       /Pattern _f0 def                        % colored
  274.       /Indexed _f1 def
  275.       /Separation _f1 def
  276.       /CIEBasedA _f1 def
  277.       /CIEBasedABC _f3 def
  278.     end
  279. dd
  280.  
  281. /_cpcs  % components per color (stroke).  colorspace => components-vector
  282.     15 dict dup begin
  283.       /DefaultGray _s1 def
  284.       /DeviceGray _s1 def
  285.       /DefaultRGB _s3 def
  286.       /DeviceRGB _s3 def
  287.       /DeviceCMYK _s4 def
  288.       /CalGray _s1 def
  289.       /CalRGB _s3 def
  290.       /CalCMYK _s4 def
  291.       /Lab _s3 def
  292.       /Pattern _s0 def                        % colored
  293.       /Indexed _s1 def
  294.       /Separation _s1 def
  295.       /CIEBasedA _s1 def
  296.       /CIEBasedABC _s3 def
  297.     end
  298. dd
  299.  
  300.  
  301. Level2? not StartLoad {                    % L1 defs
  302.  
  303.     % L1 setcolor fns set color space as well, so _sfcs does nothing
  304.     /_sfcs { } dd
  305.     /_sscs { } dd
  306.     /_sfc { _fc L1setcolor } dd
  307.     /_ssc { _sc L1setcolor } dd
  308.     /L1setcolor {                            %: color-components-array => -
  309.         aload length
  310.         % From the number of colors, we can tell which operator to use.
  311.         % Uncolored patterns will use their underlying color space.
  312.         dup 0 eq
  313.             { pop .5 setgray }                % Colored pattern
  314.             { dup 1 eq
  315.                 { pop setgray }                % DeviceGray, Indexed, Separation
  316.                 { 3 eq
  317.                     { setrgbcolor }            % DeviceRGB, CalRGB, Lab
  318.                     { setcmykcolor }        % DeviceCMYK, CalCMYK
  319.                 ifelse }
  320.             ifelse }
  321.         ifelse
  322.     } bind dd
  323.     
  324.     % set render intent                        % name ri -
  325.     /ri/pop ld
  326.     % makePat                                % patDict mtx => patDict
  327.     /makePat/pop ld        % We use the dictionary only to check its PaintType.
  328.     /sethalftone                            % Emulate for L1
  329.     {                                        % halftoneDict => -
  330.         begin
  331.         HalftoneType 1 eq
  332.             { Frequency Angle /SpotFunction load }
  333.             { 0 0 currentdict }
  334.         ifelse
  335.         setscreen
  336.       end
  337.     } bind def
  338.     
  339. } EndLoad
  340.  
  341. Level2? StartLoad
  342. {
  343.     % L2 defs
  344.  
  345.     /_sfcs
  346.     {
  347.         _fcs setcolorspace
  348.     } bind dd    % Set the colorspace for fill.
  349.     /_sscs
  350.     {
  351.         _scs setcolorspace
  352.     } bind dd    % Set the colorspace for stroke
  353.     /_sfc    % Set the fill color.
  354.     {
  355.         _fc aload pop    % Push the color components ...
  356.         _fp    % ... and maybe the fill pattern
  357.         setcolor    % ... then set the color.
  358.     } bind dd
  359.     /_ssc
  360.     {
  361.         _sc aload pop _sp setcolor
  362.     } bind dd    % Set the color for stroke.
  363.  
  364.     % set render intent                        % name ri -
  365.     /ri
  366.     {
  367.         /findcolorrendering isdefined?
  368.         {
  369.             findcolorrendering pop
  370.             dup /ColorRendering resourcestatus
  371.             {
  372.                 pop pop
  373.                 /ColorRendering findresource
  374.                 setcolorrendering
  375.             }
  376.             {
  377.                 pop
  378.             } ifelse
  379.         }
  380.         {
  381.             pop
  382.         } ifelse
  383.     } bd
  384.     /makePat /makepattern ld
  385. } EndLoad
  386.  
  387. % set fill or stroke color
  388. /sc        % set fill color                % c1 ... cn sc -
  389. {
  390.     _fc astore pop
  391.     ilp
  392. } bd
  393. /SC        % set stroke color                % c1 ... cn SC -
  394. {
  395.     _sc astore pop
  396.     ilp
  397. } bd
  398.  
  399. % set fill color for patterns.
  400. % If the value on the top of the stack is not a name, then this
  401. % is equivalent to 'sc'. Otherwise, the name refers to a pattern.
  402. % If the current colorspace is /Pattern, then 'name' must be a 
  403. % colored pattern, but if it's [/Pattern base], then we have to 
  404. % examine the pattern to see whether it's colored. If it's a colored
  405. % pattern, we use _f0 for the "components." 
  406.  
  407. /scn {                                    % c1 ... cn name scn -
  408.     dup type /nametype eq
  409.       { /Pattern findRes                % Get the value.
  410.           dup /_fpat xdd                % Store that in _fpat
  411.           /_fp { _fpat } dd                % Redefine _fp to push _fpat.
  412.           /PaintType get 1 eq            % Colored?
  413.           { /_fc _f0 dd ilp }            % Yes. Set _fc to a 0-length array.
  414.           { /_fc cpcf _fcs ucs get dd    % No. Recompute _fc ...
  415.               sc }                        % ... and store c1..cn there.
  416.           ifelse }                        
  417.       { sc }
  418.     ifelse
  419. } bd
  420.  
  421. /SCN {                                    % c1 ... cn name SCN -
  422.     dup type /nametype eq
  423.       { /Pattern findRes                % Get the value.
  424.           dup /_spat xdd                % Store that in _spat
  425.           /_sp { _spat } dd                % Redefine _sp to push _spat.
  426.           /PaintType get 1 eq            % Colored?
  427.           { /_sc _s0 dd ilp }            % Yes. Set _sc to a 0-length array.
  428.           { /_sc cpc _scs ucs get dd    % No. Recompute _sc ...
  429.               SC }                        % ... and store c1..cn there.
  430.           ifelse }                        
  431.       { SC }
  432.     ifelse
  433. } bd
  434.  
  435. % color operators
  436. /g  { /DefaultGray cs sc } bd
  437. /rg { /DefaultRGB cs sc } bd
  438. /k  { /DeviceCMYK cs sc } bd
  439. /G  { /DefaultGray CS SC } bd
  440. /RG { /DefaultRGB CS SC } bd
  441. /K  { /DeviceCMYK CS SC } bd
  442.  
  443. % a b c d x y cm -
  444. /cm { _mtx astore concat } bd
  445.  
  446. % x y width height re - 
  447. % Add the rectangle to the current path
  448. /re {
  449.     4 2 roll m            % x y m
  450.     1 index 0 rlineto    % w 0 rlineto
  451.     0 exch rlineto        % 0 h rlineto
  452.     neg 0 rlineto        % -w 0 rlineto
  453.     h
  454. } bd
  455.  
  456. % x y width height RC - 
  457. /RC/rectclip ld
  458.  
  459. % formdict EF -
  460. /EF/execform ld
  461.  
  462. % exec-string PS -
  463. /PS { cvx exec } bd
  464.  
  465. % initialize gstate once per page
  466. /initgs {
  467.     /DefaultGray where
  468.         { pop }
  469.         { /DefaultGray /DeviceGray dd }
  470.     ifelse
  471.     /DefaultRGB where
  472.         { pop }
  473.         { /DefaultRGB /DeviceRGB dd }
  474.     ifelse
  475.     0 g 0 G
  476.     [] 0 d 0 j 0 J 10 M 1 w
  477.     true setSA
  478. } bd
  479.  
  480. % The predefined spot functions
  481. 17 dict dup begin
  482.       /CosineDot
  483.       { 180 mul cos exch 180 mul cos add 2 div } bd
  484.  
  485.       /Cross
  486.       { abs exch abs 2 copy gt { exch } if pop neg } bd
  487.       
  488.       /Diamond                % Photoshop's version
  489.       { abs exch abs 2 copy add .75 le
  490.           { dup mul exch dup mul add 1 exch sub }
  491.           { 2 copy add 1.23 le
  492.               { .85 mul add 1 exch sub }
  493.               { 1 sub dup mul exch 1 sub dup mul add 1 sub }
  494.               ifelse }
  495.           ifelse } bd
  496.       
  497.       /DoubleDot
  498.       { 2 { 360 mul sin 2 div exch } repeat add } bd
  499.       
  500.       /Ellipse
  501.       { abs exch abs 2 copy 3 mul exch 4 mul add 3 sub dup 0 lt
  502.           { pop dup mul exch .75 div dup mul add 4 div
  503.               1 exch sub }
  504.           { dup 1 gt
  505.               {pop 1 exch sub dup mul exch 1 exch sub
  506.                   .75 div dup mul add 4 div 1 sub }
  507.               { .5 exch sub exch pop exch pop }
  508.               ifelse }
  509.           ifelse } bd
  510.       
  511.       /EllipseB
  512.       { dup 5 mul 8 div mul exch dup mul exch add sqrt 1 exch sub } bd
  513.       
  514.       /EllipseC
  515.       { dup .5 gt { 1 exch sub } if
  516.           dup .25 ge
  517.           { .5 exch sub 4 mul dup mul 1 sub }
  518.           { 4 mul dup mul 1 exch sub }
  519.           ifelse
  520.           exch
  521.           dup .5 gt { 1 exch sub } if
  522.           dup .25 ge
  523.           { .5 exch sub 4 mul dup mul 1 sub }
  524.           { 4 mul dup mul 1 exch sub }
  525.           ifelse
  526.           add -2 div } bd
  527.       
  528.       /InvertedDoubleDot
  529.       { 2 { 360 mul sin 2 div exch } repeat add neg } bd
  530.       
  531.       /InvertedEllipseA 
  532.       { dup mul .9 mul exch dup mul add 1 sub } bd
  533.       
  534.       /InvertedSimpleDot
  535.       { dup mul exch dup mul add 1 sub } bd
  536.  
  537.       /Line 
  538.       { exch pop abs neg } bd
  539.       
  540.       /LineY                % called "Line" in FrameMaker 5
  541.       { pop } bd
  542.  
  543.       /Rhomboid
  544.       { abs exch abs 0.9 mul add 2 div } bd
  545.       % 0.8 in FrameMaker 5 
  546.       
  547.       /Round 
  548.       { abs exch abs 2 copy add 1 le
  549.           { dup mul exch dup mul add 1 exch sub }
  550.           { 1 sub dup mul exch 1 sub dup mul add 1 sub }
  551.           ifelse } bd
  552.       
  553.       /SimpleDot
  554.       { dup mul exch dup mul add 1 exch sub } bd
  555.       
  556.       /Square
  557.       { abs exch abs 2 copy lt { exch } if pop neg } bd
  558.     end
  559.     { /Function defineRes pop } forall
  560.  
  561. /Identity {} /Function defineRes pop
  562.  
  563. Level2? StartLoad {
  564.     /gs 
  565.     {
  566.         begin
  567.             /SA here { setstrokeadjust } if
  568.             /OP here { setoverprint } if
  569.             /BG here { setblackgeneration } if
  570.             /UCR here { setundercolorremoval } if
  571.             /HT here { sethalftone } if
  572.             /sethalftonephase isdefined? { /HTP here { sethalftonephase } if } if
  573.             /TR here 
  574.             {    % A procedure or an array of 4 procedures. 
  575.                 dup xcheck { settransfer } { setcolortransfer } ifelse
  576.             } if
  577.         end
  578.     } bd
  579. } EndLoad
  580.  
  581. Level2? not StartLoad {
  582.     /gs
  583.     {
  584.         begin
  585.             /SA here { /_sa? xdd } if
  586.             /HT here 
  587.             {
  588.                 begin
  589.                     HalftoneType 1 eq 
  590.                     { Frequency Angle /SpotFunction load setscreen }
  591.                     if
  592.                 end
  593.             } if
  594.             /TR here { dup type xcheck { settransfer } if } if
  595.         end
  596.     } bd
  597. } EndLoad
  598.  
  599. % 'truncate2' and 'int' are used in code that interpolates from sampled values
  600. % in function resources.
  601.  
  602. /truncate2 { 2 copy idiv 3 1 roll mod } bd
  603.  
  604. /int {  % x x0 x1 y0 y1 => y
  605.     % On the line defined by (x0,y0) and (x1,y1), interpolate a
  606.     % value for y, given x.
  607.     dup 2 index sub 3 index 5 index sub div 6 -2 roll sub mul
  608.     exch pop add exch pop
  609. } bd
  610.  
  611. %%EndFile
  612.