<> <> <> DIRECTORY CD, CDApplications, CDOps, CDPanel, CDSequencer, CDTechnology, CDTexts, CDValue, CDSil, Convert, Rope, TerminalIO, UserProfile; CDSilTextCommands: CEDAR PROGRAM IMPORTS CDApplications, CDOps, CDPanel, CDSequencer, CDTechnology, CDTexts, CDValue, CDSil, Convert, Rope, TerminalIO, UserProfile = BEGIN FontRec: TYPE = CDTexts.FontRec; CreateTextComm: PROC [comm: CDSequencer.Command] = BEGIN ENABLE TerminalIO.UserAbort => GOTO userAbort; fn: NAT _ MIN[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 _ CDTechnology.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_1.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 CDOps.DelayedRedraw[design, CDApplications.ARectO[aptr]]; aptr.ob _ txt; IF design#NIL THEN CDOps.DelayedRedraw[design, CDApplications.ARectO[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.