NMosTextCommands.mesa (part of Chipndale)
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, June 24, 1983 5:03 pm
last edited Christian Jacobi, September 23, 1985 6:35:51 pm PDT
DIRECTORY
CD,
CDTexts,
CDOps,
CDSequencer,
TerminalIO,
Rope,
CDValue,
NMos,
CDPanel;
NMosTextCommands: CEDAR PROGRAM
IMPORTS CDOps, CDSequencer, TerminalIO, CDTexts, Rope, CDValue, CDPanel, NMos =
BEGIN
CreateTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
ENABLE TerminalIO.UserAbort => GOTO userAbort;
fn: NATMIN[INT[fontNum]-1, CDValue.FetchInt[comm.design, $FontNumber]];
font: CDTexts.CDFont ← fontArray[fn];
r: Rope.ROPE ← TerminalIO.RequestRope["create text >"];
ob: CD.Object;
IF font=NIL THEN {
TerminalIO.WriteRope["** no font\n"];
RETURN
};
IF Rope.IsEmpty[r] THEN {
TerminalIO.WriteRope["empty text not included\n"];
RETURN
};
ob ← CDTexts.CreateText[r, font];
CDOps.AddAnObject[design: comm.design, ob: ob, location: comm.pos, orientation: 0];
EXITS
userAbort => {TerminalIO.WriteRope["discarded\n"]}
END;
ScaleTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
ff: REAL = 1.2599;
fff: REAL = ff*ff*ff;
first: CD.Instance;
multiple: BOOL;
TerminalIO.WriteRope["Scale text\n"];
[first, multiple] ← CDOps.SelectedInstance[comm.design];
IF multiple THEN TerminalIO.WriteRope["multiple selection; not done\n"]
ELSE IF first=NIL THEN TerminalIO.WriteRope["no selection; not done\n"]
ELSE IF NOT ISTYPE[first.ob.specificRef, CDTexts.TextPtr] THEN TerminalIO.WriteRope["not text; not done\n"]
ELSE {
factor: REAL𡤁.0;
n: INT ← TerminalIO.RequestSelection[
choice: LIST[" >>", " >", " <", " <<"],
label: "scale"
];
SELECT n FROM
1 => factor ← 1.0/fff;
2 => factor ← 1.0/ff;
3 => factor ← ff;
4 => factor ← fff;
ENDCASE => factor ← 1.0;
ScaleInst[comm.design, first, factor];
TerminalIO.WriteRope["done\n"]
};
END;
ScaleInst: PROC [design: CD.Design, aptr: CD.Instance, factor: REAL] =
BEGIN
IF aptr#NIL AND aptr.ob#NIL THEN
WITH aptr.ob.specificRef SELECT FROM
tp: CDTexts.TextPtr => {
font: CDTexts.CDFont = tp.cdFont;
scaledFont: REF CDTexts.FontRec = CDTexts.MakeFont[name: font.supposedName, scale: font.scaleI*factor];
IF scaledFont#NIL THEN {
txt: CD.Object = CDTexts.CreateText[tp.text, scaledFont, aptr.ob.layer];
IF txt#NIL THEN {
CDOps.DelayedRedraw[design, CDInstances.ARectO[aptr]];
aptr.ob ← txt;
CDOps.DelayedRedraw[design, CDInstances.ARectO[aptr]];
};
};
};
ENDCASE => ERROR
END;
fontNum: NAT = 5;
FontRange: TYPE = [0..fontNum);
fontArray: ARRAY FontRange OF CDTexts.CDFont;
ImplCommands: PROC [] =
BEGIN
CDSequencer.ImplementCommand[$DrawText, CreateTextComm, NMos.nmos];
CDSequencer.ImplementCommand[$ScaleTextS, ScaleTextComm, NMos.nmos];
CDValue.EnregisterKey[$FontNumber, NMos.nmos];
CDPanel.DefineIntEntry[cdValueKey: $FontNumber, tech: NMos.nmos,
text: "Font:", min: 0, default: 0, max: fontNum-1];
CDPanel.DefineNewLine[NMos.nmos];
fontArray[0] ← CDTexts.MakeFont[scale: 2, name: "Xerox/Tiogafonts/Helvetica10"];
fontArray[1] ← CDTexts.MakeFont[scale: 2, name: "Xerox/Tiogafonts/Gates32"];
fontArray[2] ← CDTexts.MakeFont[scale: 2, name: "Xerox/Tiogafonts/MusicFont10"];
fontArray[3] ← CDTexts.MakeFont[scale: 1, name: "Xerox/Tiogafonts/OldEnglish18"];
fontArray[4] ← CDTexts.MakeFont[scale: 1, name: "Xerox/Tiogafonts/TimesRoman36"];
END;
ImplCommands[];
END.