NewImagerIPImpl.mesa
Edited by:
Doug Wyatt, June 22, 1984 5:23:22 pm PDT
DIRECTORY
Font USING [FONT, Name, RequestedTransformation],
NewImager USING [Class, ClassRep, Context, Error],
ImagerBasic USING [Color, ConstantColor, IntPair, IntRectangle, Pair, PathMapType, PixelArray, StrokeEnd, Transformation, Visibility],
ImagerTransform USING [Contents, TransformationRec],
IPOutput,
RefText USING [TrustTextAsRope],
Rope USING [FromChar, ROPE, Substr];
ImagerIPImpl: CEDAR PROGRAM
IMPORTS Font, Imager: NewImager, ImagerTransform, IPOutput, RefText, Rope
~ BEGIN OPEN ImagerBasic;
ROPE: TYPE ~ Rope.ROPE;
Context: TYPE ~ Imager.Context;
FONT: TYPE ~ Font.FONT;
Name: TYPE ~ ImagerPrivate.Name;
TransformationRec: TYPE ~ ImagerTransform.TransformationRec;
Master: TYPE ~ IPOutput.Master;
Init: PROC[context: Context, info: REF] ~ {
master: Master ~ IPOutput.Narrow[info];
context.data ← master;
};
GetMaster: PROC[context: Context] RETURNS[Master] ~ INLINE {
RETURN[IPOutput.Narrow[context.data]];
};
SetFont: PROC[context: Context, font: FONT] ~ {
master: Master ~ GetMaster[context];
name: ROPE ~ font.Name[];
m: TransformationRec ~ font.RequestedTransformation[].Contents[];
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] ~ {
master: Master ~ GetMaster[context];
WITH color SELECT FROM
c: ConstantColor => {
master.SetGray[1.0-(REAL[c.Y]/REAL[CARDINAL.LAST])];
};
ENDCASE => ERROR Imager.Error[$Unimplemented];
};
SetStrokeWidth: PROC[context: Context, strokeWidth: REAL] ~ {
master: Master ~ GetMaster[context];
master.PutReal[strokeWidth]; master.ISet[$strokeWidth];
};
SetAmplifySpace: PROC[context: Context, amplifySpace: REAL] ~ {
master: Master ~ GetMaster[context];
master.PutReal[amplifySpace]; master.ISet[$amplifySpace];
};
SetCorrectShrink: PROC[context: Context, correctShrink: REAL] ~ {
master: Master ~ GetMaster[context];
master.PutReal[correctShrink]; master.ISet[$correctShrink];
};
SetPriorityImportant: PROC[context: Context, priorityImportant: BOOL] ~ {
master: Master ~ GetMaster[context];
master.PutInt[IF priorityImportant THEN 1 ELSE 0]; master.ISet[$priorityImportant];
};
SetStrokeEnd: PROC[context: Context, strokeEnd: StrokeEnd] ~ {
master: Master ~ GetMaster[context];
master.PutInt[SELECT strokeEnd FROM square => 0, butt => 1, round => 2, ENDCASE => ERROR];
master.ISet[$strokeEnd];
};
SetSampledColor: PROC[context: Context, pa: PixelArray, pixelT: Transformation, colorOperator: ATOM] ~ {
ERROR Imager.Error[$Unimplemented];
};
SetSampledBlack: PROC[context: Context, pa: PixelArray, pixelT: Transformation, transparent: BOOLEAN] ~ {
ERROR Imager.Error[$Unimplemented];
};
DoSave: PROC[context: Context, body: PROC] ~ {
master: Master ~ GetMaster[context];
master.BeginDoSaveSimpleBody[];
body[];
master.EndDoSaveSimpleBody[];
};
DoSaveAll: PROC[context: Context, body: PROC] ~ {
master: Master ~ GetMaster[context];
master.BeginMakeSimpleCO[];
body[];
master.EndMakeSimpleCO[];
master.DoSaveAll[];
};
ConcatT: PROC[context: Context, m: Transformation] ~ {
master: Master ~ GetMaster[context];
master.MakeT[m.a, m.b, m.c, m.d, m.e, m.f];
master.ConcatT[];
};
ScaleT: PROC[context: Context, s: REAL] ~ {
master: Master ~ GetMaster[context];
master.Scale[s]; master.ConcatT[];
};
Scale2T: PROC[context: Context, sx, sy: REAL] ~ {
master: Master ~ GetMaster[context];
master.Scale2[sx, sy]; master.ConcatT[];
};
RotateT: PROC[context: Context, a: REAL] ~ {
master: Master ~ GetMaster[context];
master.Rotate[a]; master.ConcatT[];
};
TranslateT: PROC[context: Context, x, y: REAL] ~ {
master: Master ~ GetMaster[context];
master.Translate[x, y]; master.ConcatT[];
};
Move: PROC[context: Context] ~ {
master: Master ~ GetMaster[context];
master.Move[];
};
Trans: PROC[context: Context] ~ {
master: Master ~ GetMaster[context];
master.Trans[];
};
SetXY: PROC[context: Context, x, y: REAL] ~ {
master: Master ~ GetMaster[context];
master.SetXY[x, y];
};
SetXYI: PROC[context: Context, x, y: INTEGER] ~ {
master: Master ~ GetMaster[context];
master.SetXY[x, y];
};
SetXYRel: PROC[context: Context, x, y: REAL] ~ {
master: Master ~ GetMaster[context];
IF y=0 THEN master.SetXRel[x]
ELSE IF x=0 THEN master.SetYRel[y]
ELSE master.SetXYRel[x, y];
};
SetXYRelI: PROC[context: Context, x, y: INTEGER] ~ {
master: Master ~ GetMaster[context];
IF y=0 THEN master.SetXRel[x]
ELSE IF x=0 THEN master.SetYRel[y]
ELSE master.SetXYRel[x, y];
};
DoTrajectories: PROC[master: Master, pathProc: PathProc, pathData: REF,
action: PROC[Master]] ~ {
started: BOOLFALSE;
lx, ly: REAL ← 0;
moveTo: PROC[x, y: REAL] ~ {
IF started THEN action[master] ELSE started ← TRUE;
master.MoveTo[lx ← x, ly ← y];
};
lineTo: PROC[x, y: REAL] ~ {
IF y=ly THEN master.LineToX[lx ← x]
ELSE IF x=lx THEN master.LineToY[ly ← y]
ELSE master.LineTo[lx ← x, ly ← y];
};
curveTo: PROC[x1, y1, x2, y2, x3, y3: REAL] ~ {
master.CurveTo[x1, y1, x2, y2, lx ← x3, ly ← y3];
};
conicTo: PROC[x1, y1, x2, y2: REAL, r: REAL] ~ {
master.ConicTo[x1, y1, lx ← x2, ly ← y2, r];
};
arcTo: PROC[x1, y1, x2, y2: REAL] ~ {
master.ArcTo[x1, y1, lx ← x2, ly ← y2];
};
pathProc[pathData, moveTo, lineTo, curveTo, conicTo, arcTo];
IF started THEN action[master];
};
MaskFill: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
master: Master ~ GetMaster[context];
n: INT ← 0;
action: PROC[master: Master] ~ { n ← n+1 };
DoTrajectories[master, pathProc, pathData, action];
master.MakeOutline[n];
master.MaskFill[];
};
MaskStroke: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
master: Master ~ GetMaster[context];
action: PROC[master: Master] ~ { master.MaskStroke[] };
DoTrajectories[master, pathProc, pathData, action];
};
MaskStrokeClosed: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
master: Master ~ GetMaster[context];
action: PROC[master: Master] ~ { master.MaskStrokeClosed[] };
DoTrajectories[master, pathProc, pathData, action];
};
MaskVector: PROC [context: Context, x1, y1, x2, y2: REAL] ~ {
master: Master ~ GetMaster[context];
master.MaskVector[x1, y1, x2, y2];
};
MaskVectorI: PROC[context: Context, x1, y1, x2, y2: INTEGER] ~ {
master: Master ~ GetMaster[context];
master.MaskVector[x1, y1, x2, y2];
};
MaskRectangle: PROC[context: Context, x, y, w, h: REAL] ~ {
master: Master ~ GetMaster[context];
master.MaskRectangle[x, y, w, h];
};
MaskRectangleI: PROC[context: Context, x, y, w, h: INTEGER] ~ {
master: Master ~ GetMaster[context];
master.MaskRectangle[x, y, w, h];
};
StartUnderline: PROC[context: Context] ~ {
master: Master ~ GetMaster[context];
master.StartUnderline[];
};
MaskUnderline: PROC[context: Context, dy, h: REAL] ~ {
master: Master ~ GetMaster[context];
master.MaskUnderline[dy, h];
};
MaskUnderlineI: PROC[context: Context, dy, h: INTEGER] ~ {
master: Master ~ GetMaster[context];
master.MaskUnderline[dy, h];
};
MaskPixel: PROC[context: Context, pa: PixelArray] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipOutline: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
ERROR Imager.Error[$Unimplemented];
};
ExcludeOutline: PROC[context: Context, pathProc: PathProc, pathData: REF] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipRectangle: PROC[context: Context, x, y, w, h: REAL] ~ {
ERROR Imager.Error[$Unimplemented];
};
ExcludeRectangle: PROC[context: Context, x, y, w, h: REAL] ~ {
ERROR Imager.Error[$Unimplemented];
};
ClipRectangleI: PROC[context: Context, x, y, w, h: INTEGER] ~ {
ERROR Imager.Error[$Unimplemented];
};
ExcludeRectangleI: PROC[context: Context, x, y, w, h: INTEGER] ~ {
ERROR Imager.Error[$Unimplemented];
};
ShowChar: PROC[context: Context, char: CHAR] ~ {
master: Master ~ GetMaster[context];
master.Show[Rope.FromChar[char]];
};
ShowCharacters: PROC[context: Context, characters: REF, start: INT, length: INT] ~ {
master: Master ~ GetMaster[context];
rope: ROPE ~ WITH characters SELECT FROM
text: REF TEXT => RefText.TrustTextAsRope[text],
ENDCASE => NARROW[characters];
master.Show[rope.Substr[start, length]];
};
CorrectMask: PROC[context: Context] ~ {
master: Master ~ GetMaster[context];
master.CorrectMask[];
};
CorrectSpace: PROC[context: Context, v: Pair] ~ {
master: Master ~ GetMaster[context];
master.CorrectSpace[v.x, v.y];
};
SetCorrectMeasure: PROC[context: Context, v: Pair] ~ {
master: Master ~ GetMaster[context];
master.SetCorrectMeasure[v.x, v.y];
};
SetCorrectTolerance: PROC [context: Context, v: Pair] ~ {
master: Master ~ GetMaster[context];
master.SetCorrectTolerance[v.x, v.y];
};
Space: PROC [context: Context, x: REAL] ~ {
master: Master ~ GetMaster[context];
master.Space[x];
};
SpaceI: PROC [context: Context, x: INTEGER] ~ {
master: Master ~ GetMaster[context];
master.Space[x];
};
Correct: PROC[context: Context, body: PROC] ~ {
master: Master ~ GetMaster[context];
master.BeginCorrect[];
body[];
master.EndCorrect[];
};
interpressClass: Imager.Class ~ NEW[Imager.ClassRep ← [
deviceType: $Interpress,
Init: Init,
DoSave: DoSave,
DoSaveAll: DoSaveAll,
SetPriorityImportant: SetPriorityImportant,
ConcatT: ConcatT,
ScaleT: ScaleT,
Scale2T: Scale2T,
RotateT: RotateT,
TranslateT: TranslateT,
Move: Move,
Trans: Trans,
SetSampledColor: SetSampledColor,
SetSampledBlack: SetSampledBlack,
SetXY: SetXY,
SetXYI: SetXYI,
SetXYRel: SetXYRel,
SetXYRelI: SetXYRelI,
MaskFill: MaskFill,
MaskStroke: MaskStroke,
MaskStrokeClosed: MaskStrokeClosed,
MaskVector: MaskVector,
MaskVectorI: MaskVectorI,
MaskRectangle: MaskRectangle,
MaskRectangleI: MaskRectangleI,
StartUnderline: StartUnderline,
MaskUnderline: MaskUnderline,
MaskUnderlineI: MaskUnderlineI,
MaskPixel: MaskPixel,
ClipOutline: ClipOutline,
ExcludeOutline: ExcludeOutline,
ClipRectangle: ClipRectangle,
ExcludeRectangle: ExcludeRectangle,
ClipRectangleI: ClipRectangleI,
ExcludeRectangleI: ExcludeRectangleI,
ShowChar: ShowChar,
ShowCharacters: ShowCharacters,
CorrectMask: CorrectMask,
CorrectSpace: CorrectSpace,
SetCorrectMeasure: SetCorrectMeasure,
SetCorrectTolerance: SetCorrectTolerance,
Space: Space,
SpaceI: SpaceI,
Correct: Correct
]];
ImagerPrivate.RegisterDevice[interpressClass];
END.