DIRECTORY
IIColorDefs USING [Color],
IIDevice USING [BoxProc, CharMask, Class, ClassRep, Device, DeviceBox, DeviceRep, HalftoneParameters, RunProc, Transformation],
IIRaster USING [Ambusher];
~
BEGIN
OPEN IIDevice;
Ambusher:
TYPE ~ IIRaster.Ambusher;
MakeClass:
PROC [old: Class]
RETURNS [new: Class] ~ {
new ←
NEW[ClassRep ← [
type: $Ambush,
SetColor: AmbushSetColor,
SetPriority: AmbushSetPriority,
SetHalftone: AmbushSetHalftone,
MaskRuns: AmbushMaskRuns,
MaskBoxes: AmbushMaskBoxes,
MaskBits: AmbushMaskBits,
DrawBits: AmbushDrawBits,
MoveBoxes: AmbushMoveBoxes,
MaskChar: AmbushMaskChar
]];
IF old.SetColor = NIL THEN new.SetColor ← NIL;
IF old.SetPriority = NIL THEN new.SetPriority ← NIL;
IF old.SetHalftone = NIL THEN new.SetHalftone ← NIL;
IF old.MaskRuns = NIL THEN new.MaskRuns ← NIL;
IF old.MaskBoxes = NIL THEN new.MaskBoxes ← NIL;
IF old.MaskBits = NIL THEN new.MaskBits ← NIL;
IF old.DrawBits = NIL THEN new.DrawBits ← NIL;
IF old.MoveBoxes = NIL THEN new.MoveBoxes ← NIL;
IF old.MaskChar = NIL THEN new.MaskChar ← NIL;
};
AmbushDevice:
PUBLIC
PROC [ambusher: Ambusher]
RETURNS [Device] ~ {
RETURN[
NEW[IIDevice.DeviceRep ← [class: MakeClass[ambusher.device.class],
box: ambusher.device.box,
surfaceToDevice: ambusher.device.surfaceToDevice,
surfaceUnitsPerInch: ambusher.device.surfaceUnitsPerInch,
surfaceUnitsPerPixel: ambusher.device.surfaceUnitsPerPixel,
data: ambusher]]];
};
AmbushSetColor:
PROC[device: Device, color: IIColorDefs.Color, viewToDevice: Transformation] ~ {
data: Ambusher ~ NARROW[device.data];
data.device.class.SetColor[data.device, color, viewToDevice];
};
AmbushSetPriority:
PROC[device: Device, priorityImportant:
BOOL] ~ {
data: Ambusher ~ NARROW[device.data];
data.device.class.SetPriority[data.device, priorityImportant];
};
AmbushSetHalftone:
PROC[device: Device, halftone: HalftoneParameters] ~ {
data: Ambusher ~ NARROW[device.data];
data.device.class.SetHalftone[data.device, halftone];
};
AmbushMaskRuns:
PROC[device: Device, bounds: DeviceBox, runs:
PROC[RunProc]] ~ {
data: Ambusher ~ NARROW[device.data];
action: PROC ~ {data.device.class.MaskRuns[data.device, bounds, runs]};
data.maskProc[data, bounds, action];
};
AmbushMaskBoxes:
PROC[device: Device, bounds: DeviceBox, boxes:
PROC[BoxProc]] ~ {
data: Ambusher ~ NARROW[device.data];
action: PROC ~ {data.device.class.MaskBoxes[data.device, bounds, boxes]};
data.maskProc[data, bounds, action];
};
AmbushMaskBits:
PROC[device: Device, srcBase:
LONG
POINTER, srcWordsPerLine:
NAT,
ts, tf:
INTEGER, boxes:
PROC[BoxProc]] ~ {
data: Ambusher ~ NARROW[device.data];
bb: DeviceBox ← [smin: CARDINAL.LAST, fmin: CARDINAL.LAST, smax: 0, fmax: 0];
bbBox:
PROC [b: DeviceBox] ~ {
IF b.smin < bb.smin THEN bb.smin ← b.smin;
IF b.fmin < bb.fmin THEN bb.fmin ← b.fmin;
IF b.smax > bb.smax THEN bb.smax ← b.smax;
IF b.fmax > bb.fmax THEN bb.fmax ← b.fmax;
};
action: PROC ~ {data.device.class.MaskBits[data.device, srcBase, srcWordsPerLine, ts, tf, boxes]};
boxes[bbBox];
IF bb.smin < bb.smax THEN data.maskProc[data, bb, action];
};
AmbushDrawBits:
PROC[device: Device, srcBase:
LONG
POINTER, srcWordsPerLine:
NAT,
ts, tf:
INTEGER, boxes:
PROC[BoxProc]] ~ {
data: Ambusher ~ NARROW[device.data];
bb: DeviceBox ← [smin: CARDINAL.LAST, fmin: CARDINAL.LAST, smax: 0, fmax: 0];
bbBox:
PROC [b: DeviceBox] ~ {
IF b.smin < bb.smin THEN bb.smin ← b.smin;
IF b.fmin < bb.fmin THEN bb.fmin ← b.fmin;
IF b.smax > bb.smax THEN bb.smax ← b.smax;
IF b.fmax > bb.fmax THEN bb.fmax ← b.fmax;
};
action: PROC ~ {data.device.class.DrawBits[data.device, srcBase, srcWordsPerLine, ts, tf, boxes]};
boxes[bbBox];
IF bb.smin < bb.smax THEN data.maskProc[data, bb, action];
};
AmbushMoveBoxes:
PROC[device: Device, ts, tf:
INTEGER, boxes:
PROC[BoxProc]] ~ {
data: Ambusher ~ NARROW[device.data];
bb: DeviceBox ← [smin: CARDINAL.LAST, fmin: CARDINAL.LAST, smax: 0, fmax: 0];
bbBox:
PROC [b: DeviceBox] ~ {
IF b.smin < bb.smin THEN bb.smin ← b.smin;
IF b.fmin < bb.fmin THEN bb.fmin ← b.fmin;
IF b.smax > bb.smax THEN bb.smax ← b.smax;
IF b.fmax > bb.fmax THEN bb.fmax ← b.fmax;
IF NAT[NAT[b.smin] - ts] < bb.smin THEN bb.smin ← b.smin - ts;
IF NAT[NAT[b.fmin] - tf] < bb.fmin THEN bb.fmin ← b.fmin - tf;
IF NAT[NAT[b.smax] - ts] > bb.smax THEN bb.smax ← b.smax - ts;
IF NAT[NAT[b.fmax] - tf] > bb.fmax THEN bb.fmax ← b.fmax - tf;
};
action: PROC ~ {data.device.class.MoveBoxes[data.device, ts, tf, boxes]};
boxes[bbBox];
IF bb.smin < bb.smax THEN data.maskProc[data, bb, action];
};
AmbushMaskChar:
PROC[device: Device, s, f:
INTEGER, mask: CharMask] ~ {
data: Ambusher ~ NARROW[device.data];
action: PROC ~ {data.device.class.MaskChar[data.device, s, f, mask]};
bb: DeviceBox ← [smin: s+mask.sMinBB, fmin: f+mask.fMinBB, smax: 0, fmax: 0];
bb.smax ← bb.smin + mask.sSizeBB;
bb.fmax ← bb.fmin + mask.fSizeBB;
data.maskProc[data, bb, action];
};