Drawing Utensils
5.1 Color
5.2 Pen
5.3 Brush
5.4 Font
5.5 Region
5.6 Path
On this page:
Font
Font.kind
Font.name
Font.size
Font.in_  pixels
Font.style
Font.weight
Font.has_  underline
Font.smoothing
Font.hinting
Font.features
Font.Feature  String
Font.Kind
Font.Kind.default
Font.Kind.decorative
Font.Kind.roman
Font.Kind.script
Font.Kind.swiss
Font.Kind.modern
Font.Kind.symbol
Font.Kind.system
Font.Style
Font.Style.normal
Font.Style.slant
Font.Style.italic
Font.Weight
Font.Weight.thin
Font.Weight.ultralight
Font.Weight.light
Font.Weight.semilight
Font.Weight.book
Font.Weight.normal
Font.Weight.medium
Font.Weight.semibold
Font.Weight.bold
Font.Weight.ultrabold
Font.Weight.heavy
Font.Weight.ultraheavy
Font.Smoothing
Font.Smoothing.default
Font.Smoothing.partly_  smoothed
Font.Smoothing.smoothed
Font.Smoothing.unsmoothed
Font.Hinting
Font.Hinting.aligned
Font.Hinting.unaligned
Font.get_  names
Font.Name  List  Kind
Font.Name  List  Kind.all
Font.Name  List  Kind.mono
Font.Name  List  Detail
Font.Name  List  Detail.face
Font.Name  List  Detail.font
Font.kind_  to_  name
Font.handle
Font.from_  handle
0.45+9.1.0.1

5.4 Font🔗ℹ

class

class draw.Font():

  constructor (

    ~kind: kind :: Font.Kind = #'default,

    ~name: name :: maybe(String) = #false,

    ~size: size :: Real.in(0.0, 1024.0) = 12.0,

    ~in_pixels: in_pixels :: Any.to_boolean = #false,

    ~style: style :: Font.Style = #'normal,

    ~weight: weight :: Font.Weight = #'normal,

    ~has_underline: has_underline :: Any = #false,

    ~smoothing: smoothing :: Font.Smoothing = #'default,

    ~hinting: hinting :: Font.Hinting = #'aligned,

    ~features: features :: Map.of(Font.FeatureString, Nat) = {},

  )

Creates an object representing a font configuration.

The kind argument acts as a default and fallback for name. The specific, system-specific font used for a kind can be obtained from Font.kind_to_name. For valid names on a system system, use Font.get_names.

The font size is in “points,” unless in_pixels is true. On Mac OS, 1 point is 1 pixel. On Windows and Unix, 1 point is 96/72 pixels.

The style and weight arguments select italic, slanted, and/or bold. If has_underline is true, then text is drawn as underlined as well.

The smoothing argument controls whether and how much anti-aliasing is applied to text, and hinting controls pixel alignment. See Font.Smoothing and Font.Hinting for more information.

The features argument provides access to additional font features. See Font.FeatureString for more information.

A font like an existing one can be constructed using with and the field names kind, name, size, in_pixels, style, weight, has_underline, smoothing, hinting, and features.

property

property (font :: draw.Font).kind :: Font.Kind

 

property

property (font :: draw.Font).name :: maybe(String)

 

property

property (font :: draw.Font).size :: Real.in(0.0, 1024.0)

 

property

property (font :: draw.Font).in_pixels :: Boolean

 

property

property (font :: draw.Font).style :: Font.Style

 

property

property (font :: draw.Font).weight :: Font.Weight

 

property

property (font :: draw.Font).has_underline :: Boolean

 

property

property (font :: draw.Font).smoothing :: Font.Smoothing

 

property

property (font :: draw.Font).hinting :: Font.Hinting

 

property

property (font :: draw.Font).features

  :: Map.of(Font.FeatureString, Nat)

Properties to access font components.

annotation

draw.Font.FeatureString

Satisfied by a 4-character string containing only   (i.e., a space), !, or characters with Char.to_int values between that of # and ~, inclusive.

The Font.features property of a font object is a map of OpenType feature settings to enable or disable optional typographic features of OpenType fonts. Each entry in the hash maps a Font.FeatureString 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).

A font kind, which is a fallback or default for a font name. The specific, system-specific font used for a Font.Kind can be obtained from Font.kind_to_name.

enumeration

enum draw.Font.Style

| normal

| slant

| italic

A font style. Typically, #'slant is a skewed form of a face’s base shape, while #'italic can be a different shape.

enumeration

enum draw.Font.Weight

| ~is_a Int.in(100 ..= 1000)

| thin

| ultralight

| light

| semilight

| book

| normal

| medium

| semibold

| bold

| ultrabold

| heavy

| ultraheavy

A font weight, either an integer in 100 to 1000 (inclusive) or one of the following symbols:

  • #'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)

A font smoothing (anti-aliasing) mode:

  • #'default: Platform-specific, sometimes user-configurable.

  • #'partly_smoothed: Grayscale anti-aliasing.

  • #'smoothed: Sub-pixel anti-aliasing.

  • #'unsmoothed: No anti-aliasing.

enumeration

enum draw.Font.Hinting

| aligned

| unaligned

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 less precisely scalable.

  • #'unaligned: Disables rounding.

function

fun draw.Font.get_names(

  ~kind: kind :: Font.NameListKind = #'all,

  ~detail: detail :: Font.NameListDetail = #'face

) :: List.of(String)

 

enumeration

enum draw.Font.NameListKind

| all

| mono

 

enumeration

enum draw.Font.NameListDetail

| face

| font

Returns a list of font names available on the current system. If kind is #'mono, then only names that are known to correspond to monospace fonts are included in the list.

If detail is #'face, then the result is in more standard terminology a list of typefaces, which are combined with style and weight options to arrive at a font. If detail is #'font, then the result includes a string for each available font.

function

fun draw.Font.kind_to_name(

  kind :: Font.Kind

) :: String

Returns the font name on the current system that is used whenever the given kind is specified.

property

property (path :: draw.Font).handle :: Any

 

function

fun draw.Font.from_handle(hand :: Any) :: Font

The Font.handle property returns a Racket object that corresponds to the font for use directly with racket/draw. The Font.from_handle function creates a Font from such a Racket object.