DIRECTORY Font USING [FONT], Imager, ImagerBasic USING [ColorRep, Pair, PixelArray, StrokeEnd, Transformation], Rope USING [ROPE]; ImagerImpl: CEDAR PROGRAM EXPORTS Imager ~ BEGIN Context: TYPE ~ REF ContextRep; ContextRep: TYPE ~ RECORD[class: Class, data: REF, state: REF]; Create: PUBLIC PROC[deviceType: ATOM, data: REF _ NIL] RETURNS [Context] ~ { }; Error: PUBLIC ERROR[errorCode: ErrorCode] ~ CODE; DoSave: PUBLIC PROC[context: Context, body: PROC] ~ { }; DoSaveAll: PUBLIC PROC[context: Context, body: PROC] ~ { }; SetPriorityImportant: PUBLIC PROC[context: Context, priorityImportant: BOOL] ~ { context.class.SetPriorityImportant[context, priorityImportant]; }; GetProp: PUBLIC PROC[context: Context, key: REF] RETURNS [value: REF] ~ { RETURN[Atom.GetPropFromList[context.propList, key]]; }; PutProp: PUBLIC PROC[context: Context, key: REF, value: REF] ~ { context.propList _ Atom.PutPropOnList[context.propList, key, val]; }; RemProp: PUBLIC PROC[context: Context, key: REF] ~ { context.propList _ Atom.RemPropFromList[context.propList, key]; }; MakeT: PROC[Matrix] RETURNS[Transformation] ~ { }; OpenT: PROC[Transformation] RETURNS[Matrix] ~ { }; Scale: PROC[s: REAL] RETURNS[Transformation] ~ { }; Scale2: PROC[sx, sy: REAL] RETURNS[Transformation] ~ { }; Rotate: PROC[a: REAL] RETURNS[Transformation] ~ { }; Translate: PROC[x, y: REAL] RETURNS[Transformation] ~ { }; Concat: PROC[m, n: Transformation] RETURNS[Transformation] ~ { }; Invert: PROC[m: Transformation] RETURNS[Transformation] ~ { }; Transform: PROC[m: Transformation, p: Pair] RETURNS[Pair] ~ { }; TransformVec: PROC[m: Transformation, p: Pair] RETURNS[Pair] ~ { }; InverseTransform: PROC[m: Transformation, p: Pair] RETURNS[Pair] ~ { }; InverseTransformVec: PROC[m: Transformation, p: Pair] RETURNS[Pair] ~ { }; pointsToMeters: Transformation; -- printer's points, 72.27 to the inch ConcatT: PROC[context: Context, m: Transformation] ~ { context.class.ConcatT[context, m]; }; ScaleT: PROC[context: Context, s: REAL] ~ { context.class.ScaleT[context, s]; }; Scale2T: PROC[context: Context, sx, sy: REAL] ~ { context.class.Scale2T[context, sx, sy]; }; RotateT: PROC[context: Context, a: REAL] ~ { context.class.RotateT[context, a]; }; TranslateT: PROC[context: Context, x, y: REAL] ~ { context.class.TranslateT[context, x, y]; }; Move: PROC[context: Context] ~ { context.class.Move[context]; }; Trans: PROC[context: Context] ~ { context.class.Trans[context]; }; MoveToP: PROC[p: Pair] RETURNS[Trajectory] ~ { }; MoveTo: PROC[x, y: REAL] RETURNS[Trajectory] ~ INLINE { RETURN MoveToP[[x, y]] }; LineToP: PROC[t: Trajectory, p: Pair] RETURNS[Trajectory]; LineTo: PROC[t: Trajectory, x, y: REAL] RETURNS[Trajectory] ~ INLINE { RETURN t.LineToP[[x, y]] }; LineToX: PROC[t: Trajectory, x: REAL] RETURNS[Trajectory]; LineToY: PROC[t: Trajectory, y: REAL] RETURNS[Trajectory]; CurveToP: PROC[t: Trajectory, p1, p2, p3: Pair] RETURNS[Trajectory]; CurveTo: PROC[t: Trajectory, x1, y1, x2, y2, x3, y3: REAL] RETURNS[Trajectory] ~ INLINE { RETURN t.CurveToP[[x1, y1], [x2, y2], [x3, y3]] }; ConicToP: PROC[t: Trajectory, p1, p2: Pair, r: REAL] RETURNS[Trajectory]; ConicTo: PROC[t: Trajectory, x1, y1, x2, y2: REAL, r: REAL] RETURNS[Trajectory] ~ INLINE { RETURN t.ConicToP[[x1, y1], [x2, y2], r] }; ArcToP: PROC[t: Trajectory, p1, p2: Pair] RETURNS[Trajectory]; ArcTo: PROC[t: Trajectory, x1, y1, x2, y2: REAL] RETURNS[Trajectory] ~ INLINE { RETURN t.ArcToP[[x1, y1], [x2, y2]] }; MapTrajectory: PathProc ~ { WITH data SELECT FROM end: Trajectory => { moveTo[end.lp]; FOR t: Trajectory _ end, t.prev UNTIL t.prev=NIL DO p0: Pair ~ t.prev.lp; WITH t SELECT FROM t: REF TrajectoryRep[move] => ERROR; -- should have had t.prev=NIL t: REF TrajectoryRep[line] => lineTo[p0]; t: REF TrajectoryRep[curve] => curveTo[t.p2, t.p1, p0]; t: REF TrajectoryRep[conic] => conicTo[t.p1, p0, x.r]; t: REF TrajectoryRep[arc] => arcTo[t.p1, p0]; ENDCASE => ERROR; -- unknown variant ENDLOOP; }; ENDCASE => ERROR; -- data is wrong type or NIL }; MapTrajectoryList: PathProc ~ { WITH data SELECT FROM head: TrajectoryList => { FOR list: TrajectoryList _ head, list.rest UNTIL list=NIL DO t: Trajectory ~ list.first; MapTrajectory[t, moveTo, lineTo, curveTo, conicTo, arcTo]; ENDLOOP; }; ENDCASE => ERROR; -- data is wrong type or NIL }; MaskFill: PROC[context: Context, outline: REF] ~ { WITH outline SELECT FROM path: PATH => context.class.MaskFill[context, MapPath, path]; t: Trajectory => context.class.MaskFill[context, MapTrajectory, t]; tlist: TrajectoryList => context.class.MaskFill[context, MapTrajectoryList, tlist]; ENDCASE => ERROR; -- outline is wrong type or NIL }; MaskFillPath: PROC[context: Context, pathProc: PathProc, pathData: REF _ NIL] ~ { context.class.MaskFill[context, pathProc, pathData]; }; SetStrokeWidth: PUBLIC PROC[context: Context, strokeWidth: REAL] ~ { context.class.SetStrokeWidth[context, strokeWidth]; }; SetStrokeEnd: PUBLIC PROC[context: Context, strokeEnd: StrokeEnd] ~ { context.class.SetStrokeEnd[context, strokeEnd]; }; MaskStroke: PUBLIC PROC[context: Context, stroke: REF] ~ { WITH stroke SELECT FROM path: PATH => context.class.MaskStroke[context, MapPath, path]; t: Trajectory => context.class.MaskStroke[context, MapTrajectory, t]; tlist: TrajectoryList => context.class.MaskStroke[context, MapTrajectoryList, tlist]; ENDCASE => ERROR; -- stroke is wrong type or NIL }; MaskStrokeClosed: PUBLIC PROC[context: Context, stroke: REF] ~ { WITH stroke SELECT FROM path: PATH => context.class.MaskStrokeClosed[context, MapPath, path]; t: Trajectory => context.class.MaskStrokeClosed[context, MapTrajectory, t]; tlist: TrajectoryList => context.class.MaskStrokeClosed[context, MapTrajectoryList, tlist]; ENDCASE => ERROR; -- stroke is wrong type or NIL }; MaskStrokePath: PUBLIC PROC[ context: Context, pathProc: PathProc, pathData: REF _ NIL] ~ { context.class.MaskStroke[context, pathProc, pathData]; }; MaskStrokeClosedPath: PUBLIC PROC[ context: Context, pathProc: PathProc, pathData: REF _ NIL] ~ { context.class.MaskStrokeClosed[context, pathProc, pathData]; }; MaskRectangle: PUBLIC PROC[context: Context, x, y, w, h: REAL] ~ { context.class.MaskRectangle[context: context, x: x, y: y, w: w, h: h]; }; MaskBox: PUBLIC PROC[context: Context, box: Box] ~ { context.class.MaskRectangle[context: context, x: box.xmin, y: box.ymin, w: box.xmax-box.xmin, h: box.ymax-box.ymin]; }; MaskVectorP: PUBLIC PROC[context: Context, p1, p2: Pair] ~ { context.class.MaskVector[context: context, x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y]; }; MaskVector: PUBLIC PROC[context: Context, x1, y1, x2, y2: REAL] ~ { context.class.MaskVector[context: context, x1: x1, y1: y1, x2: x2, y2: y2]; }; SetXYP: PROC[context: Context, p: Pair]; SetXY: PROC[context: Context, x, y: REAL] ~ INLINE { context.SetXYP[[x, y]] }; SetXYI: PROC[context: Context, x, y: INTEGER] ~ INLINE { context.class.SetXYI[context, x, y] }; SetXYRelP: PROC[context: Context, p: Pair]; SetXYRel: PROC[context: Context, x, y: REAL] ~ INLINE { context.SetXYRelP[[x, y]] }; SetXYRelI: PROC[context: Context, x, y: INTEGER] ~ INLINE { context.class.SetXYRelI[context, x, y] }; SetXRel: PROC[context: Context, x: REAL]; SetXRelI: PROC[context: Context, x: INTEGER] ~ INLINE { context.class.SetXYRelI[context, x, 0] }; SetYRel: PROC[context: Context, y: REAL]; SetYRelI: PROC[context: Context, y: INTEGER] ~ INLINE { context.class.SetXYRelI[context, 0, y] }; FONT: TYPE ~ Font.FONT; ROPE: TYPE ~ Rope.ROPE; RopeOrRefText: TYPE ~ REF; -- ROPE or REF TEXT FindFont: PROC[name: ROPE] RETURNS[FONT]; ModifyFont: PROC[font: FONT, m: Transformation] RETURNS[FONT]; MakeFont: PROC[name: ROPE, size: REAL] RETURNS[FONT]; SetFont: PROC[context: Context, font: FONT]; ShowChar: PROC[context: Context, char: CHAR, font: FONT _ NIL]; ShowCharacters: PROC[context: Context, characters: RopeOrRefText, start: INT _ 0, length: INT _ INT.LAST, font: FONT _ NIL]; SetAmplifySpace: PROC[context: Context, amplifySpace: REAL]; StartUnderline: PROC[context: Context]; MaskUnderline: PROC[context: Context, dy, h: REAL]; MaskUnderlineI: PROC[context: Context, dy, h: INTEGER] ~ INLINE { context.class.MaskUnderlineI[context, dy, h] }; CorrectMask: PROC[context: Context]; CorrectSpaceP: PROC[context: Context, p: Pair]; CorrectSpace: PROC[context: Context, x, y: REAL] ~ INLINE { context.CorrectSpaceP[[x, y]] }; Correct: PROC[context: Context, body: PROC]; SetCorrectMeasureP: PROC[context: Context, p: Pair]; SetCorrectMeasure: PROC[context: Context, x, y: REAL] ~ INLINE { context.SetCorrectMeasureP[[x, y]] }; SetCorrectToleranceP: PROC[context: Context, p: Pair]; SetCorrectTolerance: PROC[context: Context, x, y: REAL] ~ INLINE { context.SetCorrectToleranceP[[x, y]] }; SetCorrectShrink: PROC[context: Context, correctShrink: REAL]; Space: PROC[context: Context, x: REAL]; SpaceI: PROC[context: Context, x: INTEGER] ~ INLINE { context.class.SpaceI[context, x] }; PixelArray: TYPE ~ ImagerBasic.PixelArray; MakePixelArrayFromBits: PROC[ bitPointer: LONG POINTER TO PACKED ARRAY [0..0) OF [0..1], bitsPerLine, samplesPerLine, numberOfLines: NAT ] RETURNS [PixelArray]; MaskPixel: PROC[context: Context, pa: PixelArray]; ConstantColor: TYPE ~ REF ImagerBasic.ColorRep[constant]; MakeGray: PROC[f: REAL] RETURNS[ConstantColor]; black: ConstantColor; -- MakeGray[1] white: ConstantColor; -- MakeGray[0] Color: TYPE ~ REF ImagerBasic.ColorRep; SetSampledColor: PROC[context: Context, pa: PixelArray, pixelT: Transformation, colorOperator: ATOM _ $Intensity]; SetSampledBlack: PROC[context: Context, pa: PixelArray, pixelT: Transformation, transparent: BOOLEAN _ FALSE]; SetColor: PROC[context: Context, color: Color]; SetGray: PROC[context: Context, f: REAL]; ClipOutline: PROC[context: Context, outline: REF]; ClipOutlinePath: PROC[context: Context, pathProc: PathProc, pathData: REF _ NIL]; ExcludeOutline: PROC[context: Context, outline: REF]; ExcludeOutlinePath: PROC[context: Context, pathProc: PathProc, pathData: REF _ NIL]; ClipRectangle: PROC[context: Context, x, y, w, h: REAL]; ClipRectangleI: PROC[context: Context, x, y, w, h: INTEGER]; ExcludeRectangle: PROC[context: Context, x, y, w, h: REAL]; ExcludeRectangleI: PROC[context: Context, x, y, w, h: INTEGER]; Class: TYPE ~ REF ClassRep; ClassRep: TYPE ~ RECORD[ deviceType: ATOM, Init: PROC [context: Context, info: REF] _, DoSave: PROC[context: Context, body: PROC] _, DoSaveAll: PROC[context: Context, body: PROC] _, SetPriorityImportant: PROC[context: Context, priorityImportant: BOOL] _, ConcatT: PROC[context: Context, m: Transformation] _, ScaleT: PROC[context: Context, s: REAL] _, Scale2T: PROC[context: Context, sx, sy: REAL] _, RotateT: PROC[context: Context, a: REAL] _, TranslateT: PROC[context: Context, x, y: REAL] _, Move: PROC[context: Context] _, Trans: PROC[context: Context] _, SetXY: PROC[context: Context, x, y: REAL] _, SetXYI: PROC[context: Context, x, y: INTEGER] _, SetXYRel: PROC[context: Context, x, y: REAL] _, SetXYRelI: PROC[context: Context, x, y: INTEGER] _, MaskFill: PROC[context: Context, pathProc: PathProc, pathData: REF] _, MaskStroke: PROC[context: Context, pathProc: PathProc, pathData: REF] _, MaskStrokeClosed: PROC[context: Context, pathProc: PathProc, pathData: REF] _, MaskVector: PROC[context: Context, x1, y1, x2, y2: REAL] _, MaskVectorI: PROC[context: Context, x1, y1, x2, y2: INTEGER] _, MaskRectangle: PROC[context: Context, x, y, w, h: REAL] _, MaskRectangleI: PROC[context: Context, x, y, w, h: INTEGER] _, StartUnderline: PROC[context: Context] _, MaskUnderline: PROC[context: Context, dy, h: REAL] _, MaskUnderlineI: PROC[context: Context, dy, h: INTEGER] _, MaskPixel: PROC[context: Context, pa: PixelArray] _, SetGray: PROC[context: Context, f: REAL] _, SetColor: PROC[context: Context, color: Color] _, SetSampledColor: PROC[context: Context, pa: PixelArray, pixelT: Transformation, colorOperator: ATOM] _, SetSampledBlack: PROC[context: Context, pa: PixelArray, pixelT: Transformation, transparent: BOOL] _, ClipOutline: PROC[context: Context, pathProc: PathProc, pathData: REF] _, ExcludeOutline: PROC[context: Context, pathProc: PathProc, pathData: REF] _, ClipRectangle: PROC[context: Context, x, y, w, h: REAL] _, ClipRectangleI: PROC[context: Context, x, y, w, h: INTEGER] _, ExcludeRectangle: PROC[context: Context, x, y, w, h: REAL] _, ExcludeRectangleI: PROC[context: Context, x, y, w, h: INTEGER] _, SetFont: PROC[context: Context, font: FONT] _, ShowChar: PROC[context: Context, char: CHAR] _, ShowCharacters: PROC[context: Context, characters: REF, start: INT, length: INT] _, CorrectMask: PROC[context: Context] _, CorrectSpace: PROC[context: Context, x, y: REAL] _, SetCorrectMeasure: PROC[context: Context, x, y: REAL] _, SetCorrectTolerance: PROC[context: Context, x, y: REAL] _, SetCorrectShrink: PROC[context: Context, correctShrink: REAL] _, SetAmplifySpace: PROC[context: Context, amplifySpace: REAL] _, Space: PROC[context: Context, x: REAL] _, SpaceI: PROC[context: Context, x: INTEGER] _, Correct: PROC[context: Context, body: PROC] _ ]; END.  NewImagerImpl.mesa Michael Plass, February 20, 1984 9:15:15 am PST Doug Wyatt, June 28, 1984 5:05:02 pm PDT Imager contexts Creation For making a new context. The data field is optional; its type is dependent on the deviceType. Errors State The state of the imager is contained in two places: the page image, and the imager variables. The variables differ in their treatment by the Do-operators below: the non-persistent variables are restored by DoSave; all variables are restored by DoSaveAll. Priority Set the current value of priorityImportant. Property lists Transformations Creating transformations Applying transformations The current transformation [[pixelsToMeters ??]] Mask operators Trajectories Create a new trajectory whose lp is p. Extend t with a straight line segment. The lp of the result is p. LineToX is equivalent to t.LineTo[x, t.LastPoint.y]. LineToY is equivalent to t.LineTo[t.LastPoint.x, y]. Extend t with a cubic curve segment. The lp of the result is p3. Let p0=t.LastPoint. The curve segment is defined by Bezier control points p0, p1, p2, p3. It starts at p0, tangent to the line joining p0 and p1, and ends at p3, tangent to the line joining p2 and p3. It is bounded by the quadrilateral with vertices p0, p1, p2, p3. Extend t with a segment of a conic section. The lp of the result is p2. Let p0=t.LastPoint. Let m be the midpoint of the line joining p0 and p2. Let p be the point on the line joining m and p1 such that Length[m, p]/Length[m, p1] = r. The curve segment starts at p0, passes through p, and ends at p2. It is a line if r=0; an ellipse if 0J˜J˜—šžœœœ˜;J˜J˜J˜——™šž œœœ ˜=J˜J˜—šž œœœ ˜@J˜J˜J˜—šžœœœ ˜DJ˜J˜—šžœœœ ˜GJ˜J˜J™——™J™šœ Οc&˜FJ˜—šžœœ)˜6J˜"J˜J˜—šžœœœ˜+Jšœ!˜!J˜J™—šžœœœ˜1Jšœ'˜'J˜J˜—šžœœœ˜,Jšœ"˜"J˜J˜—šž œœœ˜2Jšœ(˜(J˜J™J™—šžœœ˜ Jšœ˜J˜J™—šžœœ˜!Jšœ˜J˜J˜———šœ™™ J™šžœœ œ˜.J˜J˜—šžœœœœ ˜,Jšœœœ˜$J™&J™—Jšžœœœ ˜:šžœœœœ ˜;Jšœœœ˜&J™BJ™—Jšžœœœœ ˜:šžœœœœ ˜:J™4J™4J™—Jšžœœ"œ ˜Dšžœœ(œœ ˜NJšœœœ,˜=™AJšœŒ™Œ—J˜—Jšžœœ!œœ ˜Iš žœœ œœœ ˜OJšœœœ%˜6šœH™HJšœϊ™ϊ—J˜—Jšžœœœ ˜>šžœœ œœ ˜DJšœœœ ˜1šœ:™:JšœΕ™Ε—J˜—šœ œœ™Jšœœ™ Jšœœœ™Jšœœœ™Jšœ œœ™,Jšœ œœœ™-Jšœœœ™!Jšœ™J™—šž œ˜šœœ˜šœ˜J˜šœœœ˜3J˜šœœ˜Jšœœœ ˜BJšœœ#˜)Jšœœ1˜7Jšœœ0˜6Jšœœ'˜-Jšœœ ˜$—Jšœ˜—J˜—Jšœœ ˜.—J˜J˜—šžœ˜šœœ˜šœ˜šœ(œœ˜Jšœ6˜6J˜J˜—šžœœœ˜"Jšœ0œœ˜>Jšœ<˜J˜—š žœœœœœœ˜5J˜J˜—šžœœœ˜,J˜—Jš žœœœœœ˜?šžœœ-˜AJš œœœœœœœ˜:J˜—šžœœ!œ˜J˜—Jšžœœœ˜'šžœœœ˜*Jšœœ&˜.—J˜——™ šœ œ˜*J˜—šžœœ˜Jš œ œœœœœœ˜:Jšœ,˜/Jšœœ˜šœ™Jšœ<™Jšžœœ˜)Jšž œœœ˜5Jšžœœœ˜9Jšž œœ%˜4Jšžœœœ˜+Jšžœœ#˜1JšžœœJœ˜gJšžœœHœ˜eJšž œœ1œ˜IJšžœœ1œ˜LJšž œœœ˜:Jšžœœœ˜>Jšžœœœ˜=Jšžœœœ˜AJšžœœœ˜.Jšžœœœ˜/Jš žœœœ œ œ˜SJšž œœ˜&Jšž œœœ˜3Jšžœœœ˜8Jšžœœœ˜:Jšžœœ"œ˜@Jšžœœ!œ˜>Jšžœœœ˜)Jšžœœœ˜-Jšžœœœ˜-J˜J˜—J™—Jšœ˜—…—3]+