CDInterpressPlotImpl.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi,
Last edited by: Christian Jacobi, December 5, 1986 10:46:17 am PST
McCreight January 15, 1987 6:36:10 pm PST
DIRECTORY
CD,
CDBasics,
CDColors,
CDCommandOps,
CDOps,
CDProperties,
CDSequencer,
Imager,
ImagerInterpress,
IO,
Real,
RefTab,
Rope,
TerminalIO;
CDInterpressPlotImpl:
CEDAR
PROGRAM
IMPORTS CD, CDBasics, CDColors, CDCommandOps, CDOps, CDProperties, CDSequencer, Imager, ImagerInterpress, IO, Real, RefTab, Rope, TerminalIO =
BEGIN
--constant sizes and scales
standardPageX: REAL = 8.5*Imager.metersPerInch; -- 8.5 inches is USA standard page width
standardPageY: REAL = 11.0*Imager.metersPerInch; -- 11 inches is USA standard page height
versatecDeviceX: REAL = 0.97; --of the very special versatec plotter sitting close to my office... It really doe not store in this constant the with of any other versatec plotter available...
c400PageX: REAL = 0.292;
c400PageY: REAL = 0.419;
--default sizes and scales
defaultPageX: REAL ← standardPageX;
defaultPageY: REAL ← standardPageY;
defaultStripeX: REAL ← versatecDeviceX;
defaultBorder: REAL ← Imager.metersPerInch;
--others
fileNameDefault: Rope.ROPE ← "///temp/temp.IP";
ColorMode: TYPE = {allBlack, color, special};
colorMode: ColorMode ← allBlack;
--set ups for this very plot which will be created right now
pageX: REAL;
pageY: REAL;
contextColors: REF CD.ContextColors = NEW[CD.ContextColors←ALL[Imager.black]];
RectToRectangle:
PROC [r:
CD.Rect]
RETURNS [Imager.Rectangle] = {
RETURN [[x: r.x1, y: r.y1, w: r.x2-r.x1, h: r.y2-r.y1]]
};
SetUpBW:
PROC [] = {
FOR layer:
CD.Layer
IN
CD.Layer
DO
contextColors[layer] ← Imager.black;
ENDLOOP;
contextColors[CD.backgroundLayer] ← NIL;
};
SetUpColor:
PROC [] = {
FOR layer:
CD.Layer
IN
CD.Layer
DO
WITH CDProperties.GetLayerProp[layer, $CDxInterpressPlotColor]
SELECT
FROM
c: Imager.Color => {contextColors[layer] ← c; LOOP};
a: ATOM => IF a=$FALSE THEN {contextColors[layer] ← NIL; LOOP};
ENDCASE => NULL;
contextColors[layer] ← CDColors.globalColors[bit8][normal].cols[layer];
ENDLOOP;
contextColors[CD.backgroundLayer] ← NIL;
};
SetUpSpecial:
PROC [] = {
FOR layer:
CD.Layer
IN
CD.Layer
DO
contextColors[layer] ← IF CDProperties.GetLayerProp[layer, $CDxInterpressPlot]=$do THEN Imager.black ELSE NIL;
ENDLOOP;
contextColors[CD.backgroundLayer] ← NIL;
};
HardCopyCommand:
PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["HardCopy\n"];
[] ← CDCommandOps.DoWithResource[proc: ProtectedHardCopy, comm: comm, resource: $CDSimplePlotImpl];
};
PropagatedGetProp:
PROC [design:
CD.Design, key:
REF]
RETURNS [x:
REF] = {
x ← CDProperties.GetDesignProp[design, key];
IF x=NIL THEN x ← CDProperties.GetTechnologyProp[design.technology, key];
};
PropagatedGetIntProp:
PROC [design:
CD.Design, key:
REF, default:
INT𡤁]
RETURNS [
INT𡤀] = {
WITH PropagatedGetProp[design, key]
SELECT
FROM
ri: REF INT => RETURN [ri^];
ri: REF INTEGER => RETURN [ri^];
rc: REF CARDINAL => RETURN [rc^];
rn: REF NAT => RETURN [rn^];
ENDCASE => NULL;
RETURN [default]
};
ProtectedHardCopy:
PROC [comm: CDSequencer.Command] = {
--not re-entrant: using a globals
abortFlag: REF BOOL = NEW[BOOL←FALSE];
fileName: Rope.ROPE ← fileNameDefault;
pageNumX: INT ← 1; --number of vertical stripes
pageNumY: INT ← 1; --number of horizontal stripes
nX, nY: INT; --number of current page
borderX, borderY: REAL; --border of page
absolutelyNoAdjustments: BOOL ← FALSE;
ref: ImagerInterpress.Ref;
dr: CD.DrawRef;
clip: CD.Rect;
start: CD.Position;
sizePerPage: CD.Position;
scale: REAL;
substituteFonts: BOOL ← FALSE;
deviceTranslation: Imager.VEC ← [0, 0];
help: Rope.ROPE ← NIL;
PlotPage:
PROC [context: Imager.Context] = {
--the real work
r: CD.Rect ← CDBasics.RectAt[start, sizePerPage];
r ← CDBasics.Intersection[r, clip];
IF ~CDBasics.NonEmpty[r] THEN RETURN;
Imager.TranslateT[context, deviceTranslation];
Imager.ScaleT[context, scale];
Imager.TranslateT[context, [-r.x1, -r.y1]];
Imager.ClipRectangle[context, RectToRectangle[r]];
dr ←
CD.CreateDrawRef[[
design: comm.design,
stopFlag: abortFlag,
contextColors: contextColors,
borders: TRUE,
specialFonts: substituteFonts,
interestClip: r,
deviceContext: context
]];
IF CDSequencer.Aborted[comm.design] THEN RETURN;
CDOps.DrawDesign[comm.design, dr];
};
PreAmble:
PROC [ref: ImagerInterpress.Ref, contextColors:
REF
CD.ContextColors] = {
declared: RefTab.Ref ← RefTab.Create[];
FOR layer:
CD.Layer
IN
CD.Layer
DO
IF contextColors[layer]#NIL
THEN
IF RefTab.Insert[declared, contextColors[layer], contextColors[layer]]
THEN
ImagerInterpress.DeclareColor[ref, contextColors[layer]]
ENDLOOP;
declared ← NIL;
};
SetUp:
PROC [] = {
RequestBorder:
PROC [anyWay:
BOOL ←
FALSE] = {
borderY ← borderX ← 0;
IF (anyWay AND ~special) THEN borderY ← borderX ← defaultBorder
ELSE {
SELECT TerminalIO.RequestSelection[header: "border", choice:
LIST["yes", "fill space", "never"]]
FROM
1 => borderY ← borderX ← defaultBorder;
3 => absolutelyNoAdjustments ← TRUE;
ENDCASE => NULL;
}
};
SetUpVaryingScaling:
PROC [clip:
CD.Rect] = {
insidePageX, insidePageY: REAL; --what fits in a page without border
IF special
AND TerminalIO.Confirm["multiple pages ?"]
THEN {
pageNumX ← TerminalIO.RequestInt["Number of pages in x direction? >"];
IF pageNumX<1
OR pageNumX>20
THEN {
TerminalIO.PutRope[" to bad\n"];
ERROR ABORTED
};
}
RequestBorder[anyWay: pageNumX=0];
insidePageX ← pageX-2*borderX;
insidePageY ← pageY-2*borderY;
IF pageNumX=0
THEN {
--single page
pageNumY ← 1;
pageNumX ← 1;
sizePerPage ← CDBasics.SizeOfRect[clip];
scale ← MIN[insidePageX/sizePerPage.x, insidePageY/sizePerPage.y];
}
ELSE {
--multiple pages
sizePerPage.x ← (clip.x2-clip.x1)/pageNumX+1;
sizePerPage.y ← Real.Fix[insidePageY*((sizePerPage.x-1.0)/insidePageX)];
scale ← insidePageX/sizePerPage.x;
pageNumY ← ( (clip.y2-clip.y1)+(sizePerPage.y-1) )/sizePerPage.y;
};
help ← IF pageY=c400PageY THEN " Example usage:\n InterpressToPD tem.pd ← ///temp/temp.IP bw400\n" ELSE " Example usage:\n InterpressToPD tem.pd ← ///temp/temp.IP raven384\n";
};--SetUpVaryingScaling
SetUpStriped:
PROC [clip:
CD.Rect] = {
borderY ← defaultBorder;
borderX ← 0;
pageNumY ← 1;
IF special
AND TerminalIO.Confirm["multiple stripes ?"]
THEN {
pageNumX ← TerminalIO.RequestInt["How many stripes? >"];
IF pageNumX<1
OR pageNumX>20
THEN {
TerminalIO.PutRope[" to bad\n"];
ERROR ABORTED
}
}
help ← " Example usage:\n InterpressToPD tem.pd ← ///temp/temp.IP versatec\n";
sizePerPage.x ← (clip.x2-clip.x1)/pageNumX;
sizePerPage.y ← clip.y2-clip.y1;
scale ← pageX/sizePerPage.x;
pageY ← scale*sizePerPage.y+2*borderY;
};
SetUpFixedScaling:
PROC [clip:
CD.Rect] = {
borderAnyway: BOOL;
defaultScale:
REAL ← Imager.metersPerPoint/comm.design.technology.lambda;
--1l -> 1 point
scale ← defaultScale;
scale ← scale*PropagatedGetIntProp[design: comm.design, key: $CDxDefaultPrintScaleNum, default: 1];
scale ← scale/PropagatedGetIntProp[design: comm.design, key: $CDxDefaultPrintScaleDenom, default: 1];
borderAnyway ←
( (clip.x2-clip.x1)*scale < (pageX - 0.05) ) AND
( (clip.y2-clip.y1)*scale < (pageY - 0.05) );
RequestBorder[borderAnyway];
sizePerPage.x ← Real.Round[(pageX-2*borderX)/scale];
sizePerPage.y ← Real.Round[(pageY-2*borderY)/scale];
pageNumX ← (clip.x2-clip.x1+sizePerPage.x-1)/sizePerPage.x;
pageNumY ← (clip.y2-clip.y1+sizePerPage.y-1)/sizePerPage.y;
help ← IF pageY=c400PageY THEN " Example usage:\n InterpressToPD tem.pd ← ///temp/temp.IP bw400\n" ELSE " Example usage:\n InterpressToPD tem.pd ← ///temp/temp.IP raven384\n";
};
AdjustPosition:
PROC [] = {
IF absolutelyNoAdjustments THEN RETURN;
IF pageNumX=1
THEN {
borderX ← MIN[(pageX - (clip.x2-clip.x1)*scale)/2, defaultBorder];
};
IF pageNumY=1
THEN {
pictureHeight: REAL ← (clip.y2-clip.y1)*scale;
borderY ← MAX[pageY-defaultBorder-pictureHeight, (pageY-pictureHeight)/2];
};
};
SubstituteFonts:
PROC = {
SELECT TerminalIO.RequestSelection["substitute tioga fonts",
LIST["yes", "no"]]
FROM
1 => {
substituteFonts ← TRUE;
TerminalIO.PutRope["substitute tioga fonts\n"];
};
ENDCASE => {
TerminalIO.PutRope["don't substitute fonts\n"];
substituteFonts ← FALSE;
};
};
GetClipRect:
PROC [comm: CDSequencer.Command] = {
n:
INT ← TerminalIO.RequestSelection[header: "plot area",
choice: LIST["complete design", "area of selected objects", "rectangle of command"]
];
SELECT n
FROM
3 => {
TerminalIO.PutRope["plot area drawn with command\n"];
clip ← CDBasics.ToRect[comm.pos, comm.sPos];
};
2 => {
TerminalIO.PutRope["plot area of selected objects\n"];
clip ← CDOps.BoundingBox[design: comm.design, onlySelected: TRUE];
};
ENDCASE => {
TerminalIO.PutRope["plot complete design\n"];
clip ← CDOps.BoundingBox[design: comm.design, onlySelected: FALSE];
};
IF ~CDBasics.NonEmpty[clip]
THEN {
TerminalIO.PutRope["clip rectangle is empty\n"];
ERROR ABORTED
};
};
GetMedium:
PROC [] = {
special ← FALSE;
fixedScale ← FALSE;
striped ← FALSE;
SELECT TerminalIO.RequestSelection["Plot",
LIST["standard page and scale", "fill standard page", "fill versatec stripe", "fill c400 page", "other"]]
FROM
1 => {
fixedScale ← TRUE;
TerminalIO.PutRope["standard page and scale\n"];
};
3 => {
striped ← TRUE;
pageX ← defaultStripeX;
TerminalIO.PutRope["fill versatec stripe\n"];
};
4 => {
pageX ← c400PageX;
pageY ← c400PageY;
TerminalIO.PutRope["fill c400 page\n"];
};
5 => {
TerminalIO.PutRope["special:\n"];
special ← TRUE;
SELECT TerminalIO.RequestSelection["Plot",
LIST["fill standard pages", "fill versatec stripes", "standard scale standard pages", "fill c400 pages", "standard scale c400 pages"]]
FROM
1 => {
TerminalIO.PutRope["fill standard pages\n"];
};
2 => {
striped ← TRUE;
pageX ← defaultStripeX;
TerminalIO.PutRope["fill versatec stripes\n"];
};
3 => {
fixedScale ← TRUE;
TerminalIO.PutRope["standard scale standard pages\n"];
};
4 => {
pageX ← c400PageX;
pageY ← c400PageY;
TerminalIO.PutRope["fill c400 pages\n"];
};
5 => {
pageX ← c400PageX;
pageY ← c400PageY;
fixedScale ← TRUE;
TerminalIO.PutRope["standard scale c400 pages\n"];
};
ENDCASE => ERROR ABORTED;
};
--2,--
ENDCASE => {
TerminalIO.PutRope["fill standard page\n"];
};
}; --GetMedium
--Setup
special: BOOL ← FALSE;
clipRect: BOOL ← FALSE;
fixedScale: BOOL ← FALSE;
striped: BOOL ← FALSE;
IF comm.key=$InterpressPlotC
THEN {
TerminalIO.PutRope["** COLORS\n"];
SetUpColor[]
}
ELSE SELECT colorMode
FROM
special => {
TerminalIO.PutRope["** SPECIAL COLORS\n"];
SetUpSpecial[]
};
color => {
TerminalIO.PutRope["** COLORS\n"];
SetUpColor[]
};
allBlack => {
TerminalIO.PutRope["** BW\n"];
SetUpBW[]
};
ENDCASE => ERROR;
pageX ← defaultPageX;
pageY ← defaultPageY;
SubstituteFonts[];
GetClipRect[comm];
GetMedium[];
sizePerPage ← CDBasics.SizeOfRect[clip];
IF striped THEN SetUpStriped[clip]
ELSE IF fixedScale THEN SetUpFixedScaling[clip]
ELSE SetUpVaryingScaling[clip];
AdjustPosition[];
TerminalIO.PutF[" printing %01g rows and %01g columns\n", IO.int[pageNumX], IO.int[pageNumY]];
}; --Setup
SetUp[];
CDSequencer.UseAbortFlag[comm.design, abortFlag];
ref ← ImagerInterpress.Create[fileName];
PreAmble[ref, contextColors];
deviceTranslation ← [borderX, borderY];
FOR nX
IN [0..pageNumX)
DO
FOR nY
IN [0..pageNumY)
DO
IF CDSequencer.Aborted[comm.design] THEN EXIT;
start.x ← clip.x1+nX*sizePerPage.x;
start.y ← clip.y1+nY*sizePerPage.y;
ImagerInterpress.DoPage[ref, PlotPage];
ENDLOOP;
ENDLOOP;
ImagerInterpress.Close[ref];
TerminalIO.PutF1[" ""%01g"" created\n", IO.rope[fileName]];
IF ~Rope.IsEmpty[help] THEN TerminalIO.PutRope[help];
IF CDSequencer.Aborted[comm.design] THEN TerminalIO.PutRope["some pages skipped\n"]
ELSE TerminalIO.PutRope[" done\n"];
};
CDCommandOps.RegisterWithMenu[menu: $HardCopyMenu, entry: "b&w interpress", doc: "all layers are painted black", key: $InterpressPlot, proc: HardCopyCommand];
CDCommandOps.RegisterWithMenu[menu: $HardCopyMenu, entry: "color interpress", doc: "does not deal with overlapping layers", key: $InterpressPlotC, proc: HardCopyCommand];
TerminalIO.PutRope["Interpress plot loaded\n"];
END.