CDPressPlotImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Last Edited by: Jacobi, November 1, 1984 8:50:32 am PST
Last Edited by: Jacobi, September 23, 1985 6:14:01 pm PDT
DIRECTORY
CD,
CDBasics,
CDCommandOps,
CDExtras,
CDMenus,
CDOps,
CDProperties,
CDSequencer,
Imager,
ImagerPress,
IO,
Real,
Rope,
TerminalIO;
CDPressPlotImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDCommandOps, CDExtras, CDMenus, CDOps, CDProperties, CDSequencer, Imager, ImagerPress, IO, Real, Rope, TerminalIO =
BEGIN
fileNameBase: Rope.ROPE ← "///temp/temp";
abortPlot: REF BOOL = NEW[BOOLFALSE];
pageW: REAL ← 0.216; -- meter (72*8.5-2; points)
pageH: REAL ← 0.277; -- meter (72*11.0; points)
standardScale: REAL ← Imager.metersPerPoint/2;
contextFilter: REF CD.ContextFilter = NEW[CD.ContextFilter←ALL[Imager.black]];
normalsetUp: BOOLFALSE;
ResetContextFilter: PROC [ignoreProperties: BOOLTRUE] =
BEGIN
normalsetUp ← ignoreProperties;
FOR layer: CD.Layer IN CD.Layer DO
IF ignoreProperties THEN contextFilter[layer] ← Imager.black
ELSE contextFilter[layer] ← NIL;
CDProperties.PutPropOnLayer[layer, $CDxPressPlot, NIL];
ENDLOOP;
contextFilter[CD.backGround] ← NIL;
END;
SetUpContextFilter: PROC [] =
BEGIN
normalsetUp ← FALSE;
FOR layer: CD.Layer IN CD.Layer DO
IF CDProperties.GetPropFromLayer[layer, $CDxPressPlot]=$doit THEN
contextFilter[layer] ← Imager.black
ELSE contextFilter[layer] ← NIL;
ENDLOOP;
contextFilter[CD.backGround] ← NIL;
END;
HardCopyCommand: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["HardCopy\n"];
abortPlot^ ← FALSE;
[] ← CDCommandOps.CallWithResource[
proc: ProtectedHardCopy,
comm: comm,
resource: $CDSimplePlotImpl,
abortFlag: abortPlot
];
END;
ToImagerRect: PROC [r: CD.Rect] RETURNS [Imager.Rectangle] =
BEGIN
RETURN [[x: r.x1, y: r.y1, w: r.x2-r.x1, h: r.y2-r.y1]]
END;
ProtectedHardCopy: PROC [comm: CDSequencer.Command] =
--not re-entrant: using a global abort flag (abortPlot)
BEGIN
nW: INT ← 1; --number of vertical stripes
nH: INT ← 1; --number of horizontal stripes
borderW, borderH: REAL; --border of page, in meters
insidePageW, insidePageH: REAL; --what fits in a page in meters
designPageW, designPageH: CD.Number; --what fits in a page in designnumbers
context: Imager.Context;
dr: CD.DrawRef;
clip: CD.Rect;
scale: REAL;
designextent: CD.Number𡤀
PrinterT: PROC [comm: CDSequencer.Command] RETURNS [pt: ImagerPress.PrinterType] =
BEGIN
SELECT comm.a FROM
$PressPlotSpruce => {pt ← spruce; TerminalIO.WriteRope[" spruce\n"]};
$PressPlotPress => {pt ← press; TerminalIO.WriteRope[" press\n"]};
ENDCASE => {TerminalIO.WriteRope[" unknown printer\n"]; ERROR ABORTED};
END;
PlotPages: PROC [] =
--uses nW, nH, context, scale, designPageW, designPageH, borderW, borderH, comm, dr
BEGIN
FOR nX: INT IN [0..nW) DO
IF abortPlot^ THEN EXIT;
FOR nY: INT IN [0..nH) DO
r: CD.Rect;
IF abortPlot^ THEN EXIT;
IF nX#0 OR nY#0 THEN ImagerPress.NewPage[context];
r.x1 ← clip.x1+nX*designPageW;
r.x2 ← MAX[r.x1+designPageW, clip.x2];
r.y1 ← clip.y1+nY*designPageH;
r.y2 ← MAX[r.y1+designPageH, clip.y2];
dr.interestClip ← r;
Imager.TranslateT[context, [borderW, borderH]];
Imager.ScaleT[context, scale];
Imager.TranslateT[context, [-r.x1, -r.y1]];
Imager.ClipRectangle[context, ToImagerRect[r]];
CDOps.DrawDesign[comm.design, dr];
ENDLOOP;
ENDLOOP;
END;
SetUpVaryingScaling: PROC [clip: CD.Rect] =
--sets up nW, nH, insidePageW, insidePageH, designPageW, designPageH, scale
BEGIN
borderH ← borderW ← 0;
nW ← TerminalIO.RequestInt["How many rows? (0 for single page) >"];
IF nW<0 OR nW>20 THEN {
TerminalIO.WriteRope[" to bad\n"];
ERROR ABORTED
};
IF nW=0 OR TerminalIO.Confirm["border ?"] THEN
borderH ← borderW ← 0.02;
insidePageW ← pageW-2*borderW;
insidePageH ← pageH-2*borderH;
IF nW=0 THEN {
--single page
nH ← 1;
nW ← 1;
designPageW ← (clip.x2-clip.x1);
designPageH ← (clip.y2-clip.y1);
scale ← MIN[insidePageW/designPageW, insidePageH/designPageH];
--we do not care designPageW or designPageH beeing to large
}
ELSE {
--multiple pages
designPageW ← (clip.x2-clip.x1)/nW+1;
designPageH ← Real.Fix[insidePageH*((designPageW-1.0)/insidePageW)];
scale ← insidePageW/designPageW;
nH ← (clip.y2-clip.y1+designPageH-1)/designPageH;
}
END;

SetUpFixedScaling
: PROC [clip: CD.Rect] =
--sets up nW, nH, insidePageW, insidePageH, designPageW, designPageH, scale
BEGIN
borderH ← borderW ← 0;
insidePageW ← pageW-2*borderW;
insidePageH ← pageH-2*borderH;
scale ← standardScale;
designPageW ← Real.Round[insidePageW/scale];
designPageH ← Real.Round[insidePageH/scale];
nH ← (clip.y2-clip.y1+designPageH-1)/designPageH;
nW ← (clip.x2-clip.x1+designPageW-1)/designPageW;
END;
SetUp: PROC [] =
BEGIN
GetClipRect: PROC [comm: CDSequencer.Command] =
BEGIN
SELECT TerminalIO.RequestSelection["Plot", LIST["standard scale all", "standard scale rect", "all", "rect"]] FROM
1 => {
fixedScale ← TRUE;
clip ← CDExtras.BoundingBox[comm.design];
TerminalIO.WriteRope["plot all; standard scale\n"];
};
2 => {
fixedScale ← TRUE;
clip ← CDBasics.ToRect[comm.pos, comm.sPos];
TerminalIO.WriteRope["plot rectangle; standard scale\n"];
};
3 => {
fixedScale ← FALSE;
clip ← CDExtras.BoundingBox[comm.design];
TerminalIO.WriteRope["plot all; adjust scale\n"];
};
4 => {
fixedScale ← FALSE;
clip ← CDBasics.ToRect[comm.pos, comm.sPos];
TerminalIO.WriteRope["plot rectangle; adjust scale\n"];
};
ENDCASE => ERROR ABORTED;
END;
fixedScale: BOOLFALSE;
GetClipRect[comm];
IF fixedScale THEN SetUpFixedScaling[clip]
ELSE SetUpVaryingScaling[clip];
TerminalIO.WriteRope[IO.PutFR[" printing %01g rows and %01g columns\n", IO.int[nW], IO.int[nH]]];
END;
printerType: ImagerPress.PrinterType ← PrinterT[comm];
fileName: Rope.ROPE ← Rope.Cat[fileNameBase, ".press"];
warningCount: INT ← 0;
IF ~normalsetUp THEN {
TerminalIO.WriteRope["** SPECIAL COLORS\n"];
SetUpContextFilter[]
};
SetUp[];
context ← ImagerPress.SimpleCreate[fileName, printerType];
dr ← CD.CreateDrawRef[comm.design, context];
dr.minimalSize ← 0;
dr.stopFlag ← abortPlot;
dr.contextFilter ← contextFilter;
ImagerPress.DoWithWarnings[context, PlotPages ! ImagerPress.Warning => {
TerminalIO.WriteRope["!"];
IF warningCount < 25 THEN {
warningCount ← warningCount+1;
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[explanation];
TerminalIO.WriteLn[];
};
RESUME
}];
ImagerPress.Close[context];
TerminalIO.WriteRope[IO.PutFR[" ""%01g"" created\n", IO.rope[fileName]]];
IF ~abortPlot^ THEN TerminalIO.WriteRope[" done\n"];
END;
Init: PROC = {
ResetContextFilter[ignoreProperties: TRUE];
CDSequencer.ImplementCommand[a: $PressPlotSpruce, p: HardCopyCommand, queue: doQueue];
CDSequencer.ImplementCommand[a: $PressPlotPress, p: HardCopyCommand, queue: doQueue];
CDMenus.CreateEntry[menu: $HardCopyMenu, entry: "b&w spruce format (unreliable)", key: $PressPlotSpruce];
CDMenus.CreateEntry[menu: $HardCopyMenu, entry: "b&w press (unreliable)", key: $PressPlotPress];
TerminalIO.WriteRope["HardCopy loaded\n"];
};
Init[];
END.