<> <> <> <> 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[BOOL_FALSE]; 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[[ doit: TRUE, color: Imager.black ]]]; normalsetUp: BOOL _ FALSE; ResetContextFilter: PROC [ignoreProperties: BOOL _ TRUE] = BEGIN normalsetUp _ ignoreProperties; FOR layer: CD.Layer IN CD.Layer DO contextFilter[layer].doit _ ignoreProperties; CDProperties.PutPropOnLayer[layer, $CDxPressPlot, NIL]; ENDLOOP; contextFilter[CD.backGround].doit _ FALSE; END; SetUpContextFilter: PROC [] = BEGIN normalsetUp _ FALSE; FOR layer: CD.Layer IN CD.Layer DO contextFilter[layer].doit _ (CDProperties.GetPropFromLayer[layer, $CDxPressPlot]=$doit) ENDLOOP; contextFilter[CD.backGround].doit _ FALSE; 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_0; 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.UserSaysYes["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: BOOL _ FALSE; 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.