ImagerArtworkImpl.mesa
Copyright Ó 1985, 1986, 1987 by Xerox Corporation. All rights reserved.
Michael Plass, April 29, 1987 7:26:32 pm PDT
Doug Wyatt, June 6, 1986 2:44:47 pm PDT
Bland, August 28, 1986 4:33:18 pm PDT
DIRECTORY
Atom USING [DottedPairNode],
Convert USING [RopeFromReal],
Imager USING [ClipRectangle, ConcatT, Context, Rectangle],
ImagerArtwork USING [],
ImagerInterpress USING [CreateFromStream, DoPage, Finish, Ref],
ImagerTransformation USING [Scale, Transformation, TransformRectangle],
IO USING [RopeFromROS, ROS, STREAM],
Rope USING [ActionType, Cat, Map, ROPE],
TEditDocument USING [Selection],
TEditInputOps USING [Break, CallWithLocks],
TextNode USING [Ref],
TiogaAccess USING [Create, Looks, Put, TiogaChar, Writer, WriteSelection];
ImagerArtworkImpl: CEDAR PROGRAM
IMPORTS Convert, Imager, ImagerInterpress, IO, Rope, TiogaAccess, ImagerTransformation, TEditInputOps
EXPORTS ImagerArtwork
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Transformation: TYPE ~ ImagerTransformation.Transformation;
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 [Transformation] ~ {
RETURN [ImagerTransformation.Scale[metersPerPoint]];
};
CreateInterpressRope: PUBLIC PROC [action: PROC [Imager.Context], bounds: Imager.Rectangle, m: Transformation, clip: BOOLTRUE] 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: Transformation, clip: BOOL, fit: BOOL] ~ {
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: BOOLFALSE;
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 'Artwork on' to command tool] ", 'n];
IF fit AND bb.h > 0 AND bb.w > 0 THEN {
aspectRope: ROPE ~ Convert.RopeFromReal[bb.h/bb.w];
topSpaceRope: ROPE ~ Convert.RopeFromReal[topSpace];
topCalcRope: ROPE ~ Rope.Cat[aspectRope, " the lineLength .mul ", topSpaceRope, " .add "];
PutRopeProp[$Postfix, Rope.Cat[
topCalcRope, "topLeading ",
topCalcRope, "topIndent " ].Cat[
Convert.RopeFromReal[bottomSpace], " mm bottomLeading ",
"0.5 0.3 0.95 backgroundColor the topLeading 6 pt .sub backgroundAscent 3 pt backgroundDescent 4 pt outlineBoxThickness 1 pt outlineBoxBearoff"
]];
PutRopeProp[$Fit, "TRUE"];
}
ELSE {
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 ",
"0.5 0.3 0.95 backgroundColor the topLeading 6 pt .sub backgroundAscent 3 pt backgroundDescent 4 pt outlineBoxThickness 1 pt outlineBoxBearoff"
]];
};
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;
tc.format ← $artworkFigure;
TiogaAccess.Put[writer, tc];
tc.format ← NIL;
tc ← vanillaTC;
PutLooksRope["", 't];
PutRope[" Insert caption here "];
PutLooksRope["", 't];
tc.endOfNode ← TRUE;
tc.char ← '\n;
tc.format ← $artworkCaption;
TiogaAccess.Put[writer, tc];
tc.format ← NIL;
};
PasteArtwork: PUBLIC PROC [action: PROC [Imager.Context], bounds: Imager.Rectangle, m: Transformation, clip: BOOL, fit: BOOL] ~ {
writer: TiogaAccess.Writer ← TiogaAccess.Create[];
locked: PROC [root: TextNode.Ref, tSel:TEditDocument.Selection] ~ {
TEditInputOps.Break[];
TiogaAccess.WriteSelection[writer];
};
WriteArtwork[writer: writer, action: action, bounds: bounds, m: m, clip: clip, fit: fit];
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]