IPMaster.mesa
Copyright (C) 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, December 12, 1984 5:56:07 pm PST
Operations for reading and writing Interpress masters.
DIRECTORY
IO USING [STREAM],
Rope USING [ROPE];
IPMaster: CEDAR DEFINITIONS ~ BEGIN
BYTE: TYPE ~ [0..377B];
CARD: TYPE ~ LONG CARDINAL;
lastNat: NAT ~ NAT.LAST; -- because interpreter can't handle NAT.LAST as a default arg
lastInt: INT ~ INT.LAST; -- because interpreter can't handle INT.LAST as a default arg
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
ShortNumber: TYPE ~ [-4000..77777B-4000]; -- 15 bits
EncodingValue: TYPE = MACHINE DEPENDENT { -- 13 bits
nil(0),
nop(1), -- 2.0
setxy(10), -- 2.0
setxyrel(11), -- 2.0
setxrel(12), -- 2.0
setyrel(13), -- 2.0
linetox(14), -- 2.0
linetoy(15), -- 2.0
space(16), -- 2.0
get(17), -- 2.0
iget(18), -- 2.0
iset(19), -- 2.0
fget(20), -- 2.0
fset(21), -- 2.0
show(22), -- 2.0
lineto(23), -- 2.0
maskstroke(24), -- 2.0
moveto(25), -- 2.0
metricMaster(100), -- full ?
environmentMaster(101), -- full ?
beginBlock(102), -- 2.0
endBlock(103), -- 2.0
noPages(104), -- full
pageInstructions(105), -- 2.0
beginBody(106), -- 2.0
endBody(107), -- 2.0
correct(110), -- 2.0
makesimpleco(114), -- 2.0
makeco(115), -- full
makecompiledimage(116), -- full
dosavesimplebody(120), -- 2.0
dobody(121), -- full
dosavebody(122), -- full
dosaveallbody(123), -- full
showandxrel(146), -- 2.0
findfont(147), -- 2.0
modifyfont(148), -- 2.0
finddecompressor(149), -- 2.0
findfontvec(150), -- full
setfont(151), -- 2.0
setcorrectmeasure(154), -- 2.0
setcorrecttolerance(155), -- 2.0
correctmask(156), -- 2.0
correctspace(157), -- 2.0
getcp(159), -- 2.0
maket(160), -- full
opent(161), -- full
translate(162), -- 2.0
rotate(163), -- 2.0
scale(164), -- 2.0
concat(165), -- 2.0
scale2(166), -- 2.0
invert(167), -- full
concatt(168), -- 2.0
move(169), -- 2.0
trans(170), -- 2.0
transform(174), -- full
transformvec(175), -- full
roundxy(176), -- full
roundxyvec(177), -- full
pop(180), -- 2.0
dup(181), -- 2.0
copy(183), -- 2.0
roll(184), -- 2.0
exch(185), -- 2.0
mark(186), -- 2.0
unmark(187), -- 2.0
count(188), -- 2.0
unmark0(192), -- 2.0
abs(200), -- 2.0
add(201), -- 2.0
and(202), -- 2.0
ceiling(203), -- 2.0
div(204), -- 2.0
eq(205), -- 2.0
floor(206), -- 2.0
ge(207), -- 2.0
gt(208), -- 2.0
mod(209), -- 2.0
mul(210), -- 2.0
neg(211), -- 2.0
not(212), -- 2.0
or(213), -- 2.0
sub(214), -- 2.0
trunc(215), -- 2.0
rem(216), -- 2.0
round(217), -- 2.0
eqname(218), -- full
type(220), -- 2.0
atan(221), -- full
cos(222), -- full
exp(223), -- full
log(224), -- full
sin(225), -- full
sqrt(226), -- full
max(227), -- full
min(228), -- full
do(231), -- 2.0
dosave(232), -- 2.0
dosaveall(233), -- 2.0
if(239), -- 2.0
ifcopy(240), -- 2.0
ifelse(241), -- 2.0
loop(242), -- full
frame(250), -- full
poolop(253), -- full
pool(254), -- full
pget(255), -- full
pset(256), -- full
makepool(257), -- full
nopool(258), -- full
env(260), -- full
makeveclu(282), -- 2.0
makevec(283), -- 2.0
shape(285), -- 2.0
openvec(286), -- full
getprop(287), -- 2.0
getp(288), -- full
mergeprop(289), -- full
dround(300), -- full
getcprounded(301), -- full
curveto(402), -- full
arcto(403), -- full
conicto(404), -- full
maskfillparity(408), -- full ?
maskfill(409), -- 2.0
maskrectangle(410), -- 2.0
masktrapezoidx(411), -- 2.0
masktrapezoidy(412), -- 2.0
startunderline(413), -- 2.0
maskunderline(414), -- 2.0
makeoutline(417), -- 2.0
clipoutline(418), -- full
cliprectangle(419), -- full
findcoloroperator(421), -- 2.1
findcolormodeloperator(422), -- 2.1
findcolor(423), -- 2.0
setgray(424), -- 2.0
makegray(425), -- 2.0
makesampledblack(426), -- 2.0
makesampledcolor(427), -- 2.1
excludeoutline(430), -- full ?
excluderectangle(431), -- full ?
maskstrokeclosed(440), -- full
maskvector(441), -- 2.0
makepixelarray(450), -- 2.0
extractpixelarray(451), -- 2.1
maskpixel(452), -- 2.0
joinpixelarrays(453), -- full ?
error(600), -- 2.1
(17777B)
};
SequenceType: TYPE = MACHINE DEPENDENT { -- 5 bits
nil(0),
sequenceString(1),
sequenceInteger(2),
sequenceRational(4),
sequenceIdentifier(5),
sequenceComment(6),
sequenceContinued(7),
sequenceLargeVector(8),
sequencePackedPixelVector(9),
sequenceCompressedPixelVector(10),
sequenceInsertFile(11),
sequenceAdaptivePixelVector(12), -- 2.1
(37B)
};
Op: TYPE ~ {nil,
-- BASE primitives
get, makeveclu, makevec, shape, openvec, getprop, getp, mergeprop,
frame, fget, fset, poolop, pool, pget, pset, env,
makepool, nopool, makeco, makesimpleco, do, dosave, dosaveall,
dobody, dosavebody, dosaveallbody, dosavesimplebody, makecompiledimage,
pop, copy, dup, roll, exch, mark, unmark, unmark0, count, nop, error,
if, ifelse, ifcopy, loop,
eq, eqname, gt, ge, and, or, not, type,
add, sub, neg, abs, floor, ceiling, trunc, round, mul, div, mod, rem,
max, min, sqrt, exp, log, sin, cos, atan,
-- IMAGE primitives
iget, iset, dround,
maket, opent, translate, rotate, scale, scale2, concat, invert,
transform, transformvec, roundxy, roundxyvec,
concatt, move, trans, show, showandxrel,
setxy, setxyrel, setxrel, setyrel, getcp, getcprounded,
makepixelarray, extractpixelarray, joinpixelarrays, finddecompressor,
makegray, findcolor, findcoloroperator, findcolormodeloperator,
makesampledcolor, makesampledblack, setgray,
moveto, lineto, linetox, linetoy, curveto, conicto, arcto, makeoutline,
maskfill, maskfillparity, maskstroke, maskstrokeclosed, maskrectangle, maskvector,
startunderline, maskunderline, masktrapezoidx, masktrapezoidy, maskpixel,
clipoutline, excludeoutline, cliprectangle, excluderectangle,
findfont, findfontvec, modifyfont, setfont,
correctmask, correctspace, correct, setcorrectmeasure, setcorrecttolerance, space,
-- Symbols
beginBody, endBody, beginBlock, endBlock,
pageInstructions, noPages, metricMaster, environmentMaster
};
TypeCode: TYPE ~ MACHINE DEPENDENT {null(0),
number(1), identifier(2), vector(3), operator(4), -- Base types
transformation(5), pixelArray(6), color(7), trajectory(8), outline(9), -- Image types
(CARDINAL.LAST)
};
ImagerVariable: TYPE ~ MACHINE DEPENDENT {
DCScpx(0), DCScpy(1), correctMX(2), correctMY(3),
T(4), priorityImportant(5), mediumXSize(6), mediumYSize(7),
fieldXMin(8), fieldYMin(9), fieldXMax(10), fieldYMax(11),
showVec(12), color(13), noImage(14),
strokeWidth(15), strokeStyle(16), underlineStart(17), amplifySpace(18),
correctPass(19), correctShrink(20), correctTX(21), correctTY(22),
strokeDashes(23)
};
StrokeStyle: TYPE ~ MACHINE DEPENDENT {
square(0), butt(1), round(2), -- standard, all with mitered joints
(CARDINAL.LAST) -- room for expansion (round joints, probably)
};
Body: TYPE ~ REF BodyRep;
BodyRep: TYPE ~ RECORD[index, length: INT];
Node: TYPE ~ REF NodeRep;
NodeRep: TYPE ~ RECORD[
index, length: INT,
pageInstructions: Body, -- may be NIL
content: SELECT tag: * FROM
body => [body: Body],
block => [block: Block],
ENDCASE
];
Block: TYPE ~ REF BlockRep;
BlockRep: TYPE ~ RECORD[
index, length: INT,
noPages: BOOL,
preamble: Node,
nodes: SEQUENCE size: NAT OF Node
];
Skeleton: TYPE ~ REF SkeletonRep;
SkeletonRep: TYPE ~ RECORD[
instructions: Body, -- may be NIL
topBlock: Block
];
Version: TYPE ~ RECORD[major, minor: CARDINAL]; -- Interpress version number
currentVersion: Version ~ [3, 0]; -- latest version supported by this interface
ErrorCode: TYPE ~ {nil,
bug,
unimplemented,
overflow,
invalidHeader,
invalidVersion,
invalidSkeleton,
invalidToken,
invalidRational,
invalidIdentifier,
invalidString
};
Error: ERROR[code: ErrorCode, explanation: ROPE];
OpFromEvArray: TYPE ~ PACKED ARRAY EncodingValue OF Op;
GetOpFromEv: PROC RETURNS[REF READONLY OpFromEvArray];
EvFromOpArray: TYPE ~ PACKED ARRAY Op OF EncodingValue;
GetEvFromOp: PROC RETURNS[REF READONLY EvFromOpArray];
EncodingValueFromOp: PROC[Op] RETURNS[EncodingValue];
Converts a Xerox encoding value to an Op. Returns nil if undefined.
OpFromEncodingValue: PROC[EncodingValue] RETURNS[Op];
Converts an Op to a Xerox encoding value.
RopeFromOp: PROC[Op] RETURNS[ROPE];
Converts a ROPE to an Op. Ignores case. Returns nil if undefined.
OpFromRope: PROC[ROPE] RETURNS[Op];
Converts an Op to a ROPE. Returns NIL if given nil.
RopeFromImagerVariable: PROC[ImagerVariable] RETURNS[ROPE];
Converts an ImagerVariable to a ROPE.
ValidIdentifier: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt] RETURNS[BOOL];
ValidString: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt] RETURNS[BOOL];
ValidName: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt] RETURNS[BOOL];
ValidVersion: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt] RETURNS[BOOL];
MapName: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt,
action: PROC[base: ROPE, start, len: INT] RETURNS[quit: BOOLFALSE]]
RETURNS[BOOL];
Calls action for each component of a structured name. Components are separated by "/".
Does NOT verify that the components are valid Identifiers.
Returns TRUE when some action returns TRUE.
ListFromName: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt]
RETURNS
[LIST OF ROPE];
Uses MapName to convert a structured name to a list of components.
VersionFromRope: PROC[rope: ROPE, start: INT ← 0, len: INT ← lastInt]
RETURNS
[Version];
Parses a Version number of the form "m.n".
GetHeader: PROC[stream: STREAM,
prefix: ROPENIL, maxLength: INT ← 100] RETURNS[ROPE];
Reads up to the first space; leaves the stream positioned after the space.
Returns the header as a ROPE, omitting the space (Example: "Interpress/Xerox/2.1").
If prefix is supplied, the beginning of the header must match it.
! Error[invalidHeader] if the prefix doesn't match or length exceeds maxLength.
GetSkeleton: PROC[stream: STREAM] RETURNS[Skeleton];
Parses the skeleton structure of the master.
! Error[invalidSkeleton] if the skeleton is malformed.
SkipToEndOfBody: PROC[stream: STREAM];
Skips to the end of the enclosing body.
Leaves the stream positioned at the token following the body.
SetIndex: PROC[stream: STREAM, index: INT];
Same as IO.SetIndex[stream, index]. Here for convenience.
CopyBytes: PROC[to: STREAM, from: STREAM, count: INT] RETURNS[copied: INT];
Copies bytes to an output stream from an input stream.
Returns the actual number of bytes copied.
CopySegment: PROC[to: STREAM, from: STREAM, start, length: INT];
Does SetIndex[from, start], then copies length bytes.
! IO.EndOfStream[from] if too few bytes were copied.
TokenType: TYPE ~ {nil, num, op, seq};
Token: TYPE ~ RECORD[
index: INT ← 0,
type: TokenType ← nil,
num: ShortNumber ← ShortNumber.FIRST,
ev: EncodingValue ← nil,
seq: SequenceType ← nil,
len: INT ← 0
];
GetToken: PROC[stream: STREAM, flushComments: BOOLTRUE] RETURNS[Token];
Reads from the stream a token in the Xerox encoding. (See Interpress section 2.5.1.)
If token.type=seq, caller must read token.len data bytes from stream to reach next token.
SkipBytes: PROC[stream: STREAM, len: INT];
Skips len bytes in the stream.
IntFromData: PROC[text: REF READONLY TEXT,
start: NAT ← 0, len: NAT ← lastNat] RETURNS[INT];
RealFromData: PROC[text: REF READONLY TEXT,
start: NAT ← 0, len: NAT ← lastNat] RETURNS[REAL];
These interpret the bytes in text[start..start+len) as a two's complement binary integer.
PutOp: PROC[stream: STREAM, op: Op];
Appends a primitive operator or symbol literal; chooses the shortest encoding.
PutInt: PROC[stream: STREAM, n: INT];
Appends a Number literal; chooses the shortest encoding.
PutBool: PROC[stream: STREAM, bool: BOOL];
Appends a 1 for TRUE, 0 for FALSE.
PutRational: PROC[stream: STREAM, n, d: INT];
Appends a Number literal, n/d.
! Error[invalidRational] if d is zero.
PutReal: PROC[stream: STREAM, val: REAL];
Appends a Number literal. Chooses a rational approximation if necessary.
PutIdentifier: PROC[stream: STREAM, rope: ROPE, start: INT ← 0, len: INT ← lastInt];
Appends an Identifier literal.
! Error[invalidIdentifier] if the rope is not a legal identifier.
PutString: PROC[stream: STREAM, rope: ROPE, start: INT ← 0, len: INT ← lastInt];
Appends the encoding notation for a string. Treats '\377 as an escape code.
See the Character Code Standard, chapter 6, and Interpress, section 2.5.3.
! Error[invalidString] if the rope is not a legal string.
PutComment: PROC[stream: STREAM, rope: ROPE, start: INT ← 0, len: INT ← lastInt];
Appends a comment token.
PutInsertFile: PROC[stream: STREAM, rope: ROPE, start: INT ← 0, len: INT ← lastInt];
Appends a sequenceInsertFile.
PutName: PROC[stream: STREAM, rope: ROPE, start: INT ← 0, len: INT ← lastInt];
Parses a structured name and appends tokens to build a Vector of Identifiers.
For example, "a/b/c" produces < a b c 3 MAKEVEC >; "foo" produces < foo 1 MAKEVEC >.
See Interpress, section 3.2.1.
! Error[invalidIdentifier] if the name contains an invalid identifier.
PutBits: PROC[stream: STREAM,
base: LONG POINTER, wordsPerLine: NAT, sMin, fMin, sSize, fSize: NAT];
Appends a sequencePackedPixelVector, one bit per sample.
PutDescriptor: PROC[stream: STREAM, seq: SequenceType, len: INT];
Appends a sequence descriptor; len data bytes must follow.
PutShortNumber: PROC[stream: STREAM, n: ShortNumber];
Appends a ShortNumber token.
PutShortOp: PROC[stream: STREAM, ev: EncodingValue[VAL[0]..VAL[37B]]];
PutLongOp: PROC[stream: STREAM, ev: EncodingValue];
Appends a ShortOp or LongOp token.
PutShortSequence: PROC[stream: STREAM, seq: SequenceType, len: [0..377B]];
PutLongSequence: PROC[stream: STREAM, seq: SequenceType, len: INT--[0..77777777B]--];
Appends a ShortSequence or LongSequence token; len data bytes must follow.
PutUnsigned: PROC[stream: STREAM, len: [0..4], val: CARD];
Appends the low order len bytes of val.
PutSigned: PROC[stream: STREAM, len: [0..4], val: INT];
Appends the low order len bytes of val.
END.