10 font%

▼ |  | The Racket Drawing Toolkit

1 | Overview
2 | bitmap%
3 | bitmap-dc%
4 | brush%
5 | brush-list%
6 | color%
7 | color-database<%>
8 | dc<%>
9 | dc-path%
10 | font%
11 | font-list%
12 | font-name-directory<%>
13 | gl-config%
14 | gl-context<%>
15 | linear-gradient%
16 | pdf-dc%
17 | pen%
18 | pen-list%
19 | point%
20 | post-script-dc%
21 | ps-setup%
22 | radial-gradient%
23 | record-dc%
24 | region%
25 | svg-dc%
26 | Drawing Functions
27 | Drawing Contracts
28 | Signature and Unit
29 | Unsafe Libraries
30 | Drawing Conveniences
31 | Platform Dependencies
| Bibliography
| Index

On this page:

make-object
get-face
get-family
get-feature-settings
get-font-id
get-hinting
get-point-size
get-size
get-size-in-pixels
get-smoothing
get-style
get-underlined
get-weight
screen-glyph-exists?

top contents ← prev up next →

class font% : class?
superclass: object%

A font is an object which determines the appearance of text, primarily when drawing text to a device context. A font is determined by eight properties:

- size — The size of the text, either in points (the default) or logical drawing units, depending on the “size-in-pixels?” property (see below).

- family — A platform- and device-independent font designation. The families are:

  - 'default

  - 'decorative

  - 'roman

  - 'script

  - 'swiss

  - 'modern (fixed width)

  - 'symbol (Greek letters and more)

  - 'system (similar to the font to draw control labels, but see normal-control-font)

  > > > The terminology “family” and “face” is mangled relative to its usual meaning. A font% “face” is really used more like a font family in the usual terminology or more generally as a face-description string that is combined with other font% attributes to arrive at a face. A font% “family” is a kind of abstract font family that is mapped to a particular font family on a given platform.

- face — A string face name, such as "Courier". The format and meaning of a face name is platform- and device-specific. If a font’s face name is #f, then the font’s appearance depends only on the family. If a face is provided but no mapping is available for the face name (for a specific platform or device), then the face name is ignored and the family is used. See font-name-directory<%> for information about how face names are mapped for drawing text.

- style — The slant style of the font, one of:

  - 'normal

  - 'slant (a.k.a “oblique”)

  - 'italic

- weight — The weight of the font, one of:

  - (integer-in 100 1000)

  - 'thin (equivalent to 100)

  - 'ultralight (equivalent to 200)

  - 'light (equivalent to 300)

  - 'semilight (equivalent to 350)

  - 'book (equivalent to 380)

  - 'normal (equivalent to 400)

  - 'medium (equivalent to 500)

  - 'semibold (equivalent to 600)

  - 'bold (equivalent to 700)

  - 'ultrabold (equivalent to 800)

  - 'heavy (equivalent to 900)

  - 'ultraheavy (equivalent to 1000)

  Changed in version 1.14 of package draw-lib: Changed to allow integer values and the symbols 'thin, 'ultralight, 'semilight, 'book, 'medium, 'semibold, 'ultrabold, 'heavy, and 'ultraheavy.

- underline? — #t for underlined, #f for plain.

- smoothing — Amount of anti-alias smoothing, one of:

  - 'default (platform-specific, sometimes user-configurable)

  - 'partly-smoothed (gray anti-aliasing)

  - 'smoothed (sub-pixel anti-aliasing)

  - 'unsmoothed

- size-in-pixels? — #t if the size of the font is in logical drawing units (i.e., pixels for an unscaled screen or bitmap drawing context), #f if the size of the font is in points, where a point is equal to 1 pixel on Mac OS and (/ 96 72) pixels on Windows and Unix

- hinting — Whether font metrics should be rounded to integers:

  - 'aligned (the default) — rounds to integers to improve the consistency of letter spacing for pixel-based targets, but at the expense of making metrics unscalable

  - 'unaligned — disables rounding

- feature settings — A hash of OpenType feature settings to enable or disable optional typographic features of OpenType fonts. Each entry in the hash maps a four-letter OpenType feature tag to its desired value. For boolean OpenType features, a value of 0 means “disabled” and a value of 1 means “enabled”; for other features, the meaning of the value varies (and may even depend on the font itself).

  Added in version 1.19 of package draw-lib.

To avoid creating multiple fonts with the same characteristics, use the global font-list% object the-font-list.

See also font-name-directory<%>.

Changed in version 1.2 of package draw-lib: Defined “points” as (/ 96 72) pixels on Windows, independent of the screen resolution.
Changed in version 1.14: Changed “weight” to allow integer values and the symbols 'thin, 'ultralight, 'semilight, 'book, 'medium, 'semibold, 'ultrabold, 'heavy, and 'ultraheavy.
Changed in version 1.19: Added the “feature settings” property to control OpenType features.

> constructor (make-object font%) → (is-a?/c font%)
> (make-object font% |  | size |  |  |  |
> |  | family |  |  |  |
> | [ | style |  |  |  |
> |  | weight |  |  |  |
> |  | underline? |  |  |  |
> |  | smoothing |  |  |  |
> |  | size-in-pixels? |  |  |  |
> |  | hinting |  |  |  |
> |  | feature-settings]) |  | → |  | (is-a?/c font%)
> size : (real-in 0.0 1024.0)
> family : font-family/c
> style : font-style/c = 'normal
> weight : font-weight/c = 'normal
> underline? : any/c = #f
> smoothing : font-smoothing/c = 'default
> size-in-pixels? : any/c = #f
> hinting : font-hinting/c = 'aligned
> feature-settings : font-feature-settings/c = (hash)
> (make-object font% |  | size |  |  |  |
> |  | face |  |  |  |
> |  | family |  |  |  |
> | [ | style |  |  |  |
> |  | weight |  |  |  |
> |  | underline? |  |  |  |
> |  | smoothing |  |  |  |
> |  | size-in-pixels? |  |  |  |
> |  | hinting |  |  |  |
> |  | feature-settings]) |  | → |  | (is-a?/c font%)
> size : (real-in 0.0 1024.0)
> face : string?
> family : font-family/c
> style : font-style/c = 'normal
> weight : font-weight/c = 'normal
> underline? : any/c = #f
> smoothing : font-smoothing/c = 'default
> size-in-pixels? : any/c = #f
> hinting : font-hinting/c = 'aligned
> feature-settings : font-feature-settings/c = (hash)

When no arguments are provided, creates an instance of the default font. If no face name is provided, the font is created without a face name.

See font% for information about family, style, weight, smoothing, size-in-pixels?, hinting, and feature-settings. font-name-directory<%>.

See also make-font.

Changed in version 1.4 of package draw-lib: Changed size to allow non-integer and zero values.
Changed in version 1.14: Changed weight to allow integer values and the symbols 'thin, 'ultralight, 'semilight, 'book, 'medium, 'semibold, 'ultrabold, 'heavy, and 'ultraheavy.
Changed in version 1.19: Added the optional feature-settings argument.

> method (send a-font get-face) → (or/c string? #f)

Gets the font’s face name, or #f if none is specified.

> method (send a-font get-family) → font-family/c

Gets the font’s family. See font% for information about families.

> method (send a-font get-feature-settings) → font-feature-settings/c

Gets the font’s OpenType feature settings.

> method (send a-font get-font-id) → exact-integer?

Gets the font’s ID, for use with a font-name-directory<%>. The ID is determined by the font’s face and family specifications, only.

> method (send a-font get-hinting) → font-hinting/c

Gets the font’s hinting. See font% for information about hinting.

> method (send a-font get-point-size) → (integer-in 1 1024)

Gets the font’s size rounded to the nearest non-zero integer. Despite the method’s name, the result is in either logical units or points, depending on the result of get-size-in-pixels.

See get-size, instead. The get-point-size method is provided for backward compatibility.

> method (send a-font get-size [in-pixels?]) → (real-in 0.0 1024.0)
> in-pixels? : any/c = (send a-font get-size-in-pixels)

Gets the font’s size (roughly the height). If in-pixels? is #f, the size is in points, otherwise it is in logical units.

Due to space included in a font by a font designer, a font tends to generate text that is slightly taller than the nominal size.

Added in version 1.4 of package draw-lib.
Changed in version 1.19: Added the in-pixels? argument.

> method (send a-font get-size-in-pixels) → boolean?

Returns #t if get-size defaults to reporting the size in logical drawing units, #f if it defaults to reporting points.

> method (send a-font get-smoothing) → font-smoothing/c

Gets the font’s anti-alias smoothing mode. See font% for information about smoothing.

> method (send a-font get-style) → font-style/c

Gets the font’s slant style. See font% for information about styles.

> method (send a-font get-underlined) → boolean?

Returns #t if the font is underlined or #f otherwise.

> method (send a-font get-weight) → font-weight/c

Gets the font’s weight. See font% for information about weights.

> > method
> > (send a-font screen-glyph-exists? |  | c |  |  |  |
> > | [ | for-label?]) |  | → |  | boolean?
> c : char?
> for-label? : any/c = #f

Returns #t if the given character has a corresponding glyph when drawing to the screen or a bitmap, #f otherwise.

If the second argument is true, the result indicates whether the glyph is available for control labels. Otherwise, it indicates whether the glyph is available for dc<%> drawing.

For dc<%> drawing, due to automatic font substitution when drawing or measuring text, the result of this method does not depend on this font’s attributes (size, face, etc.). The font’s attributes merely provide a hint for the glyph search.

See also glyph-exists? .
top contents ← prev up next →