Class “Font”

Object > Font

Represents a font. See also FontValue

Constructor public
Singleton No
Namespace tabris
Direct subclasses None
JSX support No

Example

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 Optional Description
size number No Positive number in dip
family string[] Yes Prioritized list of font families
weight 'black' | 'bold' | 'medium' | 'thin' | 'light' | 'normal' Yes Boldness of the font
style 'italic' | 'normal' Yes Face of the font family to be used

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 Optional Description
fontValue FontValue No 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 Optional Description
value any No The value to test

Returns value is FontValue

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 Optional Description
value any No The value to test

Returns value is FontValue

Properties

family

Prioritized list of font families

Type string[]
Settable No
Change events No

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

size

Positive number in dip

Type number
Settable No
Change events 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
Change events 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
Change events No

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

Static Properties

condensed

Type "condensed"
Settable No
Change events No

monospace

Type "monospace"
Settable No
Change events No

sansSerif

Type "sans-serif"
Settable No
Change events No

serif

Type "serif"
Settable No
Change events No