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, October 21, 1986 12:17:16 pm PDT
DIRECTORY
Ascii,
CD,
CDLayers,
CDOps,
CDPanel,
CDPanelFonts,
CDPrivate,
CDSequencer,
CDTexts,
Rope,
TerminalIO;
CDTextsCommands:
CEDAR
MONITOR
IMPORTS Ascii, CDLayers, CDOps, CDPanel, CDPanelFonts, CDSequencer, CDTexts, 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.Redisplay[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 ← CDPanelFonts.LayerForText[lay, comm.design.technology];
ob ← CDTexts.Create[text: r, font: font, layer: lay];
IF ob=NIL THEN CDSequencer.Quit["not done"];
CDOps.IncludeObject[design: comm.design, ob: ob, trans: [comm.pos, original]];
};
ChangeTextComm:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ;
CDPanel.Redisplay[comm.design];
inst ← CDOps.TheInstance[comm.design, "change text\n"];
IF inst#
NIL
THEN {
WITH inst.ob.specific
SELECT
FROM
t: CDTexts.TextSpecific => {
ob: CD.Object;
r: ROPE;
TerminalIO.PutRopes["replace text """, t.text, """ >"];
r ← TerminalIO.RequestRope[];
IF Rope.IsEmpty[r] THEN TerminalIO.PutRope["empty text not used\n"]
ELSE {
ob ← CDTexts.Create[text: r, font: t.cdFont, layer: inst.ob.layer, flip: CDTexts.IsFlipText[inst.ob]];
CDOps.RedrawInstance[comm.design, inst, TRUE];
IF ob#NIL THEN inst.ob ← ob;
CDOps.RedrawInstance[comm.design, inst, FALSE];
}
}
ENDCASE => TerminalIO.PutRope["selected ob is not text; not done\n"];
};
};
SetFlip:
PROC [design:
CD.Design, flip:
BOOL ←
TRUE]
RETURNS [cnt:
INT𡤀] = {
FOR il:
CD.InstanceList ← CDOps.InstList[design], il.rest
WHILE il#
NIL
DO
IF il.first.selected
AND CDTexts.IsText[il.first.ob]
THEN
IF (flip
AND CDTexts.IsRigidText[il.first.ob])
OR (~flip
AND CDTexts.IsFlipText[il.first.ob])
THEN {
ob:
CD.Object ← CDTexts.Create[
text: NARROW[il.first.ob.specific, CDTexts.TextSpecific].text,
font: NARROW[il.first.ob.specific, CDTexts.TextSpecific].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.PutF["%g texts converted to flip mode\n", [integer[cnt]]]
};
SetRigidComm:
PROC [comm: CDSequencer.Command] = {
cnt: INT ← SetFlip[comm.design, FALSE];
TerminalIO.PutF["%g texts converted to rigid mode\n", [integer[cnt]]];
};
ChangeFontComm:
PROC [comm: CDSequencer.Command] = {
n: INT ← 0; font: CDFont;
CDPanel.Redisplay[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 CDTexts.IsText[il.first.ob]
THEN
IF SetInstanceFont[comm.design, il.first, font] THEN n ← n+1;
ENDLOOP;
TerminalIO.PutF["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:
BOOL←
FALSE] = {
IF font#
NIL
THEN {
ob:
CD.Object ← CDTexts.Create[
text: NARROW[text.ob.specific, CDTexts.TextSpecific].text,
font: font,
layer: text.ob.layer,
flip: CDTexts.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 CDTexts.IsText[w.first.ob]
AND w.first.selected
THEN {
textPtr: CDTexts.TextSpecific ← NARROW[w.first.ob.specific];
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.PutF["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.