[comp.lang.postscript] BeginSetup/EndSetup

rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (05/10/89)

Howdy!  I'm playing with the document structuring conventions, and I
want to be sure I understand something.  Is it true that, assuming a
well-structured PostScript file and a correctly behaving server, that
the following file

%!PS-Adobe-2.0...
...
%%BeginSetup
% we possibly change the CTM here, maybe even stash it away
% for later use
6 array currentmatrix print flush % this is the *last* thing in setup
%%EndSetup
%%Page 1 1
6 array currentmatrix print flush % this is the *first* thing in page
%%Trailer

will show two *different* matrices?  Is it safe to `save' the CTM
during the `Setup' so it can be used in the actual pages themselves?

Thanks!

-tom

greid@adobe.com (Glenn Reid) (05/12/89)

In article <9059@polya.Stanford.EDU> rokicki@polya.Stanford.EDU (Tomas G. Rokicki) writes:
>Howdy!  I'm playing with the document structuring conventions, and I
>want to be sure I understand something.  Is it true that, assuming a
>well-structured PostScript file and a correctly behaving server, that
>the following file
>
>%!PS-Adobe-2.0...
>...
>%%BeginSetup
>% we possibly change the CTM here, maybe even stash it away
>% for later use
>6 array currentmatrix print flush % this is the *last* thing in setup
>%%EndSetup
>%%Page 1 1
>6 array currentmatrix print flush % this is the *first* thing in page
>%%Trailer
>
>will show two *different* matrices?  Is it safe to `save' the CTM
>during the `Setup' so it can be used in the actual pages themselves?

I'm not entirely sure I understand the way you've presented this
question, but I'll try to answer it anyway.  Your main question reads
like this:  "Is it true that ... the following file ... will show two
different matrices?"  My first answer is "NO."  Given that the only
thing between the two calls to "currentmatrix" is a few comments, the
matrices should be identical.  But the way in which individual pages
use the setup code is up to you.  The only requirement is that it must
not depend on the order in which the pages are executed, or even depend
on all the pages being present at all.  Servers can strip out pages,
rearrange them, etc.

However, you were asking about the comments and the structure.
Basically, it works like this:

%!PS-Adobe-2.1
%%BeginProcSet
	% You can make any definitions you want here, but cannot
	% change the state of the interpreter.
%%EndProcSet
%%EndProlog
%%BeginSetup
	% You can change the state of the interpreter here, and
	% provide any job-specific setup like reencoding fonts.
	% Bear in mind that YOU are responsible for any state
	% you set here and how it is used by each page.  The
	% structuring conventions just guarantee that it will
	% always be executed first, before any of the pages.  The
	% structuring conventions to not dictate *which* page
	% will be the one to execute after setup.  It could be
	% page 1, page 4, or page 15, depending on page selection
	% and reordering that may be done by the server.
%%EndSetup
%%Page: "label" m
	% any code can go here.  It may rely on prologue definitions
	% made before the %%EndProlog comment, and it may rely on
	% state set up in the Setup section ONLY IF it also leaves
	% that state set at the end of the page.  This is because
	% the pages must not be interdependent, and any of them may
	% be executed in any order.
	% If a matrix representing the current matrix is stored into
	% a variable during setup, it is reasonable to use this value
	% with "setmatrix" to establish the coordinate system at the
	% beginning of each page.
%%Page: "label" n
	% This is exactly the same as page "m"
%%Trailer
	% The structuring conventions guarantee only that this code
	% will be executed last, after the final page.  It is
	% appropriate here to remove your dictionaries from the
	% dictionary stack and to make sure you've left nothing
	% on the operand stack.
%%EOF
	% If this is the end of job and an end-of-file would normally
	% appear here, this comment may be used to indicate end-of-
	% file in a transport-mechanism-independent manner.


I hope this helps. I think you basically have it right.

Glenn Reid
Adobe Systems

rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (05/12/89)

Just a note to thank Glenn for the outstanding explanation of the
document structuring conventions.  (Why isn't it explained that
concisely in the actual Adobe document?)  Anyway, I think Adobe
(in the form of Glenn) is providing excellent support for
PostScript.  Thanks!

geof@apolling (Geof Cooper) (05/17/89)

In article <825@adobe.UUCP> greid@adobe.COM (Glenn Reid) writes:
>In article <9059@polya.Stanford.EDU> rokicki@polya.Stanford.EDU (Tomas G. Rokicki) writes:
>>%!PS-Adobe-2.0...
>>...
>>%%BeginSetup
>>% we possibly change the CTM here, maybe even stash it away
>>% for later use
>>6 array currentmatrix print flush % this is the *last* thing in setup
>>%%EndSetup
>>%%Page 1 1
>>6 array currentmatrix print flush % this is the *first* thing in page
>>%%Trailer
>>

I need to ask another question... were you thinking of storing your
preamble in the printer using exitserver, then just sending the
document part later?  If so, what you specify is a bit dangerous, since
the conditions under which the document might print might have a
different matrix from when the preamble was executed.  This would be
the case on some printers if the paper tray changed.  It would also be
the case on some products if the printing resolution changed between
PostScript files.

- Geof Cooper
  IMAGEN (is a subset of QMS)

rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (05/17/89)

>>>...
>>>%%BeginSetup
>>>% we possibly change the CTM here, maybe even stash it away
>>>% for later use

> I need to ask another question... were you thinking of storing your
> preamble in the printer using exitserver, then just sending the
> document part later?

No, I agree that might be stretching things.  As it turns out, I've
decided not to do it that way after all.  Though it is perfectly
legal and works just fine on printers, it fails in an environment
such as DPS* where scaling and zooming might modify the default CTM
at unpredictable ways.

*By DPS I mean Display PostScript running an interactive view program
that repeatedly executes the Page portion at different resolutions
under user control.

As non-printer environments for PostScript become more common I
imagine such issues may well become important and may lead to some
additional recommendations on what is the `suggested' format of
PS files.

-tom

greid@adobe.com (Glenn Reid) (05/17/89)

The attributions are a little mixed up.  The following code segment
was the one originally posted by Tomas Rokicki, not by Glenn Reid.
In any case, I'll address the question.  The caution that Geof Cooper
provides in this message is a good one.  That is why it is important to
follow the structuring conventions correctly, not just to put the
comments into the file.

In article <3780@imagen.UUCP> geof@apolling (Geof Cooper) writes:
>In article <825@adobe.UUCP> greid@adobe.COM (Glenn Reid) writes:
>>In article <edited> rokicki@polya.Stanford.EDU (Tomas G. Rokicki) writes:
>>>%!PS-Adobe-2.0...
>>>...
>>>%%BeginSetup
>>>% we possibly change the CTM here, maybe even stash it away
>>>% for later use
>>>6 array currentmatrix print flush % this is the *last* thing in setup
>>>%%EndSetup
>>>%%Page 1 1
>>>6 array currentmatrix print flush % this is the *first* thing in page
>>>%%Trailer
>>>
>
>I need to ask another question... were you thinking of storing your
>preamble in the printer using exitserver, then just sending the
>document part later?  If so, what you specify is a bit dangerous, since
>the conditions under which the document might print might have a
>different matrix from when the preamble was executed.  This would be
>the case on some printers if the paper tray changed.  It would also be
>the case on some products if the printing resolution changed between
>PostScript files.
>
>- Geof Cooper
>  IMAGEN (is a subset of QMS)

The "preamble" or "prologue" does NOT include the setup section.  That
is the point of the BeginSetup / EndSetup comments.  They follow the
%%EndProlog comment, which is the correct place to break the file if
you are going to download the prologue permanently.

The Setup section is simply guaranteed to precede the pages, but it is
not part of the prologue.  Here again is the crux of what I said
before, just so we can stay un-confused in our cross-referencing (I've
added comments to show where the document can be cut:

%!PS-Adobe-2.1
%%BeginProcSet
	% You can make any definitions you want here, but cannot
	% change the state of the interpreter.  This is the "prologue",
	% which can be permanently downloaded or made available once
	% for a large number of individual document bodies.
%%EndProcSet
%%EndProlog
% ------------- cut here for permanent download of the prologue ----------
%%BeginSetup
	% You can change the state of the interpreter here, and
	% provide any job-specific setup like reencoding fonts.
	% Bear in mind that YOU are responsible for any state
	% you set here and how it is used by each page.  The
	% structuring conventions just guarantee that it will
	% always be executed first, before any of the pages.  The
	% structuring conventions to not dictate *which* page
	% will be the one to execute after setup.  It could be
	% page 1, page 4, or page 15, depending on page selection
	% and reordering that may be done by the server.  This section
	% is part of the individual document body, and must be
	% repeated with each document.  It is not part of the prologue.
%%EndSetup
% ------------- cut here for page reordering or subsetting ---------------
%%Page: "label" m
	% any code can go here.  It may rely on prologue definitions
	% made before the %%EndProlog comment, and it may rely on
	% state set up in the Setup section ONLY IF it also leaves
	% that state set at the end of the page.  This is because
	% the pages must not be interdependent, and any of them may
	% be executed in any order.
	% If a matrix representing the current matrix is stored into
	% a variable during setup, it is reasonable to use this value
	% with "setmatrix" to establish the coordinate system at the
	% beginning of each page.
%%Page: "label" n
	% This is exactly the same as page "m"
%%Trailer
	% The structuring conventions guarantee only that this code
	% will be executed last, after the final page.  It is
	% appropriate here to remove your dictionaries from the
	% dictionary stack and to make sure you've left nothing
	% on the operand stack.
%%EOF
	% If this is the end of job and an end-of-file would normally
	% appear here, this comment may be used to indicate end-of-
	% file in a transport-mechanism-independent manner.


Glenn Reid
Adobe Systems