Reputation: 15
stream
{ 360 mul sin
2 div
exch 360 mul sin
2 div
add
}
endstream
Can someone please explain this syntax to me?
Upvotes: 1
Views: 746
Reputation: 90213
This doesn't look like PDF to me:
stream
and endstream
are PDF keywords, yes.
But the rest rather looks like PostScript.
So stream
and endstream
could also be PostScript variables or functions, defined elsewhere (before) in the same code...
As PostScript, the code means:
{
and }
are just separators that structure the code into blocks360 mul sin
: multiply by 360 (multiply what? => the value that's topmost on the stack), compute the sinus value for the result, and put this as topmost on the stack.2 div
: divide the topmost value on the stack by 2.exch 360 mul sin
: swap the 2 topmost items on the stack, multiply the item that's now topmost by 360, compute the sinus of it and put it back on the stack. 2 div
: divide the topmost value on the stack by 2.add
: add the 2 topmost values on the stack.Update:
Ouch!
I had completely forgotten about the details of the (very limited) PostScript function objects which the PDF spec allows inside PDF documents. These represent self-contained and static numerical transformations.
So my above explanation of the PostScript code as a calculator function is still valid, and it looks to me like describing a 'spot function' for a halftone screen. (However, stream
and endstream
in this context of course do keep their original meanings as PDF keywords, and the curly braces {
and }
are required to enclose the function definition.)
Since the PDF spec for these PostScript function objects does not allow the use of arrays, variables, names or strings, but only integers, reals and booleans as values, the processing of these code segments doesn't require a fully fledged PostScript interpreter, and this statement in the spec:
"PDF is not a programming language, and a PDF file is not a program."
does still apply and makes still the PDF language very different from PostScript (which is a programming language, and PS files are programs).
Keeping in mind, that PostScript is a stack-based language, and understanding its code by thinking of a pocket calculator that uses 'reverse Polish notation' conventions will help you wrapping your mind around this topic...
Upvotes: 3
Reputation: 3184
Its a postscript program which executes on the raw data to provide the end values. You will need a Postscript parser to handle it
Upvotes: 2