CDInterpressPlotImpl.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Jacobi, July 12, 1985 8:50:32 am PST
Last Edited by: Jacobi, July 11, 1986 11:30:05 am PDT
Last edited by: Christian Jacobi, August 25, 1986 2:09:28 pm PDT
DIRECTORY
CD,
CDBasics,
CDColors,
CDCommandOps,
CDIO,
CDCommandOpsExtras2,
CDOps,
CDProperties,
CDSequencer,
CDTexts,
FS,
Imager,
ImagerInterpress,
IO,
Real,
RefTab,
Rope,
SymTab,
TerminalIO;
CDInterpressPlotImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDColors, CDCommandOps, CDIO, CDCommandOpsExtras2, CDOps, CDProperties, CDTexts, FS, Imager, ImagerInterpress, IO, Real, RefTab, Rope, SymTab, TerminalIO =
BEGIN
--constant sizes and scales
standardPageX: REAL = 0.216; --(72*8.5; points) United States standard page with....
standardPageY: REAL = 0.277; --(72*11.0; points)
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;
defaultScale: REAL ← 0; --Imager.metersPerPoint/comm.design.technology.lambda
--others
abortFlag: REF BOOL = NEW[BOOLFALSE];
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] =
BEGIN
RETURN [[x: r.x1, y: r.y1, w: r.x2-r.x1, h: r.y2-r.y1]]
END;
SetUpBW: PROC [] =
BEGIN
FOR layer: CD.Layer IN CD.Layer DO
contextColors[layer] ← Imager.black;
ENDLOOP;
contextColors[CD.backgroundLayer] ← NIL;
END;
SetUpColor: PROC [] =
BEGIN
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;
END;
SetUpSpecial: PROC [] =
BEGIN
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;
END;
HardCopyCommand: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["HardCopy\n"];
abortFlag^ ← FALSE;
[] ← CDCommandOps.CallWithResource[
proc: ProtectedHardCopy,
comm: comm,
resource: $CDSimplePlotImpl,
abortFlag: abortFlag
];
END;
DrawOutLine: PUBLIC PROC [r: CD.Rect, l: CD.Layer, pr: CD.DrawRef] =
BEGIN
ActionWithContext: PROC [] =
BEGIN
Imager.SetColor[pr.deviceContext, pr.contextColors[l]];
Imager.MaskVector[pr.deviceContext, [r.x1, r.y1], [r.x2, r.y1]];
Imager.MaskVector[pr.deviceContext, [r.x2, r.y1], [r.x2, r.y2]];
Imager.MaskVector[pr.deviceContext, [r.x2, r.y2], [r.x1, r.y2]];
Imager.MaskVector[pr.deviceContext, [r.x1, r.y2], [r.x1, r.y1]];
END;
IF pr.deviceContext#NIL THEN {
IF pr.contextColors[l]#NIL THEN Imager.DoSave[pr.deviceContext, ActionWithContext]
}
END;
ProtectedHardCopy: PROC [comm: CDSequencer.Command] =
--not re-entrant: using a global abort flag (abortFlag)
BEGIN
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: BOOLFALSE;
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.ROPENIL;
PlotPage: PROC [context: Imager.Context] =
--the real stuff
BEGIN
r: CD.Rect ← CDBasics.RectAt[start, sizePerPage];
r ← CDBasics.Intersection[r, clip];
IF ~CDBasics.NonEmpty[r] THEN RETURN;
IF abortFlag^ 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,
drawOutLine: DrawOutLine,
contextColors: contextColors,
borders: TRUE,
interestClip: r,
deviceContext: context
]];
IF substituteFonts THEN {
dr.specialFonts ← TRUE;
CDProperties.PutProp[dr.properties, $FontExchange, fontReplace];
};
CDOps.DrawDesign[comm.design, dr];
END;
PreAmble: PROC [ref: ImagerInterpress.Ref, contextColors: REF CD.ContextColors] =
BEGIN
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;
END;
SetUp: PROC [] =
BEGIN
RequestBorder: PROC [anyWay: BOOLFALSE] =
BEGIN
borderY ← borderX ← 0;
IF (anyWay AND ~special) THEN borderY ← borderX ← defaultBorder
ELSE {
SELECT TerminalIO.RequestSelection[label: "border", choice: LIST["yes", "fill space", "never"]] FROM
1 => borderY ← borderX ← defaultBorder;
3 => absolutelyNoAdjustments ← TRUE;
ENDCASE => NULL;
}
END;
SetUpVaryingScaling: PROC [clip: CD.Rect] =
BEGIN
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.WriteRope[" to bad\n"];
ERROR ABORTED
};
}
ELSE {
pageNumX ← 0;
};
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";
END;--SetUpVaryingScaling
SetUpStriped: PROC [clip: CD.Rect] =
BEGIN
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.WriteRope[" to bad\n"];
ERROR ABORTED
}
}
ELSE {
pageNumX ← 1;
};
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;
END;
SetUpFixedScaling: PROC [clip: CD.Rect] =
BEGIN
borderAnyway: BOOL;
scale ← defaultScale;
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";
END;
AdjustPosition: PROC [] =
BEGIN
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];
};
END;
SubstituteFonts: PROC =
BEGIN
SELECT TerminalIO.RequestSelection["substitute fonts ?", LIST["no substitution", "standard substitution file", "user substitution file"]] FROM
2 => {
substituteFonts ← TRUE;
TerminalIO.WriteRope["use standard font substitution file\n"];
fontTab ← InitFontTab[];
};
3 => {
r: Rope.ROPE;
r ← TerminalIO.RequestRope["fullpath name for font substitution file > "];
substituteFonts ← TRUE;
fontTab ← InitFontTab[r];
};
ENDCASE => {
TerminalIO.WriteRope["don't substitute fonts\n"];
substituteFonts ← FALSE;
};
END;
GetClipRect: PROC [comm: CDSequencer.Command] =
BEGIN
n: INT ← TerminalIO.RequestSelection[label: "plot area",
choice: LIST["complete design", "area of selected objects", "rectangle of command"]
];
SELECT n FROM
3 => {
TerminalIO.WriteRope["plot area drawn with command\n"];
clip ← CDBasics.ToRect[comm.pos, comm.sPos];
};
2 => {
TerminalIO.WriteRope["plot area of selected objects\n"];
clip ← CDCommandOps.BoundingBox[design: comm.design, onlySelected: TRUE];
};
ENDCASE => {
TerminalIO.WriteRope["plot complete design\n"];
clip ← CDCommandOps.BoundingBox[design: comm.design, onlySelected: FALSE];
};
IF ~CDBasics.NonEmpty[clip] THEN {
TerminalIO.WriteRope["clip rectangle is empty\n"];
ERROR ABORTED
};
END;
GetMedium: PROC [] =
BEGIN
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.WriteRope["standard page and scale\n"];
};
3 => {
striped ← TRUE;
pageX ← defaultStripeX;
TerminalIO.WriteRope["fill versatec stripe\n"];
};
4 => {
pageX ← c400PageX;
pageY ← c400PageY;
TerminalIO.WriteRope["fill c400 page\n"];
};
5 => {
TerminalIO.WriteRope["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.WriteRope["fill standard pages\n"];
};
2 => {
striped ← TRUE;
pageX ← defaultStripeX;
TerminalIO.WriteRope["fill versatec stripes\n"];
};
3 => {
fixedScale ← TRUE;
TerminalIO.WriteRope["standard scale standard pages\n"];
};
4 => {
pageX ← c400PageX;
pageY ← c400PageY;
TerminalIO.WriteRope["fill c400 pages\n"];
};
5 => {
pageX ← c400PageX;
pageY ← c400PageY;
fixedScale ← TRUE;
TerminalIO.WriteRope["standard scale c400 pages\n"];
};
ENDCASE => ERROR ABORTED;
};
--2,-- ENDCASE => {
TerminalIO.WriteRope["fill standard page\n"];
};
END; --GetMedium
--Setup
special: BOOLFALSE;
clipRect: BOOLFALSE;
fixedScale: BOOLFALSE;
striped: BOOLFALSE;
defaultScale ← Imager.metersPerPoint/comm.design.technology.lambda;
IF comm.key=$InterpressPlotC THEN {
TerminalIO.WriteRope["** COLORS\n"];
SetUpColor[]
}
ELSE SELECT colorMode FROM
special => {
TerminalIO.WriteRope["** SPECIAL COLORS\n"];
SetUpSpecial[]
};
color => {
TerminalIO.WriteRope["** COLORS\n"];
SetUpColor[]
};
allBlack => {
TerminalIO.WriteRope["** BW\n"];
SetUpBW[]
};
ENDCASE => ERROR;
pageX ← defaultPageX;
pageY ← defaultPageY;
fontTab ← NIL;
SubstituteFonts[];
GetClipRect[comm];
GetMedium[];
sizePerPage ← CDBasics.SizeOfRect[clip];
IF striped THEN SetUpStriped[clip]
ELSE IF fixedScale THEN SetUpFixedScaling[clip]
ELSE SetUpVaryingScaling[clip];
AdjustPosition[];
TerminalIO.WriteF[" printing %01g rows and %01g columns\n", IO.int[pageNumX], IO.int[pageNumY]];
END; --Setup
SetUp[];
ref ← ImagerInterpress.Create[fileName];
PreAmble[ref, contextColors];
deviceTranslation ← [borderX, borderY];
FOR nX IN [0..pageNumX) DO
FOR nY IN [0..pageNumY) DO
IF abortFlag^ 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.WriteF1[" ""%01g"" created\n", IO.rope[fileName]];
IF ~Rope.IsEmpty[help] THEN TerminalIO.WriteRope[help];
IF ~abortFlag^ THEN TerminalIO.WriteRope[" done\n"];
END;
--************************************************
--Font replacement stuff
fontTab: SymTab.Ref;
wDir: Rope.ROPE;
fontReplace: REF PROC [CDTexts.CDFont] RETURNS [CDTexts.CDFont]
NEW[PROC [CDTexts.CDFont] RETURNS [CDTexts.CDFont] ← FontReplace];
FontKeyRope: PROC[name: Rope.ROPE, scale: INT] RETURNS[key: Rope.ROPE] =
BEGIN
RETURN[ IO.PutFR["%g-%g", IO.rope[name], IO.int[scale] ]]
END;
FontReplace: PROC [cdFont: CDTexts.CDFont] RETURNS [CDTexts.CDFont] =
BEGIN
newFont: CDTexts.CDFont ← NIL;
fontKey: Rope.ROPE ← FontKeyRope[cdFont.supposedName, cdFont.scaleI];
WITH SymTab.Fetch[fontTab, fontKey].val SELECT FROM
f: CDTexts.CDFont => RETURN [f];
f: REF CDTexts.FontRec => RETURN [f];
ENDCASE => NULL;
WITH SymTab.Fetch[fontTab, cdFont.supposedName].val SELECT FROM
l: LIST OF REF ANY => {
IF l.first#NIL AND l.rest#NIL AND l.rest.rest=NIL THEN {
scale: INT ← 0;
name: Rope.ROPE ← CDCommandOps.ToRope[l.first];
WITH l.rest.first SELECT FROM
ri: REF INT => scale ← ri^*cdFont.scaleI
ENDCASE => NULL;
IF scale>0 AND ~Rope.IsEmpty[name] THEN {
newFont ← CDTexts.MakeFont[name, scale];
IF newFont#NIL THEN {
x: REF CDTexts.FontRec;
TRUSTED {x ← LOOPHOLE[newFont]};
[] ← SymTab.Store[fontTab, fontKey, x];
}
};
}
};
f: CDTexts.CDFont => newFont ← f;
f: REF CDTexts.FontRec => newFont ← f;
ENDCASE => NULL;
IF newFont=NIL THEN newFont�ont;
RETURN [newFont]
END;
InitFontTab: PROC [fileName: Rope.ROPENIL] RETURNS [fontTab: SymTab.Ref] =
BEGIN
OneLine: PROC [line: Rope.ROPE] =
BEGIN
stream: IO.STREAMIO.RIS[line];
scale: INT;
subst, by: Rope.ROPE;
subst ← IO.GetRopeLiteral[stream];
by ← IO.GetRopeLiteral[stream];
scale ← IO.GetInt[stream];
[] ← fontTab.Store[subst, LIST[by, NEW[INT←scale]]];
END;
file: IO.STREAMNIL;
fontTab ← SymTab.Create[];
IF Rope.IsEmpty[fileName] THEN fileName ← "CDSubstituteFonts";
fileName ← CDIO.MakeName[base: fileName, ext: "SubstituteFonts", wDir: wDir];
file ← FS.StreamOpen[fileName ! FS.Error => {
TerminalIO.WriteRopes["no font substitution: ", error.explanation, "\n"];
GOTO thatsIt
}];
DO
line: Rope.ROPE;
line ← IO.GetLineRope[file ! IO.EndOfStream => GOTO thatsIt];
IF ~Rope.IsEmpty[line] THEN
OneLine[line !
IO.EndOfStream => GOTO thatsIt;
IO.Error => {
TerminalIO.WriteRopes["**error reading font substitution: ", line, "\n"];
CONTINUE
};
];
ENDLOOP;
EXITS thatsIt => NULL;
END;
--************************************************
Init: PROC =
BEGIN
wDir ← CDIO.GetWorkingDirectory[NIL];
CDCommandOpsExtras2.RegisterWithMenu[menu: $HardCopyMenu, entry: "b&w interpress", key: $InterpressPlot, proc: HardCopyCommand];
CDCommandOpsExtras2.RegisterWithMenu[menu: $HardCopyMenu, entry: "color interpress", key: $InterpressPlotC, proc: HardCopyCommand];
TerminalIO.WriteRope["BW Interpress plot loaded\n"];
END;
Init[];
END.