CDSilTextCommands.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 24, 1985 10:49:59 am PDT
gbb September 13, 1985 3:27:14 pm PDT
DIRECTORY
CD,
CDInstances,
CDCommandOps,
CDLayers,
CDOps,
CDPanel,
CDSequencer,
CDSil,
CDTexts,
CDValue,
Convert,
FileNames,
IO,
Rope,
TerminalIO,
UserProfile;
CDSilTextCommands: CEDAR PROGRAM
IMPORTS CDInstances, CDCommandOps, CDLayers, CDOps, CDPanel, CDSequencer, CDSil, CDTexts, CDValue, Convert, FileNames, IO, Rope, TerminalIO, UserProfile =
BEGIN
techName: Rope.ROPE = "ChipNSil";
fontNum: NAT = 10;
FontRange: TYPE = [0..fontNum);
fontArray: ARRAY FontRange OF CDTexts.CDFont ← ALL[NIL];
lambda: CD.Number = 2;
CurrentFontNum: PROC [design: CD.Design] RETURNS [fn: FontRange] =
BEGIN
i: INT ← CDValue.FetchInt[boundTo: design, key: $CDSilFontNumber, propagation: technology];
fn ← MAX[MIN[INT[fontNum]-1, i], 0];
END;
SetFontNumber: PROC [design: REF, n: INT] =
BEGIN
name: Rope.ROPENIL;
n ← MAX[MIN[INT[fontNum]-1, n], 0];
name ← UseName[n];
CDValue.StoreInt[design, $CDSilFontNumber, n];
CDValue.Store[design, $CDSilFontName, name];
WITH design SELECT FROM
d: CD.Design => CDPanel.RedisplayLabels[d];
ENDCASE => NULL;
END;
UseName: PROC [fn: FontRange, full: BOOLFALSE] RETURNS [name: Rope.ROPENIL] =
BEGIN
IF fontArray[fn]#NIL THEN name ← fontArray[fn].supposedName;
IF Rope.IsEmpty[name] THEN name ← " ?? "
ELSE {
IF ~full THEN name ← FileNames.GetShortName[name];
IF fontArray[fn].scaleI#lambda THEN
name ← IO.PutFR["%0g[%0g/2]", IO.rope[name], IO.int[fontArray[fn].scaleI]];
};
END;
CurrentFont: PROC [d: CD.Design] RETURNS [font: CDTexts.CDFont ← NIL] =
BEGIN
fn: FontRange ← CurrentFontNum[d];
font ← fontArray[fn];
END;
CreateTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
ob: CD.Object;
lay: CD.Layer;
r: Rope.ROPE;
font: CDTexts.CDFont ← CurrentFont[comm.design];
CDPanel.RedisplayLabels[comm.design];
IF font=NIL THEN {
TerminalIO.WriteRope["** no font\n"];
RETURN
};
r ← TerminalIO.RequestRope["create text >"];
lay ← CDLayers.CurrentLayer[comm.design];
IF Rope.IsEmpty[r] THEN {
TerminalIO.WriteRope["empty text not included\n"];
RETURN
};
ob ← CDTexts.CreateText[text: r, font: font, layer: lay];
IF ob=NIL THEN {
TerminalIO.WriteRope["not done\n"];
RETURN
};
CDOps.AddAnObject[design: comm.design, ob: ob, location: comm.pos, orientation: 0];
END;
ChangeTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ;
CDPanel.RedisplayLabels[comm.design];
inst ← CDCommandOps.TheInstance[comm, "change text"];
IF inst#NIL THEN {
WITH inst.ob.specificRef SELECT FROM
t: CDTexts.TextPtr => {
ob: CD.Object;
r: Rope.ROPE;
TerminalIO.WriteRope["replace text """];
TerminalIO.WriteRope[t.text];
TerminalIO.WriteRope[""" >"];
r ← TerminalIO.RequestRope[];
IF Rope.IsEmpty[r] THEN TerminalIO.WriteRope["empty text not used\n"]
ELSE {
ob ← CDTexts.CreateText[text: r, font: t.cdFont, layer: inst.ob.layer];
CDOps.DelayedRedraw[comm.design, CDInstances.InstRectO[inst]];
IF ob#NIL THEN inst.ob ← ob;
CDOps.DelayedRedraw[comm.design, CDInstances.InstRectO[inst], FALSE];
}
}
ENDCASE => TerminalIO.WriteRope["selected ob is not text; not done\n"];
};
END;
ChangeFontComm: PROC [comm: CDSequencer.Command] =
BEGIN
fn: FontRange ← CurrentFontNum[comm.design];
font: CDTexts.CDFont ← fontArray[fn];
CDPanel.RedisplayLabels[comm.design];
IF font=NIL THEN {
TerminalIO.WriteRope ["** no font\n"];
RETURN
};
FOR all: CD.InstanceList ← CDOps.InstList[comm.design], all.rest WHILE all # NIL DO
IF all.first.selected THEN
IF ISTYPE [all.first.ob.specificRef, CDTexts.TextPtr] THEN BEGIN
ob: CD.Object ← CDTexts.CreateText [
text: NARROW[all.first.ob.specificRef, CDTexts.TextPtr].text,
font: font,
layer: all.first.ob.layer];
CDOps.DelayedRedraw [comm.design, CDInstances.InstRectO[all.first]];
IF ob#NIL THEN all.first.ob ← ob;
CDOps.DelayedRedraw[comm.design, CDInstances.InstRectO[all.first], FALSE]
END
ENDLOOP
END;
NoteProfileChange: UserProfile.ProfileChangedProc =
-- PROC [reason: ProfileChangeReason]
BEGIN
SupposedFontName: PROC [fn: FontRange] RETURNS [fontName: Rope.ROPE, scale: INT] =
BEGIN
DefaultFontName: PROC [fn: FontRange] RETURNS [Rope.ROPE] =
BEGIN
RETURN [SELECT fn FROM
0 => "Xerox/TiogaFonts/Helvetica10",
1 => "Xerox/TiogaFonts/Helvetica8",
2 => "Xerox/TiogaFonts/Gates32",
3 => "Xerox/TiogaFonts/Template64",
4 => "Xerox/TiogaFonts/Helvetica14",
5 => "Xerox/TiogaFonts/Helvetica18",
6 => "Xerox/TiogaFonts/TimesRoman10",
7 => "Xerox/TiogaFonts/TimesRoman14",
8 => "Xerox/TiogaFonts/Helvetica8I",
9 => "Xerox/TiogaFonts/Hippo10",
ENDCASE => NIL]
END;
num: Rope.ROPE = Convert.RopeFromInt[from: fn, showRadix: FALSE];
fontName ← UserProfile.Token[key: Rope.Cat["ChipNDale.", techName, ".Font", num]];
scale ← UserProfile.Number[key:
Rope.Cat["ChipNDale.", techName, ".ScaleFont", Convert.RopeFromInt[fn]],
default: 2
];
IF Rope.IsEmpty[fontName] THEN {
fontName ← DefaultFontName[fn];
scale ← lambda;
};
END;
FontForIndex: PROC [fn: FontRange] RETURNS [font: CDTexts.CDFont ← NIL] =
BEGIN
fontName: Rope.ROPE;
scale: INT;
[fontName, scale] ← SupposedFontName[fn];
font ← fontArray[fn];
IF fontArray[fn]=NIL
OR ~Rope.Equal[fontArray[fn].supposedName, fontName]
OR scale#fontArray[fn].scaleI
THEN IF NOT Rope.IsEmpty[fontName] THEN
font ← CDTexts.MakeFont[name: fontName, scale: scale]
END;
changed: BOOLFALSE;
FOR fn: FontRange IN [0..fontNum) DO
newFont: CDTexts.CDFont ← FontForIndex[fn];
changed ← changed OR fontArray[fn]#newFont;
fontArray[fn] ← newFont;
ENDLOOP;
IF changed AND reason=edit THEN
TerminalIO.WriteRope["ChipNSil Font has changed; reset all font buttons\n"];
END;
ChangeDefaultFont: PROC [comm: CDSequencer.Command] =
BEGIN
n: INT;
list: LIST OF Rope.ROPENIL;
TerminalIO.WriteRope["change font\n"];
FOR i: INT IN FontRange DO
name: Rope.ROPE ← UseName[i, FALSE];
list ← CONS[name, list]
ENDLOOP;
n ← TerminalIO.RequestSelection[label: "change font", choice: list];
IF n>0 THEN {
num: INT ← fontNum-n;
SetFontNumber[comm.design, num];
TerminalIO.WriteRope[Rope.Cat[" ", UseName[num, TRUE], " for text inputs\n"]];
}
END;
ImplCommands: PROC [] =
BEGIN
CDSequencer.ImplementCommand[$DrawText, CreateTextComm, CDSil.cdsil];
CDSequencer.ImplementCommand[$ChangeText, ChangeTextComm, CDSil.cdsil];
CDSequencer.ImplementCommand[$ChangeFont, ChangeFontComm, CDSil.cdsil];
CDValue.EnregisterKey[$CDSilFontNumber, CDSil.cdsil];
CDValue.EnregisterKey[$CDSilFontName, CDSil.cdsil];
CDPanel.DefineButton[tech: CDSil.cdsil, name: "font", proc: ChangeDefaultFont];
CDPanel.DefineLabel[tech: CDSil.cdsil,
name: " ",
cdValueKey: $CDSilFontName
];
CDPanel.DefineNewLine[CDSil.cdsil];
UserProfile.CallWhenProfileChanges[NoteProfileChange];
SetFontNumber[CDSil.cdsil, 0];
END;
ImplCommands[];
END.
Edited on January 18, 1985 1:13:03 pm PST, by Beretta
Eliminated alternate font stuff.
changes to: FontForIndex: if a font cannot be made, $CDxCompatibilityFont is choosen, CDIO.MakeName is called to put wDir: "/Indigo/AltoFonts/" and ext: "Strike".
Edited on May 31, 1985 1:35:21 pm PDT, by Jacobi
redone completely for Cedar 6.0
gbb September 13, 1985 3:26:19 pm PDT
changes to: ChangeFontComm: Change is applied to all selected instances.