Class “Font”

Object > Font

Represents a font. See also FontValue

Type: Font extends Object
Constructor: public
Singleton: No
Namespace: tabris
Direct subclasses: None
JSX Support: No

Examples

JavaScript

import {Font} from 'tabris';

const font = Font.from('bold 24px');
console.log(font.size); // 24

See also:

JS Applying multiple font styles to TextViews

Constructor

new Font(size, family?, weight?, style?)

Parameter Type Description
size number Positive number in dip
family string[] Prioritized list of font families Optional.
weight 'black'
| 'bold'
| 'medium'
| 'thin'
| 'light'
| 'normal'
Boldness of the font Optional.
style 'italic' | 'normal' Face of the font family to be used Optional.

Methods

toString()

Returns a string representation of the font using the CSS font shorthand syntax.

Returns: string

Static Methods

from(fontValue)

Creates a new instance of Font using any valid font expression. For any other value, including null and 'initial' the method throws.

Parameter Type Description
fontValue FontValue The value to create a Font instance from

Returns: Font

isFontValue(value)

Returns true if value is a FontValue. This includes null and 'initial'. Use this to check if a value will be accepted by a font property. This is also a valid TypeScript type guard function.

Parameter Type Description
value any The value to test

Returns: boolean

isValidFontValue(value)

Returns true if value is a valid FontValue. This excludes null and 'initial'. Use this to check if a value will be accepted by Font.from. This is also a valid TypeScript type guard function.

Parameter Type Description
value any The value to test

Returns: value is FontValue

Properties

family

Prioritized list of font families

Type: string[]
Settable: No

This property can only be set via constructor. Once set, it cannot change anymore.

size

Positive number in dip

Type: number
Settable: No

This property can only be set via constructor. Once set, it cannot change anymore.

style

Face of the font family to be used

Type: 'italic' | 'normal'
Settable: No

This property can only be set via constructor. Once set, it cannot change anymore.

weight

Boldness of the font

Type: 'black'
| 'bold'
| 'medium'
| 'thin'
| 'light'
| 'normal'
Settable: No

This property can only be set via constructor. Once set, it cannot change anymore.

Static Properties

condensed

Type: "condensed"
Settable: No

monospace

Type: "monospace"
Settable: No

sansSerif

Type: "sans-serif"
Settable: No

serif

Type: "serif"
Settable: No