CDSilTextCommands.mesa (part of Chipndale)
Copyright © 1983, 1984 by Xerox Corporation. All rights reserved.
by Christian Jacobi June 24, 1983 5:03 pm
last edited Christian Jacobi October 22, 1984 9:40:00 am PDT
DIRECTORY
CD,
CDCommandOps,
CDOps,
CDPanel,
CDSequencer,
CDDefaults,
CDTexts,
CDValue,
CDSil,
Convert,
Rope,
TerminalIO,
UserProfile;
CDSilTextCommands: CEDAR PROGRAM
IMPORTS CDCommandOps, CDOps, CDPanel, CDSequencer, CDDefaults, CDTexts, CDValue, CDSil, Convert, Rope, TerminalIO, UserProfile =
BEGIN
FontRec: TYPE = CDTexts.FontRec;
CreateTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
ENABLE TerminalIO.UserAbort => GOTO userAbort;
fn: NATMIN[INT[fontNum]-1, CDValue.FetchInt[comm.design, $FontNumber]];
font: REF CDTexts.FontRec ← fontArray[fn];
r: Rope.ROPE ← TerminalIO.RequestRope["Create text\n", "please type: "];
ob: CD.ObPtr;
lev: CD.Level ← CDDefaults.CurrentLevel[comm.design];
IF Rope.IsEmpty[r] THEN {
TerminalIO.WriteRope["empty text not included\n"];
RETURN
};
ob ← CDTexts.CreateText[text: r, font: font, level: lev];
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.ApplicationPtr;
multiple: BOOL;
TerminalIO.WriteRope["Scale text\n"];
[first, multiple] ← CDOps.SelectedApplication[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;
ScaleApp[comm.design, first, factor];
TerminalIO.WriteRope["done\n"]
};
END;
ScaleApp: PROC [design: CD.Design, aptr: CD.ApplicationPtr, factor: REAL] =
BEGIN
IF aptr#NIL AND aptr.ob#NIL THEN
WITH aptr.ob.specificRef SELECT FROM
tp: CDTexts.TextPtr => {
font: REF CDTexts.FontRec ~ tp.font;
scaledFont: REF CDTexts.FontRec ~ CDTexts.MakeFont[
name: font.name,
scale: font.scale*factor,
whiteBorder: font.whiteBorder,
scaleByReplacingFontAllowed: font.scaleByReplacingFontAllowed,
levelSubstitute: font.levelSubstitute
];
IF scaledFont#NIL THEN {
txt: CD.ObPtr ~ CDTexts.CreateText[tp.text, scaledFont, aptr.ob.level];
IF txt#NIL THEN {
IF design#NIL THEN CDCommandOps.RedrawApplication[design, aptr];
aptr.ob ← txt;
IF design#NIL THEN CDCommandOps.RedrawApplication[design, aptr];
};
};
};
ENDCASE => ERROR
END;
fontNum: NAT = 8;
FontRange: TYPE = [0..fontNum);
fontArray: ARRAY FontRange OF REF CDTexts.FontRec←ALL[NIL];
techName: Rope.ROPE = "chipnsil";
MakeFont: PROC [fn: FontRange] RETURNS [REF CDTexts.FontRec] =
BEGIN
num: Rope.ROPE = Convert.RopeFromInt[from: fn, showRadix: FALSE];
fontname: Rope.ROPE ← UserProfile.Token[key:
Rope.Cat["Chipndale.", techName, ".Font", num]
];
scale: REAL ← (1.0/16)*UserProfile.Number[key:
Rope.Cat["Chipndale.", techName, ".ScaleFont", num],
default: 32
];
font: REF CDTexts.FontRec;
IF fontArray[fn]#NIL AND Rope.Equal[fontArray[fn].name, fontname] AND scale=fontArray[fn].scale THEN RETURN [fontArray[fn]];
IF NOT Rope.IsEmpty[fontname] THEN
font ← CDTexts.MakeFont[scale: scale, name: fontname];
IF font=NIL THEN {
fontname ← UserProfile.Token[key:
Rope.Cat["Chipndale.", techName, ".AlternateFont", num]
];
IF fontArray[fn]#NIL AND Rope.Equal[fontArray[fn].name, fontname] AND scale=fontArray[fn].scale THEN RETURN [fontArray[fn]];
IF NOT Rope.IsEmpty[fontname] THEN
font ← CDTexts.MakeFont[scale: scale, name: fontname];
};
IF font=NIL THEN {
font ← CDTexts.GetFont[key: $CDxCompatibilityFont];
};
RETURN [font]
END;
NoteProfileChange: UserProfile.ProfileChangedProc =
-- PROC [reason: ProfileChangeReason]
BEGIN
FOR fn: FontRange IN [0..fontNum) DO
fontArray[fn] ← MakeFont[fn];
ENDLOOP;
END;
ImplCommands: PROC [] =
BEGIN
CDSequencer.ImplementCommand[$DrawText, CreateTextComm, CDSil.cdsil];
CDSequencer.ImplementCommand[$ScaleTextS, ScaleTextComm, CDSil.cdsil];
CDValue.EnregisterKey[$FontNumber, CDSil.cdsil];
CDPanel.DefineIntEntry[cdValueKey: $FontNumber, tech: CDSil.cdsil,
text: "Font:", min: 0, default: 0, max: fontNum-1];
CDPanel.DefineNewLine[CDSil.cdsil];
UserProfile.CallWhenProfileChanges[NoteProfileChange];
END;
ImplCommands[];
END.