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, April 11, 1985 11:29:25 am PST
Last Edited by: Beretta, January 18, 1985 1:15:04 pm PST
DIRECTORY
CD,
CDApplications,
CDCommandOps,
--CDDefaults,
CDIO,
CDOps,
CDPanel,
CDSequencer,
CDSil,
CDTexts,
CDValue,
Convert,
FileNames,
Rope,
TerminalIO,
UserProfile;
CDSilTextCommands: CEDAR PROGRAM
IMPORTS CDApplications, CDCommandOps, --CDDefaults,-- CDIO, CDOps, CDPanel, CDSequencer, CDSil, CDTexts, CDValue, Convert, FileNames, Rope, TerminalIO, UserProfile =
BEGIN
FontRec: TYPE = CDTexts.FontRec;
CreateTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
fn: NATMIN[INT[fontNum]-1,
CDValue.FetchInt[boundTo: comm.design, key: $CDSilFontNumber, propagation: technology]
];
font: REF CDTexts.FontRec ← fontArray[fn];
r: Rope.ROPE ← TerminalIO.RequestRope["Create text\n", "please type: "];
ob: CD.ObPtr;
lev: CD.Layer ← CDDefaults.CurrentLayer[comm.design]; NOT YET GOOD; WAIT FOR IMAGER
lev: CD.Layer ← CDSil.xneutral;
IF Rope.IsEmpty[r] THEN {
TerminalIO.WriteRope["empty text not included\n"];
RETURN
};
ob ← CDTexts.CreateText[text: r, font: font, layer: lev];
CDOps.AddAnObject[design: comm.design, ob: ob, location: comm.pos, orientation: 0];
END;
ChangeTextComm: PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.ApplicationPtr ← CDCommandOps.TheApplication[comm, "change text"];
IF ap#NIL THEN {
WITH ap.ob.specificRef SELECT FROM
t: CDTexts.TextPtr => {
ob: CD.ObPtr;
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.font, layer: ap.ob.layer];
CDOps.DelayedRedraw[comm.design, CDApplications.ARectO[ap]];
IF ob#NIL THEN ap.ob ← ob;
CDOps.DelayedRedraw[comm.design, CDApplications.ARectO[ap], FALSE];
}
}
ENDCASE => TerminalIO.WriteRope["selected ob is not text; not done\n"];
};
END;
ChangeFontComm: PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.ApplicationPtr ← CDCommandOps.TheApplication[comm, "change font"];
IF ap#NIL THEN {
WITH ap.ob.specificRef SELECT FROM
t: CDTexts.TextPtr => {
fn: NATMIN[INT[fontNum]-1, CDValue.FetchInt[comm.design, $CDSilFontNumber]];
font: REF CDTexts.FontRec ← fontArray[fn];
ob: CD.ObPtr ← CDTexts.CreateText[text: t.text, font: font, layer: ap.ob.layer];
CDOps.DelayedRedraw[comm.design, CDApplications.ARectO[ap]];
IF ob#NIL THEN ap.ob ← ob;
CDOps.DelayedRedraw[comm.design, CDApplications.ARectO[ap], FALSE];
}
ENDCASE => TerminalIO.WriteRope["selected ob is not text; not 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,
scaleByReplacingFontAllowed: font.scaleByReplacingFontAllowed,
layerSubstitute: font.layerSubstitute
];
IF scaledFont#NIL THEN {
txt: CD.ObPtr ~ CDTexts.CreateText[tp.text, scaledFont, aptr.ob.layer];
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";
Fontname: PROC [fn: FontRange] RETURNS [fontname: Rope.ROPE] =
BEGIN
num: Rope.ROPE = Convert.RopeFromInt[from: fn, showRadix: FALSE];
fontname ← UserProfile.Token[key: Rope.Cat["ChipNDale.", techName, ".Font", num]];
IF Rope.IsEmpty[fontname] THEN fontname ← DefaultFontName[fn];
END;
MakeFont: PROC [fn: FontRange] RETURNS [REF CDTexts.FontRec] =
BEGIN
font: REF CDTexts.FontRec ← NIL;
fontname : Rope.ROPE ← Fontname[fn];
scale: REAL ← (1.0*UserProfile.Number[key:
Rope.Cat["ChipNDale.", techName, ".ScaleFont", Convert.RopeFromInt[fn]],
default: 32
])/16;
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 {
fontname ← CDIO.MakeName [base: fontname, ext: "Strike", wDir: "/Indigo/AltoFonts/"];
font ← CDTexts.MakeFont[scale: scale, name: fontname]
};
IF font=NIL THEN {
font ← CDTexts.GetFont[key: $CDxCompatibilityFont];
};
RETURN [font]
END;
DefaultFontName: PROC [fn: FontRange] RETURNS [Rope.ROPE] =
BEGIN
RETURN [SELECT fn FROM
0 => "Helvetica10.strike",
1 => "Helvetica7.strike",
2 => "Gates32.strike",
3 => "Template64.strike",
4 => "Helvetica14.strike",
5 => "Helvetica18.strike",
6 => "TimesRoman10.strike",
7 => "Hippo10.strike",
ENDCASE => NIL]
END;
NoteProfileChange: UserProfile.ProfileChangedProc =
-- PROC [reason: ProfileChangeReason]
BEGIN
FOR fn: FontRange IN [0..fontNum) DO
fontArray[fn] ← MakeFont[fn];
ENDLOOP;
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 ← fontArray[i].name;
IF Rope.IsEmpty[name] THEN name ← " ?? " ;
list ← CONS[name, list]
ENDLOOP;
n ← TerminalIO.RequestSelection[label: "change font", choice: list];
IF n>0 THEN {
num: INT ← fontNum-n;
name: Rope.ROPE ← FileNames.GetShortName[fontArray[num].name];
IF ~Rope.IsEmpty[name] THEN {
CDValue.StoreInt[comm.design, $CDSilFontNumber, num];
CDValue.Store[comm.design, $CDSilFontName, name];
CDPanel.RedisplayLabels[comm.design];
TerminalIO.WriteRope[Rope.Cat[" ", name, " 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];
CDValue.StoreInt[CDSil.cdsil, $CDSilFontNumber, 0];
CDValue.Store[CDSil.cdsil, $CDSilFontName, FileNames.GetShortName[fontArray[0].name]];
END;
ImplCommands[];
END.
Edited on January 18, 1985 1:13:03 pm PST, by Beretta
Eliminated alternate font stuff.
changes to: MakeFont: if a font cannot be made, $CDxCompatibilityFont is choosen, CDIO.MakeName is called to put wDir: "/Indigo/AltoFonts/" and ext: "Strike".