<> <> <> <> <> 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.ROPE _ NIL; 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: BOOL_FALSE] RETURNS [name: Rope.ROPE _ NIL] = 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: BOOL _ FALSE; 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.ROPE_NIL; 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. <> <> <> <> <> <> <> <<>>