## 8.8 Text fonts

### 8.8.1 Description

Fonts are obtained by the `QTk.newFont` function. The only parameter of that function is a record describing the font in the following form: `font(param1:value1 ... paramX:valueX)`. Once obtained, a font can be used several times in different contexts (parameters of different widgets for example). Fonts can also be dynamically reconfigured and all widgets using the font redisplays themselves using the new attributes.

### 8.8.2 Parameters

- `family:VS`: The case-insensitive font family name. The following families are guaranteed to exist on all platforms: `Courier` (a monospaced ``typewriter'' font), `Times` (a serifed ``newspaper'' font), and `Helvetica` (a sans-serif ``European'' font). The most closely matching native font family will automatically be substituted when one of the above font families is used. The name may also be the name of a native, platform-specific font family; in that case it will work as desired on one platform but may not display correctly on other platforms. If the family is unspecified or unrecognized, a platform-specific default font will be chosen.

- `size:I`: The desired size of the font. If `I` is a positive number, it is interpreted as a size in points. If `I` is a negative number, its absolute value is interpreted as a size in pixels. If a font cannot be displayed at the specified size, a nearby size will be chosen. If size is unspecified or zero, a platform-dependent default size will be chosen. Sizes should normally be specified in points so the application will remain the same ruler size on the screen, even when changing screen resolutions or moving scripts across platforms. However, specifying pixels is useful in certain circumstances such as when a piece of text must line up with respect to a fixed-size bitmap.

- `weight:A`: The nominal thickness of the characters in the font. The atom `normal` specifies a normal weight font, while `bold` specifies a bold font. The closest available weight to the one specified will be chosen. The default weight is `normal`.

- `slant:A`: The amount the characters in the font are slanted away from the vertical. Valid values for slant are the atoms `roman` and `italic`. A roman font is the normal, upright appearance of a font, while an italic font is one that is tilted some number of degrees from upright. The closest available slant to the one specified will be chosen. The default slant is `roman`.

- `underline:B`: Specifies whether characters in this font should be underlined. The default value for `underline` is `false`. `B` must be a boolean value.

- `overstrike:B`: Specifies whether a horizontal line should be drawn through the middle of characters in this font. The default value for `overstrike` is `false`. `B` must be a boolean value.

### 8.8.3 Interface

Fonts obtained by `Qtk.newFont` are objects that support the following methods:

- `set(parameter1:value1 ... parameterX:valueX)`: Changes the value of one or more parameters. `parameterX` must be a valid parameter for the widget. `valueX` must be a valid value for the parameter.

- `get(parameter1:Variable1 ... parameterX:VariableX)`: Obtains the value of one or more parameters. `parameterX` must be a valid parameter for the widget. `VariableX` must be free variables that will receive the current value of the parameters.

- `delete`: Delete the font. If there are widgets using that font, it won't actually be deleted until all the instances are released. Those widgets will continue to display using the last known values for the font.

- `families(V)`: Binds `V` to a list a string containing all available font families on the platform.

- `measure(VS V ?displayof:D)`: Binds `V` to the amount of space the string `VS` would use in the given font when displayed in the window `D`. If the window `D` argument is omitted, it defaults to the main window. The return value is the total width in pixels of text, not including the extra pixels used by highly exaggerated characters such as cursive ``f''. If the string contains newlines or tabs, those characters are not expanded or treated specially when measuring the string.

- `metrics(A V ?displayof:D`: Binds `V` to metrics information of the font (font-specific data) when displayed in the window `D` or in the main window is the `displayof` parameter is not specified. The returned information depends on the value of `A`:

  - `ascent`: The amount in pixels that the tallest letter sticks up above the baseline of the font, plus any extra blank space added by the designer of the font.

  - `descent`: The largest amount in pixels that any letter sticks down below the baseline of the font, plus any extra blank space added by the designer of the font.

  - `linespace`: Returns how far apart vertically in pixels two lines of text using the same font should be placed so that none of the characters in one line overlap any of the characters in the other line. This is generally the sum of the ascent above the baseline line plus the descent below the baseline.

  - `fixed`: Returns a boolean flag that is ``1'' if this is a fixed-width font, where each normal character is the same width as all the other characters, or is ``0'' if this is a proportionally-spaced font, where individual characters have different widths. The widths of control characters, tab characters, and other non-printing characters are not included when calculating this value.