<> <> <> <> DIRECTORY Convert USING [AppendInt], Imager USING [Error], ImagerFont USING [Extents, Find, FontBoundingBox, RopeWidth, VEC, Width], Real USING [RoundI], RefText USING [AppendChar, AppendRope, ObtainScratch, ReleaseScratch, TrustTextAsRope], Rope USING [ROPE], UserProfile USING [Number, Token], VFonts USING [DefaultFont, defaultFont, ErrorCode, Font]; VFontsImpl: CEDAR PROGRAM IMPORTS Convert, Imager, ImagerFont, Real, RefText, UserProfile, VFonts EXPORTS VFonts ~ BEGIN OPEN VFonts; VEC: TYPE ~ ImagerFont.VEC; ROPE: TYPE = Rope.ROPE; Error: PUBLIC ERROR [code: VFonts.ErrorCode] ~ CODE; defaultFont: PUBLIC VFonts.Font _ NIL; EstablishFont: PUBLIC PROC [family: ROPE, size: CARDINAL, bold: BOOL _ FALSE, italic: BOOL _ FALSE, defaultOnFailure: BOOL _ TRUE ] RETURNS [font: Font _ NIL] ~ { scratch: REF TEXT ~ RefText.ObtainScratch[100]; text: REF TEXT _ scratch; text _ RefText.AppendRope[text, "Xerox/TiogaFonts/"]; text _ RefText.AppendRope[text, family]; text _ Convert.AppendInt[text, size]; IF bold THEN text _ RefText.AppendChar[text, 'B]; IF italic THEN text _ RefText.AppendChar[text, 'I]; font _ ImagerFont.Find[RefText.TrustTextAsRope[text] ! Imager.Error => IF defaultOnFailure THEN CONTINUE]; IF font=NIL THEN font _ defaultFont; RefText.ReleaseScratch[scratch]; }; CharWidth: PUBLIC PROC [char: CHAR, font: Font _ NIL] RETURNS [NAT] ~ { width: VEC ~ ImagerFont.Width[DefaultFont[font], [set: 0, code: ORD[char]]]; RETURN[Real.RoundI[width.x]]; }; StringWidth: PUBLIC PROC [string: ROPE, font: Font _ NIL] RETURNS [NAT] ~ { width: VEC ~ ImagerFont.RopeWidth[DefaultFont[font], string]; RETURN[Real.RoundI[width.x]]; }; FontHeight: PUBLIC PROC [font: Font _ NIL] RETURNS [NAT] ~ { extents: ImagerFont.Extents ~ ImagerFont.FontBoundingBox[DefaultFont[font]]; RETURN[Real.RoundI[extents.descent+extents.ascent]]; }; FontAscent: PUBLIC PROC [font: Font _ NIL] RETURNS [NAT] ~ { extents: ImagerFont.Extents ~ ImagerFont.FontBoundingBox[DefaultFont[font]]; RETURN[Real.RoundI[extents.ascent]]; }; CreateDefaultFont: PROC ~ { family: ROPE ~ UserProfile.Token["Viewers.DefaultFontFamily", "Tioga"]; size: INT ~ UserProfile.Number["Viewers.DefaultFontSize", 10]; err: BOOL _ FALSE; defaultFont _ EstablishFont[family: family, size: size, defaultOnFailure: FALSE ! Imager.Error => { err _ TRUE; CONTINUE }]; IF err THEN defaultFont _ EstablishFont[family: "Tioga", size: 10, defaultOnFailure: FALSE]; <> }; CreateDefaultFont[]; END.