<> <> <> DIRECTORY Atom, ViewerClasses, TiogaMenuOps, Convert, Commander, FS, Imager, ImagerInterpress, Interpress, IO, Rope, TiogaAccess, ImagerArtwork, ImagerTransformation, TEditInputOps, TextNode, TEditDocument; ImagerArtworkImpl: CEDAR PROGRAM IMPORTS Convert, Imager, ImagerInterpress, IO, Rope, TiogaAccess, ImagerTransformation, TEditInputOps EXPORTS ImagerArtwork ~ BEGIN ROPE: TYPE ~ Rope.ROPE; metersPerPoint: REAL _ 254.0/720000.0; mmPerPoint: REAL _ 254.0/720.0; topSpace: REAL _ 8.0*mmPerPoint; bottomSpace: REAL _ 4.0*mmPerPoint; Points: PUBLIC PROC RETURNS [Imager.Transformation] ~ { RETURN [ImagerTransformation.Scale[metersPerPoint]]; }; CreateInterpressRope: PUBLIC PROC [action: PROC [Imager.Context], bounds: Imager.Rectangle, m: Imager.Transformation, clip: BOOL _ TRUE] RETURNS [ROPE] ~ { ros: IO.STREAM ~ IO.ROS[]; outputMaster: ImagerInterpress.Ref ~ ImagerInterpress.CreateFromStream[ros, "Interpress/Xerox/3.0 "]; pageAction: PROC [context: Imager.Context] ~ { IF m # NIL THEN Imager.ConcatT[context, m]; IF clip THEN Imager.ClipRectangle[context, bounds]; action[context]; }; ImagerInterpress.DoPage[outputMaster, pageAction, 1.0]; ImagerInterpress.Finish[outputMaster]; RETURN [IO.RopeFromROS[ros]]; }; WriteArtwork: PUBLIC PROC [writer: TiogaAccess.Writer, action: PROC [Imager.Context], bounds: Imager.Rectangle, m: Imager.Transformation, clip: BOOL _ TRUE] ~ { interpress: ROPE ~ CreateInterpressRope[action, bounds, m, clip]; tc: TiogaAccess.TiogaChar _ [ charSet: 0, char: '\n, looks: ALL[FALSE], format: NIL, comment: TRUE, endOfNode: FALSE, deltaLevel: 0, propList: NIL ]; PutRope: PROC [rope: ROPE] ~ { action: Rope.ActionType ~ {tc.char _ c; TiogaAccess.Put[writer, tc]}; [] _ Rope.Map[base: rope, action: action]; }; PutLooksRope: PROC [rope: ROPE, look1, look2: CHAR _ '\000] ~ { save: TiogaAccess.Looks ~ tc.looks; IF look1 # '\000 THEN tc.looks[look1] _ TRUE; IF look2 # '\000 THEN tc.looks[look2] _ TRUE; PutRope[rope]; tc.looks _ save; }; PutRopeProp: PROC [key: ATOM, val: ROPE] ~ { tc.propList _ CONS[NEW[Atom.DottedPairNode _ [key: key, val: val]], tc.propList]; }; sepNeeded: BOOL _ FALSE; Sp: PROC ~ {PutRope[" "]; sepNeeded _ FALSE}; Comma: PROC ~ {IF sepNeeded THEN PutRope[", "]; sepNeeded _ FALSE}; Putmm: PROC [meters: REAL] ~ { PutLooksRope[Convert.RopeFromReal[meters*1000], 'f]; PutLooksRope["mm", 's, 'o]; sepNeeded _ TRUE; }; PutKey: PROC [rope: ROPE] ~ { Comma[]; PutLooksRope[rope, 'o]; PutLooksRope[": ", 'o]; sepNeeded _ TRUE; }; PutKeyMeters: PROC [name: ROPE, meters, defaultMeters: REAL] ~ { IF meters#defaultMeters THEN {PutKey[name]; Putmm[meters]}; }; bb: Imager.Rectangle _ ImagerTransformation.TransformRectangle[m, bounds]; scale: REAL ~ 1000.0; tc.endOfNode _ TRUE; PutRope["\n"]; tc.endOfNode _ FALSE; PutLooksRope[" [Artwork node; type 'ArtworkInterpress on' to command tool] ", 'n]; PutRopeProp[$Postfix, Rope.Cat[ Convert.RopeFromReal[(bb.h+bb.y)*scale+topSpace], " mm topLeading ", Convert.RopeFromReal[(bb.h+bb.y)*scale+topSpace], " mm topIndent " ].Cat[ Convert.RopeFromReal[(-bb.y)*scale+bottomSpace], " mm bottomLeading " ]]; PutRopeProp[$Bounds, Rope.Cat[ Convert.RopeFromReal[bb.x*scale], " mm xmin ", Convert.RopeFromReal[bb.y*scale], " mm ymin " ].Cat[ Convert.RopeFromReal[(bb.x+bb.w)*scale], " mm xmax ", Convert.RopeFromReal[(bb.y+bb.h)*scale], " mm ymax " ]]; PutRopeProp[$Artwork, "Interpress"]; PutRopeProp[$Interpress, interpress]; tc.endOfNode _ TRUE; tc.deltaLevel _ 1; tc.char _ '\n; TiogaAccess.Put[writer, tc]; tc _ vanillaTC; PutRope[" Insert caption here "]; tc.endOfNode _ TRUE; tc.char _ '\n; tc.format _ $caption; TiogaAccess.Put[writer, tc]; }; PasteArtwork: PUBLIC PROC [action: PROC [Imager.Context], bounds: Imager.Rectangle, m: Imager.Transformation, clip: BOOL] ~ { writer: TiogaAccess.Writer _ TiogaAccess.Create[]; locked: PROC [root: TextNode.Ref, tSel:TEditDocument.Selection] ~ { TEditInputOps.Break[]; TiogaAccess.WriteSelection[writer]; }; WriteArtwork[writer, action, bounds, m, clip]; TEditInputOps.CallWithLocks[locked]; }; vanillaTC: TiogaAccess.TiogaChar ~ [ charSet: 0, char: '\n, looks: ALL[FALSE], format: NIL, comment: FALSE, endOfNode: FALSE, deltaLevel: 0, propList: NIL ]; END. CreateButton p _ ImagerArtwork.PasteArtwork[LOOPHOLE[ImagerExamplesImpl.Text], [0,0,0.08,0.05], ImagerTransformation.Scale[0.5], TRUE]