%\% To print this file, concatenate (join together) a copy of Qs and this file, %\% and send the combined file to a PostScript printer or PostScript %\% interpreter. %PS% QSdict /PagStr (Quikscript Layout Mechanism ) put PE %PN%%BD%%SZ,16%%CL% Quikscript Layout Mechanism %SZ%%LT%%P% If you want to tailor Quikscript, modifying how existing layout marks work or creating new layout marks, you will need to understand how the Quikscript machinery processes layout marks. %P% Quikscript contains a table%L,.5%%T,20% Kwrd %L,.5%an array of arrays. Each array within Kwrd contains three items: %ST,0,10,15,25,160% 1. %CO,2,4%The keyword string, eg. (FN), identifying the keyword.%NR% 2. %CO,2,4%The keyword procedure, which will be run to implement the keyword.%L% The text following the keyword string is put on top of the stack before the procedure is run. That is, a layout mark %%FN,Cou%% will match a keyword string of (FN), and (,Cou) will be put on the stack to be available to the procedure. A layout mark %%FN%% will also match (FN), and the empty string () will be put on the stack before running the procedure.%NR% 3. %CO,2,4%The keyword flags, indicating how the keyword is to be processed and when the procedure is to be run. The flags are built as bitwise-OR of the following codes: %NR,3% 1 %CO%line-breaking%L% This indicates that the text already received should be output immediately, as following text will not influence its layout. Obvious examples include %%L%% or %%P%%; more subtle would be %%PS, which could have any type of effect on the output; because the effect of PostScript code is unpredictable as far as Quikscript is concerned, we are forced to assume the worst. Keywords that move the current point to a defined place will always be line-breaking.%NR,3% 2 %CO%output-producing%L% This keyword will itself put output on the page which will have to be measured. The implication of setting this bit is firstly that the procedure can only be executed when Quikscript is ready to put it on the page, and secondly, that there will be an entry in the MeasureK procedure to determine the amount of space on the page that output of this keyword will occupy. An example of this will be %%C,code%% or %%_%%. However, %%VL would not be classed as output-producing, even though it will cause a line to be drawn eventually, because the line produced will not affect the placement of preceding or following text. %L,.5% "Output-producing" and "line-breaking" are mutually exclusive.%NR,3% 4 %CO%start-recording%L% This keyword turns off normal processing of the input stream, instead recording the incoming text in a buffer (RecBuf). Any layout marks in the input stream will be written to RecBuf without being processed, unless they are of type "end-recording".%NR,3% 8 %CO%end-recording%L% This keyword will process the text in RecBuf in some way, and will decrement the count of the number of "start-recording" keywords so far met. If this count reaches zero, normal processing of the input stream will resume. %L,.5% "End-recording" and "start-recording" are mutually exclusive. %NR%%CO,2,4% It is possible for a keyword to have none of these flags set. Such keywords must be capable of being executed when text is being measured and again when it is being output without risk of side-effects from either the premature or second execution. %ET%%P% Quikscript processes all layout marks until %P,8,-8,-.5% 1) text to be output is encountered, or%P% 2) an output-producing keyword is encountered, or%P% 3) a start-recording keyword is encountered. %P,0,0,0% In cases 1) or 2), the input stream is now processed word at a time, each word being measured to see if it will fit on the current line. The accumulated text is output when the output line is filled, or when a line-breaking or start-recording layout mark is encountered. A line-breaking mark will cause the input text to be processed again keyword by keyword. %P% In case 3), the input stream is recorded to RecBuf, being checked for layout marks that have start-recording or end-recording status. Any other layout marks are simply included with the text in RecBuf. RecBuf is cleared when an end-recording layout mark causes the count of recording marks to be decremented to zero. It is possible by this scheme to record text for multiple purposes, but only one buffer is used and the text is recorded from the first start-recording mark, for use when an end-recording mark is found. %P% At the start of Quikscript execution, it places a number and a mark on the stack. At various stages during its execution, other information is put on the stack beneath the mark, with the number changed accordingly. This means of recording internal state information should not be interfered with in any PostScript included within a Quikscript document, for the effects will be unpredictable. %P% When embedded PostScript is executed, the current point is recorded beneath the mark, so if the embedded PostScript finishes with no current point existing, it can be recovered from the stack. %P% Graham Freeman