IPOutputImpl.mesa
An "operator interface" for writing Interpress masters.
See the Introduction to Interpress, chapter 7.
Last edited by:
Doug Wyatt, March 12, 1984 1:21:33 pm PST
DIRECTORY
FS USING [StreamOpen],
Imager USING [Context, Create],
IO USING [STREAM],
IPBasic USING [ImagerVariable, Op, StrokeEnd],
IPWriter USING [Close, Create, PutHeader, PutIdentifier, PutInt, PutOp, PutReal, PutString, Writer],
IPOutput USING [],
Rope USING [Index, ROPE, Size, Substr];
IPOutputImpl: CEDAR PROGRAM
IMPORTS FS, Imager, IPWriter, Rope
EXPORTS IPOutput
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Writer: TYPE ~ IPWriter.Writer;
Op: TYPE ~ IPBasic.Op;
Master: TYPE ~ REF MasterRep;
MasterRep:
PUBLIC
TYPE ~
RECORD[
writer: Writer,
page: INT ← 0,
stack: LIST OF Op ← NIL,
imager: Imager.Context ← NIL
];
Error: PUBLIC ERROR[explanation: ROPE] ~ CODE;
Narrow:
PUBLIC
PROC[x:
REF]
RETURNS[Master] ~ {
RETURN[
NARROW[x]] };
BeginMaster:
PUBLIC
PROC[fileName:
ROPE, encoding:
ATOM ←
NIL]
RETURNS[Master] ~ {
stream: STREAM ~ FS.StreamOpen[fileName, $create];
RETURN[BeginMasterFromStream[stream, encoding]];
};
BeginMasterFromStream:
PUBLIC
PROC[stream:
STREAM, encoding:
ATOM ←
NIL]
RETURNS[Master] ~ {
self: Master ~ NEW[MasterRep ← []];
IF encoding=NIL THEN encoding ← $Xerox;
self.writer ← IPWriter.Create[stream, encoding];
self.writer.PutHeader[];
self.writer.PutOp[$beginBlock];
RETURN[self];
};
Begin:
PROC[self: Master, op: Op] ~ {
top: LIST OF Op ~ self.stack;
self.stack ← CONS[op, top];
};
End:
PROC[self: Master, op: Op] ~ {
top: LIST OF Op ~ self.stack;
IF top.first=op THEN self.stack ← top.rest
ELSE ERROR Error["Bodies improperly nested."];
};
BeginPreamble:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
IF self.page#0 THEN ERROR Error["BeginPreamble misplaced."];
Begin[self, $nil];
writer.PutOp[$beginBody];
};
EndPreamble:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
End[self, $nil];
writer.PutOp[$endBody];
self.page ← 1;
};
BeginPage:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
IF self.page=0 THEN ERROR Error["BeginPage misplaced."];
Begin[self, $nil];
writer.PutOp[$beginBody];
};
EndPage:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
End[self, $nil];
writer.PutOp[$endBody];
self.page ← self.page+1;
};
EndMaster:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$endBlock];
writer.Close[];
};
BeginBodyOp:
PROC[self: Master, op: Op] ~ {
writer: Writer ~ self.writer;
Begin[self, op];
writer.PutOp[op];
writer.PutOp[$beginBody];
};
EndBodyOp:
PROC[self: Master, op: Op] ~ {
writer: Writer ~ self.writer;
End[self, op];
writer.PutOp[$endBody];
};
Display:
PUBLIC
PROC[self: Master, action:
PROC[Imager.Context]] ~ {
IF self.imager=NIL THEN self.imager ← Imager.Create[$Interpress, self];
action[self.imager];
};
PutOp:
PUBLIC
PROC[self: Master, op: Op] ~ {
writer: Writer ~ self.writer;
writer.PutOp[op];
};
PutInt:
PUBLIC
PROC[self: Master, int:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[int];
};
PutReal:
PUBLIC
PROC[self: Master, real:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[real];
};
PutIdentifier:
PUBLIC
PROC[self: Master, identifier:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutIdentifier[identifier];
};
PutName:
PUBLIC
PROC[self: Master, name:
ROPE] ~ {
writer: Writer ~ self.writer;
size: INT ~ name.Size[];
start: INT ← 0;
n: INT ← 0;
DO
stop: INT ~ name.Index[pos1: start, s2: "/"];
id: ROPE ~ name.Substr[start: start, len: stop-start];
writer.PutIdentifier[id]; n ← n+1;
IF stop<size THEN start ← stop+1 ELSE EXIT;
ENDLOOP;
writer.PutInt[n];
writer.PutOp[$makevec];
};
PutString:
PUBLIC
PROC[self: Master, string:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutString[string];
};
Get:
PUBLIC
PROC[self: Master, j:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[j]; writer.PutOp[$get];
};
MakeVecLU:
PUBLIC
PROC[self: Master, l, u:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[l]; writer.PutInt[u]; writer.PutOp[$makeveclu];
};
MakeVec:
PUBLIC
PROC[self: Master, n:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[n]; writer.PutOp[$makevec];
};
Shape:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$shape];
};
OpenVec:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$openvec];
};
GetProp:
PUBLIC
PROC[self: Master, id:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutIdentifier[id]; writer.PutOp[$getprop];
};
GetP:
PUBLIC
PROC[self: Master, id:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutIdentifier[id]; writer.PutOp[$getp];
};
MergeProp:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$mergeprop];
};
Frame:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$frame];
};
FGet:
PUBLIC
PROC[self: Master, j:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[j]; writer.PutOp[$fget];
};
FSet:
PUBLIC
PROC[self: Master, j:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[j]; writer.PutOp[$fset];
};
PoolOp:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$poolop];
};
Pool:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$pool];
};
PGet:
PUBLIC
PROC[self: Master, j:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[j]; writer.PutOp[$pget];
};
PSet:
PUBLIC
PROC[self: Master, j:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[j]; writer.PutOp[$pset];
};
Env:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$env];
};
MakePool:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$makepool];
};
NoPool:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$nopool];
};
BeginMakeCO:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $makeco];
};
EndMakeCO:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $makeco];
};
BeginMakeSimpleCO:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $makesimpleco];
};
EndMakeSimpleCO:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $makesimpleco];
};
Do:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$do];
};
DoSave:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$dosave];
};
DoSaveAll:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$dosaveall];
};
BeginDoBody:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $dobody];
};
EndDoBody:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $dobody];
};
BeginDoSaveBody:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $dosavebody];
};
EndDoSaveBody:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $dosavebody];
};
BeginDoSaveAllBody:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $dosaveallbody];
};
EndDoSaveAllBody:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $dosaveallbody];
};
BeginDoSaveSimpleBody:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $dosavesimplebody];
};
EndDoSaveSimpleBody:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $dosavesimplebody];
};
Pop:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$pop];
};
Copy:
PUBLIC
PROC[self: Master, depth:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[depth]; writer.PutOp[$copy];
};
Dup:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$dup];
};
Roll:
PUBLIC
PROC[self: Master, depth, moveFirst:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[depth]; writer.PutInt[moveFirst]; writer.PutOp[$roll];
};
Exch:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$exch];
};
Mark:
PUBLIC
PROC[self: Master, n:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[n]; writer.PutOp[$mark];
};
Unmark:
PUBLIC
PROC[self: Master, n:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[n]; writer.PutOp[$unmark];
};
Unmark0:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$unmark0];
};
Count:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$count];
};
BeginIf:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $if];
};
EndIf:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $if];
};
BeginIfElse:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $ifelse];
};
EndIfElse:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $ifelse];
};
IGet:
PUBLIC
PROC[self: Master, var: IPBasic.ImagerVariable] ~ {
writer: Writer ~ self.writer;
writer.PutInt[var.ORD]; writer.PutOp[$iget];
};
ISet:
PUBLIC
PROC[self: Master, var: IPBasic.ImagerVariable] ~ {
writer: Writer ~ self.writer;
writer.PutInt[var.ORD]; writer.PutOp[$iset];
};
SetPriorityImportant:
PUBLIC
PROC[self: Master, priorityImportant:
BOOL] ~ {
writer: Writer ~ self.writer;
writer.PutInt[IF priorityImportant THEN 1 ELSE 0]; ISet[self, $priorityImportant];
};
SetStrokeWidth:
PUBLIC
PROC[self: Master, strokeWidth:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[strokeWidth]; ISet[self, $strokeWidth];
};
SetStrokeEnd:
PUBLIC
PROC[self: Master, strokeEnd: IPBasic.StrokeEnd] ~ {
writer: Writer ~ self.writer;
writer.PutInt[strokeEnd.ORD]; ISet[self, $strokeEnd];
};
SetAmplifySpace:
PUBLIC
PROC[self: Master, amplifySpace:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[amplifySpace]; ISet[self, $amplifySpace];
};
SetCorrectShrink:
PUBLIC
PROC[self: Master, correctShrink:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[correctShrink]; ISet[self, $correctShrink];
};
MakeT:
PUBLIC
PROC[self: Master, a, b, c, d, e, f:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[a]; writer.PutReal[b]; writer.PutReal[c];
writer.PutReal[d]; writer.PutReal[e]; writer.PutReal[f];
writer.PutOp[$maket];
};
Translate:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$translate];
};
Rotate:
PUBLIC
PROC[self: Master, a:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[a]; writer.PutOp[$rotate];
};
Scale:
PUBLIC
PROC[self: Master, s:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[s]; writer.PutOp[$scale];
};
Scale2:
PUBLIC
PROC[self: Master, sx, sy:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[sx]; writer.PutReal[sy]; writer.PutOp[$scale2];
};
Concat:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$concat];
};
ConcatT:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$concatt];
};
TranslateT:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$translate];
writer.PutOp[$concatt];
};
RotateT:
PUBLIC
PROC[self: Master, a:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[a]; writer.PutOp[$rotate];
writer.PutOp[$concatt];
};
ScaleT:
PUBLIC
PROC[self: Master, s:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[s]; writer.PutOp[$scale];
writer.PutOp[$concatt];
};
Scale2T:
PUBLIC
PROC[self: Master, sx, sy:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[sx]; writer.PutReal[sy]; writer.PutOp[$scale2];
writer.PutOp[$concatt];
};
Move:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$move];
};
Trans:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$trans];
};
Show:
PUBLIC
PROC[self: Master, string:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutString[string]; writer.PutOp[$show];
};
ShowAndXRel:
PUBLIC
PROC[self: Master, string:
ROPE] ~ {
writer: Writer ~ self.writer;
writer.PutString[string]; writer.PutOp[$showandxrel];
};
SetXY:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$setxy];
};
SetXYRel:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$setxyrel];
};
SetXRel:
PUBLIC
PROC[self: Master, x:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutOp[$setxrel];
};
SetYRel:
PUBLIC
PROC[self: Master, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[y]; writer.PutOp[$setyrel];
};
MakeGray:
PUBLIC
PROC[self: Master, f:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[f]; writer.PutOp[$makegray];
};
FindColor:
PUBLIC
PROC[self: Master, name:
ROPE] ~ {
writer: Writer ~ self.writer;
PutName[self, name]; writer.PutOp[$findcolor];
};
FindColorOperator:
PUBLIC
PROC[self: Master, name:
ROPE] ~ {
writer: Writer ~ self.writer;
PutName[self, name]; writer.PutOp[$findcoloroperator];
};
SetGray:
PUBLIC
PROC[self: Master, f:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[f]; writer.PutOp[$setgray];
};
MoveTo:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$moveto];
};
LineTo:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$lineto];
};
LineToX:
PUBLIC
PROC[self: Master, x:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutOp[$linetox];
};
LineToY:
PUBLIC
PROC[self: Master, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[y]; writer.PutOp[$linetoy];
};
CurveTo:
PUBLIC
PROC[self: Master, x1, y1, x2, y2, x3, y3:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x1]; writer.PutReal[y1];
writer.PutReal[x2]; writer.PutReal[y2];
writer.PutReal[x3]; writer.PutReal[y3];
writer.PutOp[$curveto];
};
ConicTo:
PUBLIC
PROC[self: Master, x1, y1, x2, y2:
REAL, e:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x1]; writer.PutReal[y1];
writer.PutReal[x2]; writer.PutReal[y2];
writer.PutReal[e];
writer.PutOp[$conicto];
};
ArcTo:
PUBLIC
PROC[self: Master, x1, y1, x2, y2:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x1]; writer.PutReal[y1];
writer.PutReal[x2]; writer.PutReal[y2];
writer.PutOp[$arcto];
};
MakeOutline:
PUBLIC
PROC[self: Master, n:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[n]; writer.PutOp[$makeoutline];
};
MaskFill:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$maskfill];
};
MaskStroke:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$maskstroke];
};
MaskStrokeClosed:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$maskstrokeclosed];
};
MaskVector:
PUBLIC
PROC[self: Master, x1, y1, x2, y2:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x1]; writer.PutReal[y1];
writer.PutReal[x2]; writer.PutReal[y2];
writer.PutOp[$maskvector];
};
MaskRectangle:
PUBLIC
PROC[self: Master, x, y, w, h:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y];
writer.PutReal[w]; writer.PutReal[h];
writer.PutOp[$maskrectangle];
};
StartUnderline:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$startunderline];
};
MaskUnderline:
PUBLIC
PROC[self: Master, dy, h:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[dy]; writer.PutReal[h]; writer.PutOp[$maskunderline];
};
FindFont:
PUBLIC
PROC[self: Master, name:
ROPE] ~ {
writer: Writer ~ self.writer;
PutName[self, name]; writer.PutOp[$findfont];
};
ModifyFont:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$modifyfont];
};
SetupFont:
PUBLIC
PROC[self: Master, n:
INT, name:
ROPE, scale:
REAL] ~ {
writer: Writer ~ self.writer;
PutName[self, name]; writer.PutOp[$findfont];
writer.PutReal[scale]; writer.PutOp[$scale]; writer.PutOp[$modifyfont];
writer.PutInt[n]; writer.PutOp[$fset];
};
SetFont:
PUBLIC
PROC[self: Master, n:
INT] ~ {
writer: Writer ~ self.writer;
writer.PutInt[n]; writer.PutOp[$setfont];
};
CorrectMask:
PUBLIC
PROC[self: Master] ~ {
writer: Writer ~ self.writer;
writer.PutOp[$correctmask];
};
CorrectSpace:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$correctspace];
};
BeginCorrect:
PUBLIC
PROC[self: Master] ~ {
BeginBodyOp[self, $correct];
};
EndCorrect:
PUBLIC
PROC[self: Master] ~ {
EndBodyOp[self, $correct];
};
SetCorrectMeasure:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$setcorrectmeasure];
};
SetCorrectTolerance:
PUBLIC
PROC[self: Master, x, y:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutReal[y]; writer.PutOp[$setcorrecttolerance];
};
Space:
PUBLIC
PROC[self: Master, x:
REAL] ~ {
writer: Writer ~ self.writer;
writer.PutReal[x]; writer.PutOp[$space];
};
END.