ImagerArtworkImpl.mesa
Copyright Ó 1985, 1986, 1987, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, March 24, 1992 12:17 pm PST
Bland, August 28, 1986 4:33:18 pm PDT
Bier, March 11, 1988 4:01:45 pm PST
Pier, October 24, 1988 12:17:41 pm PDT
Added ImagerArtworkExtras code, October 24, 1988
Bloomenthal, May 29, 1990 2:52:30 pm PDT
Doug Wyatt, October 1, 1991 4:28 pm PDT
DIRECTORY Convert, Imager, ImagerArtwork, ImagerInterpress, ImagerTransformation, IO, Prop, Rope, TEditDocument, TEditInputOps, TEditSelection, TextNode, TiogaAccess, TiogaAccessViewers;
ImagerArtworkImpl: CEDAR PROGRAM
IMPORTS Convert, Imager, ImagerInterpress, ImagerTransformation, IO, Prop, Rope, TEditInputOps, TEditSelection, TiogaAccess, TiogaAccessViewers
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 ¬ NIL,
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: Transformation ¬ NIL,
clip: BOOL ¬ TRUE,
fit: BOOL ¬ FALSE,
caption: BOOL ¬ TRUE]
~ {
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 ¬ Prop.Put[propList: tc.propList, key: key, val: val];
};
interpress: ROPE ~ CreateInterpressRope[action, bounds, m, clip];
tc: TiogaAccess.TiogaChar ¬ vanillaTC;
bb: Imager.Rectangle ¬ ImagerTransformation.TransformRectangle[m, bounds];
scale: REAL ~ 1000.0;
tc.comment ¬ TRUE;
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, "bigger topLeading ",
topCalcRope, "bigger topIndent " ].Cat[
Convert.RopeFromReal[bottomSpace], " mm bigger 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 bigger topLeading ",
Convert.RopeFromReal[(bb.h+bb.y)*scale+topSpace], " mm bigger topIndent " ].Cat[
Convert.RopeFromReal[(-bb.y)*scale+bottomSpace], " mm bigger 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;
IF caption THEN {
PutLooksRope["", 't];
PutRope[" Insert caption here "];
PutLooksRope["", 't];
tc.endOfNode ¬ TRUE;
tc.char ¬ '\n;
tc.format ¬ $artworkCaption;
TiogaAccess.Put[writer, tc];
tc.format ¬ NIL;
tc.endOfNode ¬ FALSE;
IF TEditSelection.pSel.granularity < node THEN {
tc.endOfNode ¬ TRUE;
PutRope["\n"];
tc.endOfNode ¬ FALSE;
};
};
};
PasteArtwork: PUBLIC PROC [
action: PROC [Imager.Context],
bounds: Imager.Rectangle,
m: Transformation ¬ NIL,
clip: BOOL ¬ TRUE,
fit: BOOL ¬ FALSE,
caption: BOOL ¬ TRUE]
~ {
Locked: PROC [root: TextNode.Ref, tSel: TEditDocument.Selection] ~ {
AddSelection: PROC ~ {
reader: TiogaAccess.Reader ¬ TiogaAccessViewers.FromSelection[];
WHILE NOT TiogaAccess.EndOf[reader] DO
TiogaAccess.Put[writer, TiogaAccess.Get[reader]];
ENDLOOP;
};
writer: TiogaAccess.Writer ¬ TiogaAccess.Create[];
IF NOT tSel.pendingDelete AND tSel.insertion = after THEN AddSelection[];
IF tSel.granularity < node OR NOT tSel.pendingDelete THEN {
tc: TiogaAccess.TiogaChar ¬ vanillaTC;
tc.comment ¬ tc.endOfNode ¬ TRUE;
tc.char ¬ '\n;
TiogaAccess.Put[writer, tc];
};
WriteArtwork[writer, action, bounds, m, clip, fit, caption];
IF NOT tSel.pendingDelete AND tSel.insertion = before THEN AddSelection[];
TiogaAccessViewers.WriteSelection[writer];
};
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]