CDSimplePressImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last Edited by: Jacobi, November 1, 1984 8:50:32 am PST
Last Edited by: Jacobi, November 5, 1984 2:04:01 pm PST
DIRECTORY
CD,
CDBasics,
CDCommandOps,
CDMenus,
CDOps,
CDSequencer,
Graphics,
GraphicsToPress,
IO,
Real,
Rope,
TerminalIO;
CDSimplePressImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDCommandOps, CDMenus, CDOps, CDSequencer, Graphics, GraphicsToPress, IO, Real, TerminalIO =
BEGIN
fileNameBase: Rope.ROPE ← "///temp/temp";
abortPlot: REF BOOL = NEW[BOOLFALSE];
debugContext: Graphics.Context←NIL;
pageW: REAL ← 72*8.5-2; --points 0.216; meter
pageH: REAL ← 72*11.0; --points 0.277; meter
contextFilter: REF CD.ContextFilter = NEW[CD.ContextFilter←ALL[[
doit: TRUE,
paintMode: Graphics.PaintMode[transparent],
color: Graphics.black
]]];
HardCopyCommand: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["HardCopy\n"];
IF CDCommandOps.CallWithResource[ProtectedHardCopy, comm, $CDSimplePressImpl, abortPlot].skipped THEN RETURN;
IF ~abortPlot^ THEN TerminalIO.WriteRope[" (needs a press printer!, spruce does not work)\ndone\n"];
END;
ToBox: PROC [r: CD.Rect] RETURNS [Graphics.Box] = INLINE {
RETURN [[xmin: r.x1, xmax: r.x2, ymin: r.y1, ymax: r.y2]]
};
For comparison: old one-page code
BEGIN
insidePageW: REAL = pageW-borderW;
insidePageH: REAL = pageH-borderH;
scale ← MIN[insidePageW/(clip.x2-clip.x1), insidePageH/(clip.y2-clip.y1)]
context.Translate[borderW, borderH];
context.Scale[scale, scale];
context.Translate[-clip.x1, -clip.y1];
context.ClipBox[ToBox[clip]];
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 device coordinates
insidePageW, insidePageH: REAL; --what fits in a page in device coordinates (points)
designPageW, designPageH: CD.DesignNumber; --what fits in a page in designnumbers
context: Graphics.Context;
dr: CD.DrawRef;
clip: CD.DesignRect = CDBasics.ToRect[comm.pos, comm.sPos];
scale: REAL;
abortPlot^ ← FALSE;
nW ← TerminalIO.RequestInt["How many rows? >"];
IF nW<1 OR nW>20 THEN {
TerminalIO.WriteRope[" to bad\n"];
RETURN
};
IF TerminalIO.UserSaysYes["border ?"] THEN borderH ← borderW ← 72*0.2
ELSE borderH ← borderW ← 0;
insidePageW ← pageW-borderW;
insidePageH pageH-borderH;
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;
TerminalIO.WriteRope[IO.PutFR[" printing %01g rows and %01g columns\n", IO.int[nW], IO.int[nH]]];
FOR nX: INT IN [0..nW) DO
FOR nY: INT IN [0..nH) DO
r: CD.DesignRect;
fileName: Rope.ROPEIO.PutFR["%01g%01g%01g%01g.press",
IO.rope[fileNameBase], IO.int[nX], IO.char['X], IO.int[nY]
];
IF abortPlot^ THEN RETURN;
r.x1 ← clip.x1+nX*designPageW;
r.x2 ← r.x1+designPageW;
r.y1 ← clip.y1+nY*designPageH;
r.y2 ← r.y1+designPageH;
IF debugContext#NIL THEN context ← debugContext
ELSE context ← GraphicsToPress.NewContext[fileName];
context.Translate[borderW, borderH];
context.Scale[scale, scale];
context.Translate[-r.x1, -r.y1];
context.ClipBox[ToBox[r]];
dr ← CD.NewNullDeviceDrawRef[comm.design, context];
dr.minimalSize ← 0;
dr.stopFlag ← abortPlot;
dr.contextFilter ← contextFilter;
dr.worldClip ← r;
CDOps.DrawDesign[comm.design, dr];
IF context#debugContext THEN GraphicsToPress.Close[context];
TerminalIO.WriteRope[IO.PutFR[" ""%01g"" created\n", IO.rope[fileName]]];
ENDLOOP;
ENDLOOP;
END;
Init: PROC = {
contextFilter[CD.backGround].doit ← FALSE;
CDSequencer.ImplementCommand[a~$HardCopy , p~HardCopyCommand];
CDMenus.CreateEntry[menu~$RectProgramMenu, entry~"HardCopy", key~$HardCopy];
TerminalIO.WriteRope["HardCopy loaded\n"];
};
Init[];
END.