0

I am a beginner for post script and just started working on post script. I want to create a post script procedure which I can use for shading effect for post script.This shading can have more then 2 colors so I need to define stitching function of type 3.

I am thinking of defining a procedure for function2 and later I can use this procedure in defining the type 3 function.

below is what I tried...

/Function2 {
/b2 exch def 
/g2 exch def 
/r2 exch def 
/b exch def 
/g exch def 
/r exch def
/FunctionType 2
/Domain [ 0 1 ]
/C0 [ r g b ]
/C1 [ r2 g2 b2 ]
/N 1
} def

/Function3
{
   /num exch def 
   /FunctionType 3
   /Domain [ 0 1 ]
   /Functions [1 1 num { pop  Function2 } for  ]
   /Bounds [ 1 1 num-1 { pop   } for  ]
   /Encode [ 1 1 num { pop 0 1 } for ]
} def

{
    /ShadingType 3
    /ColorSpace /DeviceRGB
    /Coords [ 200 200 0 200 200 100 ]
    /Extend [ true true ]
    /Function Function3
}
shfill

Issue I am facing is how to read bound variables from the stack. I am not sure this will work or not. please check and let me know the issues in that.

archit
  • 185
  • 4
  • 12

1 Answers1

2

I'm not really sure what you are asking for here. Perhaps you could clarify the question. You don't 'read bound variables from the stack', stack objects are just that, objects on the stack.

This:

   **/Bounds [ 1 1 num-1 { pop   } for  ]**

looks incorrect to me 'num-1' will be immediately evaluated, and you don;t seem to have defined a name object '/num-1', so will throw an undefined error I think.

Also, of course, the '**' constructs will similarly throw an error.

You have defined the functions as 'procedures' (in PostScript terminology actually executable arrays), whereas PostScript functions are required to be dictionaries, so what you have here won't work. That is you have used '{' and '}' when you should use '<<' and '>>', in simplistic terms.

Function dictionaries don't take arguments on the stack If you are truly just starting out in PostScript, functions and shadings are probably the worst possible place to start, since they are rather complex.

Here is a working example shading using both a type 2 and a type 3 function, for your perusal:

%!PS-Adobe-3.0

gsave
0.480 setlinewidth
1 setlinecap
1 setlinejoin
0.302 0.302 0.302 setrgbcolor
/stop_function
<<
    /FunctionType 2
    /Domain[0 1]
    /C0 [1 0 0]
    /C1 [0 1 0]
    /N 1
>> def
/RepFunction
<<
    /FunctionType 3
    /Domain [ -81 1 ]
    /Functions [ 82 {stop_function} repeat ]
    /Bounds [ -80 1 0 {} for ]
    /Encode [ -81 1 0 { pop 0 1 } for ]
>> def
<<
    /PatternType 2
    /Shading
    <<
      /ShadingType 3
      /ColorSpace [/DeviceRGB]
      /Extend [false false]
      /Coords [-1300.8 -468 979.2 60 504 7.2]
      /Function
      <<
        /FunctionType 3
        /Domain [0 1]
        /Bounds []
        /Encode[-80 1]
        /Functions [RepFunction]
      >>
    >> 
>>
matrix makepattern setpattern
12.000 528.000 moveto
84.000 528.000 lineto
84.000 456.000 lineto
12.000 456.000 lineto
closepath
gsave
fill
grestore
0.302 0.302 0.302 setrgbcolor
stroke
grestore

showpage
KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thanks for the reply. Here what I am looking is passing some external values of color and coordinates to shading. Here I am getting color and coordinates from some third party API and want to draw those in post script. I want to define a general procedure which can be called for coming set of inputs. whatever you have given is not generic. – archit Oct 19 '16 at 09:23
  • please explain -80 -81 82 also. – archit Oct 19 '16 at 09:29
  • Seriously ? If you can't follow this then I suggest you tackle something a little more basic and return to the problem when you have a deeper understanding of PostScript. Obviously I didn't give you a generic solution, for a number of reasons. One of them being that you didn't give (and still haven't) a complete description of the problem. – KenS Oct 19 '16 at 11:57
  • Sorry for not able to explain myself. Problem I am trying to solve is conversion of SVG images in to post script. SVG images are coming from user and I want to convert these images in to post script. After parsing the SVG image I am having all the useful information like color, coordinates, paths, transformation. Now I want to make a post script using this information. This information can vary so I needed a generic procedure for shading which can be applied for all the SVG images. can you give me some good online tutorial where I can start learning post script. – archit Oct 20 '16 at 06:02
  • You need; The PostScript Language Reference Manual (PLRM, Red Book) , the PostScript Language Tutorial (Green Book) and the PostScript Cookbook (Blue Book) all available on the Adobe web site. In addition I recommend Acumen Training's Acumen Journal (Google for this). I don't know enough about SVG to know what you mean by 'SVG images' nor whether its even possible to create an implementation of all possible SVG descriptions as shadings, I kind of doubt that you can write a single generic shading which will manage all of them though. – KenS Oct 20 '16 at 09:56