CDTextsCommands.mesa (part of ChipNDale)
Copyright © 1983, 1985, 1986 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, June 24, 1983 5:03 pm
gbb April 8, 1986 5:46:03 pm PST
Last Edited by: Christian Jacobi, September 2, 1986 11:55:30 am PDT
DIRECTORY
Ascii,
CD,
CDInstances,
CDCommandOps,
CDLayers,
CDOps,
CDPanel,
CDPanelFonts,
CDPanelFontsExtras,
CDPrivate,
CDSequencer,
CDTexts,
CDTextsExtras,
Rope,
TerminalIO;
CDTextsCommands: CEDAR MONITOR
IMPORTS Ascii, CDInstances, CDCommandOps, CDLayers, CDOps, CDPanel, CDPanelFonts, CDPanelFontsExtras, CDSequencer, CDTexts, CDTextsExtras, Rope, TerminalIO
SHARES CDTexts =
BEGIN
ROPE: TYPE = Rope.ROPE;
CDFont: TYPE = CDTexts.CDFont;
CreateTextComm: PROC [comm: CDSequencer.Command] = {
ob: CD.Object;
lay: CD.Layer;
r: ROPE;
font: CDFont ← CDPanelFonts.CurrentFont[comm.design];
CDPanel.RedisplayLabels[comm.design];
IF font=NIL THEN CDSequencer.Quit["** no font"];
r ← TerminalIO.RequestRope["create text >"];
IF Rope.IsEmpty[r] THEN CDSequencer.Quit["empty text not included"];
lay ← CDLayers.CurrentLayer[comm.design];
lay ← CDPanelFontsExtras.LayerForText[lay, comm.design.technology];
ob ← CDTexts.CreateText[text: r, font: font, layer: lay];
IF ob=NIL THEN CDSequencer.Quit["not done"];
CDOps.IncludeObjectI[design: comm.design, ob: ob, location: comm.pos, orientation: 0];
};
ChangeTextComm: PROC [comm: CDSequencer.Command] = {
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;
TerminalIO.WriteRopes["replace text """, t.text, """ >"];
r ← TerminalIO.RequestRope[];
IF Rope.IsEmpty[r] THEN TerminalIO.WriteRope["empty text not used\n"]
ELSE {
ob ← CDTextsExtras.Create[text: r, font: t.cdFont, layer: inst.ob.layer, flip: CDTextsExtras.IsFlipText[inst.ob]];
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"];
};
};
SetFlip: PROC [design: CD.Design, flip: BOOLTRUE] RETURNS [cnt: INT𡤀] = {
FOR il: CD.InstanceList ← CDOps.InstList[design], il.rest WHILE il#NIL DO
IF il.first.selected AND CDTextsExtras.IsText[il.first.ob] THEN
IF (flip AND CDTextsExtras.IsRigidText[il.first.ob]) OR (~flip AND CDTextsExtras.IsFlipText[il.first.ob]) THEN {
ob: CD.Object ← CDTextsExtras.Create[
text: NARROW[il.first.ob.specificRef, CDTexts.TextPtr].text,
font: NARROW[il.first.ob.specificRef, CDTexts.TextPtr].cdFont,
layer: il.first.ob.layer,
flip: flip
];
IF ob#NIL THEN il.first.ob ← ob;
cnt ← cnt+1
}
ENDLOOP;
IF cnt>0 THEN CDOps.Redraw[design];
};
SetFlipComm: PROC [comm: CDSequencer.Command] = {
cnt: INT ← SetFlip[comm.design, TRUE];
TerminalIO.WriteF["%g texts converted to flip mode\n", [integer[cnt]]]
};
SetRigidComm: PROC [comm: CDSequencer.Command] = {
cnt: INT ← SetFlip[comm.design, FALSE];
TerminalIO.WriteF["%g texts converted to rigid mode\n", [integer[cnt]]];
};
ChangeFontComm: PROC [comm: CDSequencer.Command] = {
n: INT ← 0; font: CDFont;
CDPanel.RedisplayLabels[comm.design];
font ← CDPanelFonts.CurrentFont[comm.design];
IF font=NIL THEN CDSequencer.Quit["** no font\n"];
FOR il: CD.InstanceList ← CDOps.InstList[comm.design], il.rest WHILE il#NIL DO
IF il.first.selected AND CDTextsExtras.IsText[il.first.ob] THEN
IF SetInstanceFont[comm.design, il.first, font] THEN n ← n+1;
ENDLOOP;
TerminalIO.WriteF["font changed for %g texts\n", [integer[n]]];
};
ChangeItalic: PROC [fontName: ROPE, italic: BOOL] RETURNS [new: ROPE] = {
pressFontLeng: INT = 17; pressFontName: ROPE = "Xerox/PressFonts/";
tiogaFontLeng: INT = 17; tiogaFontName: ROPE = "Xerox/TiogaFonts/";
leng: INT ← Rope.Length[fontName];
new ← fontName;
IF leng>tiogaFontLeng THEN
IF Rope.Equal[Rope.Substr[fontName, 0, tiogaFontLeng], tiogaFontName, FALSE] THEN {
IF Rope.Equal[Rope.Substr[fontName, 0, tiogaFontLeng], tiogaFontName, FALSE] THEN {
IF italic THEN {
IF Ascii.Upper[Rope.Fetch[fontName, leng-1]]='I THEN RETURN;
RETURN [Rope.Concat[fontName, "I"]];
}
ELSE {
IF Ascii.Upper[Rope.Fetch[fontName, leng-1]]#'I THEN RETURN;
RETURN [Rope.Substr[fontName, 0, leng-1]];
}
}
};
IF leng>pressFontLeng THEN
IF Rope.Equal[Rope.Substr[fontName, 0, pressFontLeng], pressFontName, FALSE] THEN {
IF italic THEN {
IF Ascii.Upper[Rope.Fetch[fontName, leng-1]]='I THEN RETURN;
RETURN [Rope.Replace[fontName, leng-2, 1, "i"]];
}
ELSE {
IF Ascii.Upper[Rope.Fetch[fontName, leng-2]]#'I THEN RETURN;
RETURN [Rope.Replace[fontName, leng-2, 1, "r"]];
}
}
};
SetInstanceFont: PROC [design: CD.Design, text: CD.Instance, font: CDFont] RETURNS [ok: BOOLFALSE] = {
IF font#NIL THEN {
ob: CD.Object ← CDTextsExtras.Create[
text: NARROW[text.ob.specificRef, CDTexts.TextPtr].text,
font: font,
layer: text.ob.layer,
flip: CDTextsExtras.IsFlipText[text.ob]];
CDOps.RedrawInstance[design, text];
IF ob#NIL THEN {text.ob ← ob; ok ← TRUE};
CDOps.RedrawInstance[design, text, FALSE];
}
};
SetItalicIzation: PROC [design: CD.Design, comment: BOOL] = {
n: INT ← 0;
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF CDTextsExtras.IsText[w.first.ob] AND w.first.selected THEN {
textPtr: CDTexts.TextPtr ← NARROW[w.first.ob.specificRef];
oldFontName: ROPE ← textPtr.cdFont.supposedName;
newFontName: ROPE ← ChangeItalic[oldFontName, comment];
IF ~Rope.Equal[oldFontName, newFontName] THEN {
font: CDFont ← CDTexts.MakeFont[newFontName, textPtr.cdFont.scaleI];
IF SetInstanceFont[design, w.first, font] THEN n ← n+1;
}
}
ENDLOOP;
TerminalIO.WriteF["comment property changed for %g texts\n", [integer[n]]];
};
MakeComment: PROC [comm: CDSequencer.Command] = {
SetItalicIzation[comm.design, TRUE]
};
UnMakeComment: PROC [comm: CDSequencer.Command] = {
SetItalicIzation[comm.design, FALSE]
};
CDSequencer.ImplementCommand[$DrawText, CreateTextComm];
CDSequencer.ImplementCommand[$ChangeText, ChangeTextComm];
CDSequencer.ImplementCommand[$ChangeFont, ChangeFontComm];
CDSequencer.ImplementCommand[$CDTextsRigid, SetRigidComm];
CDSequencer.ImplementCommand[$CDTextsFlip, SetFlipComm];
CDSequencer.ImplementCommand[$MakeComment, MakeComment];
CDSequencer.ImplementCommand[$UnMakeComment, UnMakeComment];
END.