ImagerIPImpl.mesa
Copyright © 1984, Xerox Corporation. All rights reserved.
Doug Wyatt, September 24, 1984 11:11:10 am PDT
DIRECTORY
Font USING [FONT],
Imager USING [Class, ClassRep, Context, ContextRep, Error, IntKey, RealKey],
ImagerColor USING [Color],
ImagerPath USING [Clipper, PathProc],
ImagerPixelArray USING [PixelArray],
ImagerTransformation USING [Transformation],
IPOutput USING [ArcTo, Concat, ConcatT, ConicTo, Correct, CorrectMask, CorrectSpace, CurveTo, DoSaveAll, DoSaveSimpleBody, FindFont, IGet, ISet, LineTo, LineToX, LineToY, MakeOutline, MakeSimpleCO, MakeT, MaskFill, MaskRectangle, MaskStroke, MaskStrokeClosed, MaskUnderline, MaskVector, Master, ModifyFont, Move, MoveTo, PutInt, PutOp, PutReal, Rotate, Scale, Scale2, SetCorrectMeasure, SetCorrectTolerance, SetGray, SetXRel, SetXY, SetXYRel, SetYRel, ShowChar, ShowRope, ShowText, Space, StartUnderline, Trans, Translate],
Rope USING [ROPE],
Vector2 USING [VEC];
ImagerIPImpl: CEDAR PROGRAM
IMPORTS Imager, IPOutput
~ BEGIN
VEC: TYPE ~ Vector2.VEC;
Transformation: TYPE ~ ImagerTransformation.Transformation;
Color: TYPE ~ ImagerColor.Color;
PixelArray: TYPE ~ ImagerPixelArray.PixelArray;
PathProc: TYPE ~ ImagerPath.PathProc;
Clipper: TYPE ~ ImagerPath.Clipper;
FONT: TYPE ~ Font.FONT;
ROPE: TYPE ~ Rope.ROPE;
Context: TYPE ~ Imager.Context;
Master: TYPE ~ IPOutput.Master;
Data: TYPE ~ REF DataRep;
DataRep: TYPE ~ RECORD[master: Master];
Create: PROC[master: Master] RETURNS[Context] ~ {
data: Data ~ NEW[DataRep ← [master: master]];
RETURN[NEW[Imager.ContextRep ← [class: ipClass, data: data, props: NIL]]];
};
SetTransformation: PROC[context: Context, transformation: Transformation] ~ {
ERROR Imager.Error[$Unimplemented];
};
SetFont: PROC[context: Context, font: FONT] ~ {
data: Data ~ NARROW[context.data];
master: Master ~ data.master;
name: ROPE ~ font.name;
m: Transformation ~ font.transformation;
master.FindFont[name];
master.MakeT[m.a, m.b, m.c, m.d, m.e, m.f];
master.ModifyFont[];
master.ISet[$showVec];
};
SetColor: PROC[context: Context, color: Color] ~ {
data: Data ~ NARROW[context.data];
master: Master ~ data.master;
WITH color SELECT FROM
c: ConstantColor => WITH c SELECT FROM
c: GrayConstantColor => master.SetGray[c.f];
c: CIEConstantColor => {
master.SetGray[1.0-(REAL[c.Y]/REAL[CARDINAL.LAST])];
};
ENDCASE => ERROR Imager.Error[$Unimplemented];
c: SampledColor => ERROR Imager.Error[$Unimplemented];
ENDCASE => ERROR Imager.Error[$Bug];
ERROR Imager.Error[$Unimplemented];
};
SetClipper: PROC[context: Context, clipper: Clipper] ~ {
ERROR Imager.Error[$Unimplemented];
};
SetReal: PROC[context: Context, key: Imager.RealKey, value: REAL] ~ {
data: Data ~ NARROW[context.data];
SELECT key FROM
$strokeWidth => { data.master.PutReal[value]; data.master.ISet[$strokeWidth] };
$amplifySpace => { data.master.PutReal[value]; data.master.ISet[$amplifySpace] };
$correctShrink => { data.master.PutReal[value]; data.master.ISet[$correctShrink] };
$underlineStart => { data.master.PutReal[value]; data.master.ISet[$underlineStart] };
ENDCASE => ERROR Imager.Error[$Unimplemented];
};
SetInt: PROC[context: Context, key: Imager.IntKey, value: INT] ~ {
data: Data ~ NARROW[context.data];
SELECT key FROM
$priorityImportant => { data.master.PutInt[value]; data.master.ISet[$priorityImportant] };
$noImage => { data.master.PutInt[value]; data.master.ISet[$noImage] };
$strokeEnd => { data.master.PutInt[value]; data.master.ISet[$strokeEnd] };
ENDCASE => ERROR Imager.Error[$Unimplemented];
};
GetTransformation: PROC[context: Context] RETURNS[Transformation] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetFont: PROC[context: Context] RETURNS[FONT] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetColor: PROC[context: Context] RETURNS[Color] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetClipper: PROC[context: Context] RETURNS[Clipper] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetReal: PROC[context: Context, key: Imager.RealKey] RETURNS[REAL] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetInt: PROC[context: Context, key: Imager.IntKey] RETURNS[INT] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetCP: PROC[context: Context] RETURNS[VEC] ~ {
ERROR Imager.Error[$Unimplemented];
};
GetCPRounded: PROC[context: Context] RETURNS[VEC] ~ {
ERROR Imager.Error[$Unimplemented];
};
SetGray: PROC[context: Context, f: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.SetGray[f];
};
PutPixelArray: PROC[master: Master, pa: PixelArray] ~ {
ERROR Imager.Error[$Unimplemented];
};
PutTransformation: PROC[master: Master, m: Transformation] ~ {
*** Should look for simple forms here.
master.MakeT[m.a, m.b, m.c, m.d, m.e, m.f];
};
PutColorOperator: PROC[master: Master, op: ATOM] ~ {
ERROR Imager.Error[$Unimplemented];
};
SetSampledColor: PROC[context: Context, pa: PixelArray, m: Transformation, op: ATOM] ~ {
data: Data ~ NARROW[context.data];
master: Master ~ data.master;
PutPixelArray[master, pa];
PutTransformation[master, m];
master.IGet[$T];
master.Concat[];
PutColorOperator[master, op];
master.PutOp[$makesampledcolor];
};
DoSave: PROC[context: Context, body: PROC] ~ {
data: Data ~ NARROW[context.data];
data.master.DoSaveSimpleBody[body];
};
DoSaveAll: PROC[context: Context, body: PROC] ~ {
data: Data ~ NARROW[context.data];
data.master.MakeSimpleCO[body];
data.master.DoSaveAll[];
};
ConcatT: PROC[context: Context, m: Transformation] ~ {
data: Data ~ NARROW[context.data];
data.master.MakeT[m.a, m.b, m.c, m.d, m.e, m.f];
data.master.ConcatT[];
};
Scale2T: PROC[context: Context, sx, sy: REAL] ~ {
data: Data ~ NARROW[context.data];
IF sx=sy THEN data.master.Scale[sx] ELSE data.master.Scale2[sx, sy];
data.master.ConcatT[];
};
RotateT: PROC[context: Context, a: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.Rotate[a]; data.master.ConcatT[];
};
TranslateT: PROC[context: Context, x, y: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.Translate[x, y]; data.master.ConcatT[];
};
Move: PROC[context: Context] ~ {
data: Data ~ NARROW[context.data];
data.master.Move[];
};
Trans: PROC[context: Context] ~ {
data: Data ~ NARROW[context.data];
data.master.Trans[];
};
SetXY: PROC[context: Context, p: VEC] ~ {
data: Data ~ NARROW[context.data];
data.master.SetXY[p.x, p.y];
};
SetXYI: PROC[context: Context, x, y: INTEGER] ~ {
data: Data ~ NARROW[context.data];
data.master.SetXY[x, y];
};
SetXYRel: PROC[context: Context, v: VEC] ~ {
data: Data ~ NARROW[context.data];
IF v.y=0 THEN data.master.SetXRel[v.x]
ELSE IF v.x=0 THEN data.master.SetYRel[v.y]
ELSE data.master.SetXYRel[v.x, v.y];
};
SetXYRelI: PROC[context: Context, x, y: INTEGER] ~ {
data: Data ~ NARROW[context.data];
IF y=0 THEN data.master.SetXRel[x]
ELSE IF x=0 THEN data.master.SetYRel[y]
ELSE data.master.SetXYRel[x, y];
};
DoTrajectories: PROC[master: Master, pathProc: PathProc, pathData: REF, action: PROC] ~ {
first: BOOLTRUE;
lp: VEC ← [0, 0];
moveTo: PROC[p: VEC] ~ {
IF first THEN first ← FALSE ELSE action[];
master.MoveTo[p.x, p.y];
lp ← p; };
lineTo: PROC[p: VEC] ~ {
IF first THEN moveTo[lp];
IF p.y=lp.y THEN master.LineToX[p.x]
ELSE IF p.x=lp.x THEN master.LineToY[p.y]
ELSE master.LineTo[p.x, p.y];
lp ← p; };
curveTo: PROC[p1, p2, p3: VEC] ~ {
IF first THEN moveTo[lp];
master.CurveTo[p1.x, p1.y, p2.x, p2.y, p3.x, p3.y];
lp ← p3; };
conicTo: PROC[p1, p2: VEC, r: REAL] ~ {
IF first THEN moveTo[lp];
master.ConicTo[p1.x, p1.y, p2.x, p2.y, r];
lp ← p2; };
arcTo: PROC[p1, p2: VEC] ~ {
IF first THEN moveTo[lp];
master.ArcTo[p1.x, p1.y, p2.x, p2.y];
lp ← p2; };
pathProc[pathData, moveTo, lineTo, curveTo, conicTo, arcTo];
IF NOT first THEN action[];
};
MaskFill: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
data: Data ~ NARROW[context.data];
n: INT ← 0;
count: PROC ~ { n ← n+1 };
DoTrajectories[data.master, pathProc, pathData, count];
data.master.MakeOutline[n];
data.master.MaskFill[];
};
MaskStroke: PROC[context: Context, pathProc: PathProc, pathData: REF, closed: BOOL] ~ {
data: Data ~ NARROW[context.data];
stroke: PROC ~ { data.master.MaskStroke[] };
strokeC: PROC ~ { data.master.MaskStrokeClosed[] };
DoTrajectories[data.master, pathProc, pathData, IF closed THEN strokeC ELSE stroke];
};
MaskVector: PROC[context: Context, p1, p2: VEC] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskVector[p1.x, p1.y, p2.x, p2.y];
};
MaskVectorI: PROC[context: Context, x1, y1, x2, y2: INTEGER] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskVector[x1, y1, x2, y2];
};
MaskRectangle: PROC[context: Context, x, y, w, h: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskRectangle[x, y, w, h];
};
MaskRectangleI: PROC[context: Context, x, y, w, h: INTEGER] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskRectangle[x, y, w, h];
};
StartUnderline: PROC[context: Context] ~ {
data: Data ~ NARROW[context.data];
data.master.StartUnderline[];
};
MaskUnderline: PROC[context: Context, dy, h: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskUnderline[dy, h];
};
MaskUnderlineI: PROC[context: Context, dy, h: INTEGER] ~ {
data: Data ~ NARROW[context.data];
data.master.MaskUnderline[dy, h];
};
MaskPixel: PROC[context: Context, pa: PixelArray] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipOutline: PROC[context: Context, pathProc: PathProc, pathData: REF, exclude: BOOL] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipRectangle: PROC[context: Context, x, y, w, h: REAL, exclude: BOOL] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipRectangleI: PROC[context: Context, x, y, w, h: INTEGER, exclude: BOOL] ~ {
ERROR Imager.Error[$Unimplemented];
};
ShowChar: PROC[context: Context, char: INT] ~ {
data: Data ~ NARROW[context.data];
data.master.ShowChar[char];
};
ShowRope: PROC[context: Context, rope: ROPE, start, len: INT] ~ {
data: Data ~ NARROW[context.data];
data.master.ShowRope[rope, start, len];
};
ShowText: PROC[context: Context, text: REF READONLY TEXT, start, len: NAT] ~ {
data: Data ~ NARROW[context.data];
data.master.ShowText[text, start, len];
};
CorrectMask: PROC[context: Context] ~ {
data: Data ~ NARROW[context.data];
data.master.CorrectMask[];
};
CorrectSpace: PROC[context: Context, v: VEC] ~ {
data: Data ~ NARROW[context.data];
data.master.CorrectSpace[v.x, v.y];
};
SetCorrectMeasure: PROC[context: Context, v: VEC] ~ {
data: Data ~ NARROW[context.data];
data.master.SetCorrectMeasure[v.x, v.y];
};
SetCorrectTolerance: PROC[context: Context, v: VEC] ~ {
data: Data ~ NARROW[context.data];
data.master.SetCorrectTolerance[v.x, v.y];
};
Space: PROC[context: Context, x: REAL] ~ {
data: Data ~ NARROW[context.data];
data.master.Space[x];
};
SpaceI: PROC[context: Context, x: INTEGER] ~ {
data: Data ~ NARROW[context.data];
data.master.Space[x];
};
Correct: PROC[context: Context, body: PROC] ~ {
data: Data ~ NARROW[context.data];
data.master.Correct[body];
};
ipClass: Imager.Class ~ NEW[Imager.ClassRep ← [
type: $Interpress,
DoSave: DoSave,
DoSaveAll: DoSaveAll,
SetTransformation: SetTransformation,
SetFont: SetFont,
SetColor: SetColor,
SetClipper: SetClipper,
SetReal: SetReal,
SetInt: SetInt,
ConcatT: ConcatT,
Scale2T: Scale2T,
RotateT: RotateT,
TranslateT: TranslateT,
Move: Move,
Trans: Trans,
SetGray: SetGray,
SetSampledColor: SetSampledColor,
MaskFill: MaskFill,
MaskStroke: MaskStroke,
MaskRectangle: MaskRectangle,
MaskRectangleI: MaskRectangleI,
MaskVector: MaskVector,
MaskVectorI: MaskVectorI,
StartUnderline: StartUnderline,
MaskUnderline: MaskUnderline,
MaskUnderlineI: MaskUnderlineI,
MaskPixel: MaskPixel,
SetXY: SetXY,
SetXYI: SetXYI,
SetXYRel: SetXYRel,
SetXYRelI: SetXYRelI,
ShowChar: ShowChar,
ShowRope: ShowRope,
ShowText: ShowText,
ClipOutline: ClipOutline,
ClipRectangle: ClipRectangle,
ClipRectangleI: ClipRectangleI,
CorrectMask: CorrectMask,
CorrectSpace: CorrectSpace,
Space: Space,
SpaceI: SpaceI,
SetCorrectMeasure: SetCorrectMeasure,
SetCorrectTolerance: SetCorrectTolerance,
Correct: Correct,
GetTransformation: GetTransformation,
GetFont: GetFont,
GetColor: GetColor,
GetClipper: GetClipper,
GetReal: GetReal,
GetInt: GetInt,
GetCP: GetCP,
GetCPRounded: GetCPRounded,
props: NIL
]];
END.