type

Font

src @Js
@Serializable { simple=true }
const class Font : Obj

Font models font-family, font-size, and font-style, and font-weight. Metrics are available for a predefined set of fonts.

constructors

fromProps

Construct from a map of CSS props such as font-family, font-size.

fromStr

Parse font from string using CSS shorthand format for supported properties

make

Construct with it-block

fields

names

List of prioritized family names

size

Size of font in points.

style

Style as normal, italic, or oblique

weight

Weight as number from 100 to 900

methods

equals

Equality is based on all fields.

hash

Return hash of all fields

name

First family name in names

toProps

Get CSS style properties for this font.

toSize

Return this font with different point size.

toStr

Format as "[style] [weight] <size>pt <names>"

toStyle

Return this font with different style

toWeight

Return this font with different weight.

Slot Details

equals

src virtual override Bool equals(Obj? that)

Equality is based on all fields.

fromProps

src static new fromProps(Str:Str props)

Construct from a map of CSS props such as font-family, font-size. Also see toProps.

fromStr

src static new fromStr(Str s, Bool checked := true)

Parse font from string using CSS shorthand format for supported properties:

[<style>] [<weight>] <size> <names>

Examples:

Font.fromStr("12pt Arial")
Font.fromStr("bold 10pt Courier")
Font.fromStr("italic bold 8pt Times")
Font.fromStr("italic 300 10pt sans-serif")

hash

src virtual override Int hash()

Return hash of all fields

make

src new make(|This| f)

Construct with it-block

name

src Str name()

First family name in names

names

src const Str[] names := Str["sans-serif"]

List of prioritized family names

size

src const Float size := 11.0f

Size of font in points.

style

src const FontStyle style := FontStyle.normal

Style as normal, italic, or oblique

toProps

src Str:Str toProps()

Get CSS style properties for this font. Also see fromProps

toSize

src Font toSize(Float size)

Return this font with different point size.

toStr

src virtual override Str toStr()

Format as "[style] [weight] <size>pt <names>"

toStyle

src Font toStyle(FontStyle style)

Return this font with different style

toWeight

src Font toWeight(FontWeight weight)

Return this font with different weight.

weight

src const FontWeight weight := FontWeight.normal

Weight as number from 100 to 900