<<>> <> <> <> <> <> <> DIRECTORY Imager, Commander, FS, IO, ImagerBackdoor, ImagerInterpress, ImagerPixelArray, Rope, SF, ViewerPrivate, ViewersWorld, ViewersWorldInstance, Snapshot; SnapshotImpl: CEDAR PROGRAM IMPORTS Imager, Commander, FS, IO, ImagerBackdoor, ImagerInterpress, ImagerPixelArray, ViewerPrivate, ViewersWorld, ViewersWorldInstance EXPORTS Snapshot ~ BEGIN ROPE: TYPE ~ Rope.ROPE; <> <> Snapshot: PUBLIC PROC [context: Imager.Context, screen: ViewerPrivate.Screen, f0, s0: NAT ¬ 0, f1, s1: NAT ¬ NAT.LAST] ~ { action: PROC [pixelMap: Imager.PixelMap] = { pa: Imager.PixelArray ¬ ImagerPixelArray.FromPixelMap[pixelMap: pixelMap, box: box, scanMode: [slow: down, fast: right], immutable: TRUE]; Imager.DrawSampledColor[context: context, pa: pa, colorOperator: op]; }; box: SF.Box ~ [[MIN[s0, s1], MIN[f0, f1]], [MAX[s0, s1], MAX[f0, f1]]]; screenContext: Imager.Context ¬ ViewerPrivate.CreateContext[screen]; op: Imager.ColorOperator ¬ ImagerBackdoor.GetBufferColorOperator[screenContext]; ImagerBackdoor.AccessBufferRectangle[screenContext, action, [f0, s0, f1, s1] ]; }; SnapshotIP: PROC [fileName: ROPE] ~ { interpress: ImagerInterpress.Ref ¬ ImagerInterpress.Create[fileName]; Paint: PROC [context: Imager.Context] ~ { width, height: NAT _ 0; [width, height] _ ViewersWorld.GetSize[ViewersWorldInstance.GetWorld[]]; Imager.SetPriorityImportant[context, TRUE]; Snapshot[context: context, screen: main, s0: 0, f0: 0, s1: height, f1: width]; }; ImagerInterpress.DoPage[self: interpress, action: Paint, scale: 0.0254/72]; ImagerInterpress.Close[interpress]; }; FindFullName: PROC [inputName: ROPE] RETURNS [ROPE] ~ { fullFName: ROPE ¬ NIL; fullFName ¬ FS.FileInfo[inputName].fullFName; RETURN [fullFName] }; CmdTokenBreak: PROC [char: CHAR] RETURNS [IO.CharClass] = { IF char = '_ THEN RETURN [break]; IF char = ' OR char = '\t OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr]; RETURN [other]; }; GetCmdToken: PROC [stream: IO.STREAM] RETURNS [rope: ROPE] = { rope ¬ NIL; rope ¬ stream.GetTokenRope[CmdTokenBreak ! IO.EndOfStream => CONTINUE].token; }; SnapshotCommand: Commander.CommandProc ~ { stream: IO.STREAM ¬ IO.RIS[cmd.commandLine]; outputName: ROPE ¬ GetCmdToken[stream]; IF outputName = NIL THEN {cmd.out.PutRope[cmd.procData.doc]; RETURN}; SnapshotIP[outputName]; outputName ¬ FindFullName[outputName]; cmd.out.PutRope[outputName]; cmd.out.PutRope[" written.\n"]; }; Commander.Register["Snapshot", SnapshotCommand, "Make an Interpress master from the screen. Specify output IP file name.\n"]; END.