<<>> <> <> <> <<>> DIRECTORY CGM, Commander, FileNames, FS, Imager, ImagerFont, ImagerInterpress, ImagerPixelArray, IO, Rope, -- MacPaint, MacPICT,-- InterpressFabricators; InterpressFabricatorsCommand: CEDAR PROGRAM IMPORTS CGM, Commander, FileNames, FS, Imager, ImagerFont, ImagerInterpress, IO, Rope -- , MacPaint, MacPICT EXPORTS InterpressFabricators ~ BEGIN OPEN InterpressFabricators; ROPE: TYPE ~ Rope.ROPE; inch: REAL = 0.0254; -- inches->meters conversion factor defaultMacPixelsPerInch: REAL = 72.0; -- for Macintosh files macCaptionFont: ROPE ¬ "xerox/pressfonts/helvetica-mir"; -- to put caption in Macintosh files headerSampled: ROPE ¬ "Interpress/Xerox/3.0 "; -- IP header for sampled images macCaptionLoc: Imager.VEC ¬ [72, 72]; -- where the caption should be in Macintosh files defaultPageWidth: REAL ¬ 0.210; -- for normal A4 sized paper defaultPageHeight: REAL ¬ 0.297; -- for normal A4 sized paper macMarginW: REAL ¬ 0.020; -- offset of Mac images on regular-sized paper macMarginH: REAL ¬ 0.040; -- offset of Mac images on regular-sized paper <> <> <> <<>> <> <> <> <> <> <> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <<};>> <> <> <> <> <> < failed ¬ TRUE;>> <<};>> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <> <> < rect.h THEN {>> <> <> <<}>> <> <> <> <<};>> <> <> <> <> <> <> <<};>> <> <> <> <> <> < failed ¬ TRUE;>> <<};>> <<>> CGMToInterpress: PUBLIC PROC [inputName: Rope.ROPE, interpress: ImagerInterpress.Ref, beginPage, endPage: ProgressProc, msg: IO.STREAM ¬ NIL, pageWidth, pageHeight: REAL, caption: ROPE] RETURNS [failed: BOOL ¬ FALSE] ~ { <> resolvedName: Rope.ROPE ¬ FileNames.ResolveRelativePath[inputName]; Paint: PROC [context: Imager.Context] ~ { Caption: PROC ~ { Imager.ScaleT[context, inch/72]; Imager.SetFont[context, ImagerFont.Scale[ImagerFont.Find[macCaptionFont], 9]]; Imager.SetXY[context, macCaptionLoc]; Imager.ShowRope[context, caption]; }; Imager.SetPriorityImportant[context, TRUE]; Imager.DoSave[context, Caption]; CGM.ToInterpress[context: context, fileName: resolvedName, pageWidth: pageWidth, pageHeight: pageHeight]; }; IF beginPage[1, 1] THEN GOTO tooBad; ImagerInterpress.DoPage[self: interpress, action: Paint, scale: 1.0]; IF endPage[1, 1] THEN GOTO tooBad; EXITS tooBad => failed ¬ TRUE; }; <> <> <> <> <> <<[] ¬ MacPaintToInterpress[inputName, output, BeginPage, EndPage, cmd.out, defaultPageWidth, defaultPageHeight, cmd.commandLine];>> <> <<};>> <> <> <> <> <> <<[] ¬ PICTToInterpress[inputName, output, BeginPage, EndPage, cmd.out, defaultPageWidth, defaultPageHeight, cmd.commandLine];>> <> <<};>> CGMToInterpressAction: PUBLIC ActionProc ~ { BeginPage: ProgressProc ~ { IF cmd.commandLine # NIL THEN cmd.out.PutF1["[%g", IO.int[pageNumber]]}; EndPage: ProgressProc ~ {IF cmd.commandLine # NIL THEN cmd.out.PutRope["] "]}; output: ImagerInterpress.Ref ¬ ImagerInterpress.Create[outputName, headerSampled]; [] ¬ CGMToInterpress[inputName, output, BeginPage, EndPage, cmd.out, defaultPageWidth, defaultPageHeight, cmd.commandLine]; ImagerInterpress.Close[output]; }; FindFullName: PROC [inputName: ROPE] RETURNS [ROPE] ~ { fullFName: ROPE ¬ NIL; fullFName ¬ FS.FileInfo[inputName].fullFName; RETURN [fullFName] }; <> <> <> <> <<};>> < CONTINUE].token;>> <<};>> GetFileNameToken: PROC [stream: IO.STREAM] RETURNS [rope: ROPE ¬ NIL] = { FileNameTokenBreak: 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]; }; rope ¬ stream.GetTokenRope[FileNameTokenBreak ! IO.EndOfStream => CONTINUE].token; }; Complain: PUBLIC ERROR [complaint: ROPE] ~ CODE; MakeOutputName: PROC [inputName: ROPE, doc: ROPE] RETURNS [ROPE] ~ { <> start: INT ¬ Rope.Index[s1: doc, s2: " to "]+4; end: INT ¬ Rope.SkipTo[s: doc, pos: start, skip: " \n\t"]; cp: FS.ComponentPositions; isMPNT: BOOL ¬ Rope.Equal[Rope.Substr[doc, start, end-start], "MPNT", FALSE]; [inputName, cp] ¬ FS.ExpandName[inputName]; RETURN [Rope.Cat[ Rope.Substr[inputName, cp.base.start, cp.base.length], IF isMPNT THEN NIL ELSE ".", IF isMPNT THEN NIL ELSE Rope.Substr[doc, start, end-start] ]] }; Command: PUBLIC Commander.CommandProc ~ { refAction: REF ActionProc ~ NARROW[cmd.procData.clientData]; stream: IO.STREAM ¬ IO.RIS[cmd.commandLine]; firstToken: ROPE ¬ GetFileNameToken[stream]; quiet: BOOL ¬ Rope.Equal[firstToken, "-q", FALSE]; outputName: ROPE ¬ FileNames.ResolveRelativePath[IF quiet THEN GetFileNameToken[stream] ELSE firstToken]; secondTokenIndex: INT ¬ IO.GetIndex[stream]; gets: ROPE ¬ GetFileNameToken[stream]; inputName: ROPE ¬ NIL; IF NOT gets.Equal["_"] THEN { inputName ¬ outputName; outputName ¬ NIL; stream.SetIndex[secondTokenIndex]; } ELSE {inputName ¬ FileNames.ResolveRelativePath[GetFileNameToken[stream]]}; IF inputName = NIL THEN RETURN[result: $Failure, msg: cmd.procData.doc]; inputName ¬ FindFullName[inputName ! FS.Error => { IF error.group = user THEN {result ¬ $Failure; msg ¬ error.explanation; GOTO Quit} }]; IF outputName = NIL THEN { outputName ¬ MakeOutputName[inputName, cmd.procData.doc]; }; cmd.out.PutRope["Reading "]; cmd.out.PutRope[inputName]; cmd.out.PutRope[" . . . "]; IF quiet THEN cmd.commandLine ¬ NIL; refAction­[inputName, outputName, cmd, stream ! Complain => {result ¬ $Failure; msg ¬ complaint; GOTO Quit}; FS.Error => { IF error.group = user THEN {result ¬ $Failure; msg ¬ error.explanation; GOTO Quit} } ]; outputName ¬ FindFullName[outputName ! FS.Error => { outputName ¬ "Output file(s)"; CONTINUE}; ]; cmd.out.PutRope[outputName]; cmd.out.PutRope[" written.\n"]; EXITS Quit => NULL }; Commander.Register["CGMToInterpress", Command, "\nConvert CGM to Interpress\nUsage:\tCGMToInterpress [-q] [ _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ CGMToInterpressAction]]; Commander.Register["CGMToIP", Command, "\nConvert CGM to Interpress\nUsage:\tCGMToIP [-q] [ _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ CGMToInterpressAction]]; < _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ MacPaintToInterpressAction]];>> < _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ MacPaintToInterpressAction]];>> < _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ PICTToInterpressAction]];>> < _] \n\t\t\t-q to suppress caption and page number", NEW[ActionProc ¬ PICTToInterpressAction]];>> END.