GriffinTextImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Written by: Maureen Stone, September 20, 1985 1:20:58 pm PDT
DIRECTORY
FS USING [ComponentPositions, ExpandName, Error],
GriffinDefs USING [UserMessage],
GriffinText,
GriffinFontDefs USING [Rot0Degrees, Regular, FontDescriptor],
GriffinStyle USING [FontFromInternalFont, InternalFont],
ImagerFont USING [Extents, RopeWidth, FontBoundingBox],
MessageWindow USING [Append, Blink],
StyleDefs USING [StyleHandle, Font],
ObjectDefs USING [tokenSize],
PointDefs,
Real USING [RoundI],
Rope USING [ROPE, Cat],
Vector2 USING [VEC],
ViewerTools USING [GetSelectionContents];
GriffinTextImpl: CEDAR PROGRAM
IMPORTS FS, GriffinDefs, ImagerFont, Real, Rope, GriffinStyle, MessageWindow, PointDefs, ViewerTools
EXPORTS GriffinText
~ BEGIN OPEN GriffinText;
ROPE: TYPE = Rope.ROPE;
X: NAT = PointDefs.X;
Y: NAT = PointDefs.Y;
InternalFont: TYPE = GriffinStyle.InternalFont;
ScrPt: TYPE = PointDefs.ScrPt;
StyleHandle: TYPE = StyleDefs.StyleHandle;
iFont: InternalFont ← NEW[GriffinFontDefs.FontDescriptor ← [
name: "Helvetica",
rotation: GriffinFontDefs.Rot0Degrees,
face: GriffinFontDefs.Regular,
points: 18]];
currentFont: StyleDefs.Font ← GriffinStyle.FontFromInternalFont[iFont];
GetFileName: PUBLIC PROC[wDir: ROPE] RETURNS[ROPE] = {
name: ROPE ← ViewerTools.GetSelectionContents[];
fullFName: ROPE; cp: FS.ComponentPositions;
IF name=NIL THEN SIGNAL GriffinDefs.UserMessage["Please select a name"];
[fullFName: fullFName, cp: cp] ← FS.ExpandName[name, wDir ! FS.Error => {
MessageWindow.Append[error.explanation, TRUE];
GOTO Fail};];
IF cp.ext.length=0 THEN fullFName ← Rope.Cat[fullFName, ".griffin"];
RETURN [fullFName];
EXITS Fail =>{
MessageWindow.Blink[];
RETURN[NIL];
};
};
Called from Save, Restore and Press. Return a full file path name without an extension
Called by FileOps
GetCaption: PUBLIC PROC RETURNS[ROPE] = {
RETURN[ViewerTools.GetSelectionContents[]];
};
GetBoundingBox: PUBLIC PROC[text: ROPE, style: StyleHandle, anchor: PointDefs.ObjPt] RETURNS[tl,br: ScrPt] = {
pt: PointDefs.ScrRealPt ← PointDefs.ObjToScrReal[anchor];
width: Vector2.VEC ← ImagerFont.RopeWidth[style.font, text];
extents: ImagerFont.Extents ← ImagerFont.FontBoundingBox[style.font];
token: REAL ← ObjectDefs.tokenSize; --select token space
tl[X] ← SELECT style.anchor FROM
left => Real.RoundI[pt[X]-token],
center => Real.RoundI[pt[X]-width.x/2.0],
right => Real.RoundI[pt[X]-width.x],
ENDCASE => ERROR;
tl[Y] ← Real.RoundI[pt[Y]+token];
br[X] ← SELECT style.anchor FROM
left => Real.RoundI[pt[X]+width.x],
center => Real.RoundI[pt[X]+width.x/2.0],
right => Real.RoundI[pt[X]+token],
ENDCASE => ERROR;
br[Y] ← Real.RoundI[pt[Y]-(extents.ascent+extents.descent)]-1;
RETURN[tl, br];
};
Called by Caption (DrawOps)
EditCaption: PUBLIC PROC[caption: ROPE] = {};
Hand the selected caption to the editing routine. Called by Modify (DrawOps)
--currently unused
GetFont: PUBLIC PROC RETURNS[StyleDefs.Font] = {RETURN[currentFont]};
called when? need to update current style when appropriate.
SetFont: PUBLIC PROC [font: StyleDefs.Font] = {currentFont ← font};
Called by SetCurrentStyle (GriffinStyleImpl)
END.