<> <> <> <<>> 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]; }; }; <> <> 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]; }; <> EditCaption: PUBLIC PROC[caption: ROPE] = {}; <> <<--currently unused>> GetFont: PUBLIC PROC RETURNS[StyleDefs.Font] = {RETURN[currentFont]}; <> SetFont: PUBLIC PROC [font: StyleDefs.Font] = {currentFont _ font}; <> <<>> END.