GGFromImagerImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, October 19, 1985 3:55:31 pm PDT
DIRECTORY
GGFromImager, GGModelTypes, GGObjects, GGSegment, Imager, ImagerBackdoor, ImagerFont, ImagerFontPrivate, ImagerPath, ImagerPrivate, ImagerRasterPrivate, ImagerState, ImagerTransformation, Rope, Vector2;
GGFromImagerImpl: CEDAR PROGRAM
IMPORTS GGObjects, GGSegment, Imager, ImagerPath, ImagerRasterPrivate, ImagerState, ImagerTransformation
EXPORTS GGFromImager, Imager, ImagerFont
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Class: TYPE ~ REF ClassRep;
ClassRep: PUBLIC TYPE ~ ImagerPrivate.ClassRep; -- export to Imager.ClassRep
Context: TYPE ~ Imager.Context;
Color: TYPE ~ Imager.Color;
ColorOperator: TYPE ~ Imager.ColorOperator;
Clipper: TYPE ~ ImagerBackdoor.Clipper;
Font: TYPE ~ ImagerFont.Font;
PathProc: TYPE ~ ImagerPath.PathProc;
PixelArray: TYPE ~ Imager.PixelArray;
Rectangle: TYPE ~ ImagerTransformation.Rectangle;
State: TYPE ~ REF StateRep;
StateRep: PUBLIC TYPE ~ ImagerState.StateRep;
Transformation: TYPE ~ ImagerTransformation.Transformation;
VEC: TYPE ~ Vector2.VEC;
XChar: TYPE ~ ImagerFont.XChar;
XStringProc: TYPE ~ ImagerFont.XStringProc;
FontImpl: TYPE ~ ImagerFontPrivate.FontImpl;
FontImplRep: PUBLIC TYPE ~ ImagerFontPrivate.FontImplRep; -- export to to ImagerFont
Warning: PUBLIC SIGNAL [context: Context, code: ATOM, message: ROPE] ~ CODE;
Data: TYPE ~ REF DataRep;
DataRep: TYPE ~ RECORD [
scene: GGModelTypes.Scene
];
Create: PROC RETURNS [Context] ~ {
data: Data ~ NEW[DataRep ← [scene: GGObjects.CreateScene[]]];
state: State ~ NEW[StateRep ← []];
state.T ← ImagerTransformation.Scale[72/0.0254];
state.color ← Imager.black;
RETURN[NEW[Imager.ContextRep ← [class: gargoyleClass, state: state, data: data]]];
};
Capture: PUBLIC PROC [action: PROC [Context]] RETURNS [GGModelTypes.Scene] ~ {
context: Context ~ Create[];
action[context];
WITH context.data SELECT FROM data: Data => RETURN [data.scene]; ENDCASE => ERROR;
};
ProcessStateChanges: PUBLIC PROC [context: Context] ~ {
state: State ~ context.state;
changed: ImagerState.ChangeFlags ~ state.changed;
state.changed ← ImagerState.notChanged;
IF changed.clipper AND state.clipper # NIL THEN SIGNAL Warning[context, $Clipping, "NotImplemented: Clipping"];
};
MyShow: PROC[context: Context, string: XStringProc, xrel: BOOL] ~ {
SIGNAL Warning[context, $Show, "NotImplemented: Show"];
};
OutlineFromPath: PROC[path: PathProc, m: Transformation, closed: BOOL] RETURNS [GGModelTypes.Outline] ~ {
curOutline: GGModelTypes.Outline ← NIL;
curTraj: GGModelTypes.Traj ← NIL;
curSeg: GGModelTypes.Segment ← NIL;
lp: VEC ← [0,0];
Finish: PROC ~ {
IF curTraj # NIL THEN {
IF curSeg # NIL THEN {
IF closed THEN GGObjects.CloseWithSegment[curTraj, curSeg, lo]
ELSE [] ← GGObjects.AddSegment[curTraj, hi, curSeg, lo];
curSeg ← NIL;
};
IF curOutline = NIL THEN curOutline ← GGObjects.OutlineFromTraj[curTraj]
ELSE SIGNAL Warning[NIL, $Holey, "NotImplemented: objects with holes"];
-- GGObjects.AddHoles[curOutline, LIST[GGObjects.OutlineFromTraj[curTraj]]];
curTraj ← NIL;
};
};
Move: PROC [p: VEC] ~ {
Finish[];
curTraj ← GGObjects.CreateTraj[[p.x, p.y]];
lp ← p;
};
Line: PROC [p1: VEC] ~ {
IF curSeg # NIL THEN [] ← GGObjects.AddSegment[curTraj, hi, curSeg, lo];
curSeg ← GGSegment.MakeLine[[lp.x, lp.y], [p1.x, p1.y]];
lp ← p1;
};
Curve: PROC [p1, p2, p3: VEC] ~ {
IF curSeg # NIL THEN [] ← GGObjects.AddSegment[curTraj, hi, curSeg, lo];
curSeg ← GGSegment.MakeBezier[[lp.x, lp.y], [p1.x, p1.y], [p2.x, p2.y], [p3.x, p3.y]];
lp ← p3;
};
Conic: PROC [p1, p2: VEC, r: REAL] ~ {
IF curSeg # NIL THEN [] ← GGObjects.AddSegment[curTraj, hi, curSeg, lo];
curSeg ← GGSegment.MakeConic[[lp.x, lp.y], [p1.x, p1.y], [p2.x, p2.y], r];
lp ← p2;
};
Arc: PROC [p1, p2: VEC] ~ {
IF curSeg # NIL THEN [] ← GGObjects.AddSegment[curTraj, hi, curSeg, lo];
curSeg ← GGSegment.MakeArc[[lp.x, lp.y], [p1.x, p1.y], [p2.x, p2.y]];
lp ← p2;
};
ImagerPath.Transform[path, m, Move, Line, Curve, Conic, Arc];
Finish[];
RETURN [curOutline];
};
MyMaskFill: PROC[context: Context, path: PathProc, parity: BOOL] ~ {
data: Data ~ NARROW[context.data];
state: State ~ context.state;
IF state.changed#ImagerState.notChanged THEN ProcessStateChanges[context];
IF parity THEN SIGNAL Warning[context, $ParityFill, "NotImplemented: ParityFill"];
CHECKED {
outline: GGModelTypes.Outline ← OutlineFromPath[path, state.T, TRUE];
GGObjects.SetFillColor[outline, state.color];
GGObjects.AddOutline[data.scene, outline, -1];
};
};
MyMaskStroke: PROC[context: Context, path: PathProc, closed: BOOL] ~ {
data: Data ~ NARROW[context.data];
state: State ~ context.state;
IF state.changed#ImagerState.notChanged THEN ProcessStateChanges[context];
IF NOT closed THEN {
outline: GGModelTypes.Outline ← OutlineFromPath[path, state.T, FALSE];
GGObjects.SetLineEnds[outline, VAL[CARDINAL[state.np.strokeEnd]]];
GGObjects.AddOutline[data.scene, outline, -1];
};
};
MyMaskRectangle: PROC[context: Context, r: Rectangle] ~ {
path: PathProc ~ {
moveTo[[r.x, r.y]]; lineTo[[r.x+r.w, r.y]];
lineTo[[r.x+r.w, r.y+r.h]]; lineTo[[r.x, r.y+r.h]]
};
MyMaskFill[context, path, FALSE];
};
MyMaskRectangleI: PROC[context: Context, x, y, w, h: INTEGER] ~ {
MyMaskRectangle[context, [x, y, w, h]];
};
MyMaskVector: PROC[context: Context, p1, p2: VEC] ~ {
path: PathProc ~ {moveTo[p1]; lineTo[p2]};
MyMaskStroke[context, path, FALSE];
};
MyMaskPixel: PROC[context: Context, pa: PixelArray] ~ {
SIGNAL Warning[context, $MaskPixel, "NotImplemented: MaskPixel"];
};
MyMaskBits: PROC[context: Context, base: LONG POINTER, wordsPerLine: NAT,
sMin, fMin, sSize, fSize: NAT, tx, ty: INTEGER] ~ {
SIGNAL Warning[context, $MaskBits, "NotImplemented: MaskBits"];
};
MyDrawBits: PROC[context: Context, base: LONG POINTER, wordsPerLine: NAT,
sMin, fMin, sSize, fSize: NAT, tx, ty: INTEGER] ~ {
SIGNAL Warning[context, $DrawBits, "NotImplemented: DrawBits"];
};
MyGetBounds: PROC[context: Context] RETURNS[Rectangle] ~ {
ERROR Imager.Error[[$NotImplemented, "NotImplemented: GetBounds"]]
};
gargoyleClass: Class ~ NEW[ClassRep ← [
type: $Gargoyle,
DoSave: ImagerState.StateDoSave,
SetInt: ImagerState.StateSetInt,
SetReal: ImagerState.StateSetReal,
SetT: ImagerState.StateSetT,
SetFont: ImagerState.StateSetFont,
SetColor: ImagerState.StateSetColor,
SetClipper: ImagerState.StateSetClipper,
SetStrokeDashes: ImagerState.StateSetStrokeDashes,
GetInt: ImagerState.StateGetInt,
GetReal: ImagerState.StateGetReal,
GetT: ImagerState.StateGetT,
GetFont: ImagerState.StateGetFont,
GetColor: ImagerState.StateGetColor,
GetClipper: ImagerState.StateGetClipper,
GetStrokeDashes: ImagerState.StateGetStrokeDashes,
ConcatT: ImagerState.StateConcatT,
Scale2T: ImagerState.StateScale2T,
RotateT: ImagerState.StateRotateT,
TranslateT: ImagerState.StateTranslateT,
Move: ImagerState.StateMove,
SetXY: ImagerState.StateSetXY,
SetXYRel: ImagerState.StateSetXYRel,
Show: MyShow,
ShowText: ImagerRasterPrivate.RasterShowText,
StartUnderline: ImagerState.StateStartUnderline,
MaskUnderline: ImagerState.StateMaskUnderline,
CorrectMask: ImagerState.StateCorrectMask,
CorrectSpace: ImagerState.StateCorrectSpace,
Space: ImagerState.StateSpace,
SetCorrectMeasure: ImagerState.StateSetCorrectMeasure,
SetCorrectTolerance: ImagerState.StateSetCorrectTolerance,
Correct: ImagerState.StateCorrect,
DontCorrect: ImagerState.StateDontCorrect,
SetGray: ImagerState.StateSetGray,
SetSampledColor: ImagerState.StateSetSampledColor,
SetSampledBlack: ImagerState.StateSetSampledBlack,
MaskFill: MyMaskFill,
MaskStroke: MyMaskStroke,
MaskRectangle: MyMaskRectangle,
MaskRectangleI: MyMaskRectangleI,
MaskVector: MyMaskVector,
MaskPixel: MyMaskPixel,
MaskBits: MyMaskBits,
DrawBits: MyDrawBits,
Clip: ImagerState.StateClip,
ClipRectangle: ImagerState.StateClipRectangle,
ClipRectangleI: ImagerState.StateClipRectangleI,
GetCP: ImagerState.StateGetCP,
GetBoundingRectangle: MyGetBounds,
propList: NIL
]];
END.