• No results found

Registering fonts

In document SRC RR 68 pdf (Page 107-110)

7 Resources

7.10 Screen-dependent fonts

7.10.3 Registering fonts

Some screentypes allow the client to register fonts. The client registers the font’s strike (bits) and metrics (description) with theStrikeOracle. The name of the font is implied by the attributes in the metrics, so thelistandlookupmethods will find client-registered fonts.

TYPE

StrikeOracle = Oracle OBJECT METHODS

<* LL.sup <= VBT.mu *>

load(strike: Strike; metrics: Metrics): T RAISES {Failure, TrestleComm.Failure}; END;

The method callst.font.load(strike, metrics)creates a font owned byst

with the given strike and metrics and returns a handle to it.

Themetricsargument must define all of the initial fields of the font metrics record:

family,pointSize, ...,isAscii, and defaultChar. The valuesminBounds

andmaxBoundsmust be provided ifcharMetricsisNIL; otherwise ifprintWidth

isAnyValue, theloadmethod will compute them fromcharMetrics. If any of the remaining fields have the valueAnyValue, theloadmethod will compute them.

7.10.4 The handle object

TYPE

T <: Public;

Public = OBJECT (*CONST*) id: INTEGER;

metrics: Metrics END;

TYPE StrikeFont = T OBJECT METHODS <* LL.sup <= VBT.mu *>

strike(): Strike RAISES {TrestleComm.Failure} END;

TYPE Strike = OBJECT

METHODS <* LL.sup <= VBT.mu *> glyph(ch: INTEGER): ScrnPixmap.T; END;

Iffis aScrnFont.T, thenf.idis an identifier whose interpretation depends on the screentype that ownsfandf.metricsare the metrics forf. If in additionfis a

StrikeFont, thenf.strike()returnsf’s strike. The screentype of the strike’s pixmaps will be the screentype that ownsf.

Ifstris aStrike, thenstr.glyph(ch)is the pixmap for the characterch. This will be empty except for characters in the range[m.firstChar..m.lastChar], wheremis the metrics (see below) for the font of whichstris the strike.

PROCEDURE BoundingBox(txt: TEXT; fnt: T): Rect.T; <* LL arbitrary *>

Return the smallest rectangle that contains the bounding boxes of the characters oftxtiftxtwere painted in the fontfntwithtxt’s reference point at the origin.

PROCEDURE BoundingBoxSub( READONLY txt: ARRAY OF CHAR; fnt: T): Rect.T;

<* LL arbitrary *>

LikeBoundingBoxbut takes an array instead of aTEXT.

PROCEDURE TextWidth(txt: TEXT; fnt: T): INTEGER; <* LL arbitrary *>

Return the sum of the printing widths of the characters intxtin the fontfnt.

7.10.5 The raw representation

TYPE

CharMetric = RECORD printWidth: INTEGER; boundingBox: Rect.T; END;

CharMetrics = REF ARRAY OF CharMetric;

TheprintWidthof a character is the displacement to the next character’s reference point.

TheboundingBoxof a character is the smallest rectangle with sides parallel to the axes that contains the glyph of the character placed with its reference point at (0,0).

7.10 Screen-dependent fonts 99

TYPE

Metrics = OBJECT (*CONST*) family: TEXT; pointSize: INTEGER; slant: Slant; weightName: TEXT; version: TEXT; foundry: TEXT; width: TEXT; pixelsize: INTEGER; hres, vres: INTEGER; spacing: Spacing; averageWidth: INTEGER; charsetRegistry: TEXT; charsetEncoding: TEXT;

firstChar, lastChar: INTEGER; charMetrics: CharMetrics; selfClearing: BOOLEAN;

rightKerning, leftKerning: BOOLEAN; isAscii: BOOLEAN;

defaultChar: INTEGER;

minBounds, maxBounds: CharMetric; METHODS <* LL arbitrary *>

intProp(name: TEXT; ch: INTEGER := -1): INTEGER RAISES {Failure};

textProp(name: TEXT; ch: INTEGER := -1): TEXT RAISES {Failure};

END;

The fields fromfamilytocharSetEncodingin theMetricsobject specify the attributes that were defined for thelookupmethod. A value of*orAnyin one of these fields means that the corresponding attribute is unknown.

The integers firstChar and lastChar are the indices of the first and last characters defined in the font.

The arraycharMetricsspecifies the metrics of the individual characters. The metrics for characterch are incharMetrics[ch-firstChar]. If all characters have the same printWidthand boundingBox, then these values are stored in

minBoundsandmaxBoundsand thecharMetricsfield isNIL.

The flag selfClearingindicates whether the font is self-clearing, as defined in theVBTinterface, and the two kerning flags indicate the present of right and left kerning in the font.

The flag isAscii indicates that character codes 32-126 (base 10) have their normal ASCII meanings.

The integerdefaultCharis the code for the recommended character to display in the place of a character that isn’t defined for the font.

The rectangles minBounds.boundingBox and maxBounds.boundingBox

contain the meet and join, respectively, of the bounding boxes of all characters in the font when they are positioned with their reference points at (0, 0). The values

minBounds.printWidthand maxBounds.printWidthare the minimum and maximum printing widths for all characters in the font.

The method callm.intProp(nm)returns the integer value of the font attribute namednm, or raisesFailureif this attribute is not defined form. The method call

m.intProp(nm, ORD(ch))returns the integer value of the font attribute namednm

for the characterch, or raisesFailureif this attribute is not defined for(m, ch). ThetextPropmethod is similar.

The set of attributes returned by the metrics methods depend on the font. Fonts that are owned by X screentypes support the attributes defined in Part IV of X Window

System (op. cit.); we recommend that other fonts support them too. (To read an X font

attribute whose type is an X atom, use thetextPropmethod, which returns the name of the atom.)

END ScrnFont.

In document SRC RR 68 pdf (Page 107-110)