A context contains information about the text style, such as the font and the document width.
new Context(
options
: Object?)
This will create a new Context
with the options
specified. options
should just contain the properties listed below.
width
: numberDefault: 400
The document width in pixels.
fontSize
: numberDefault: 13
The base font size in pixels.
lineHeight
: numberDefault: 1.5
The line height in multiples of the font size.
indentWidth
: numberDefault: 16
The text indent width of an indented paragraph in pixels.
doubleHeight
: numberDefault: 1
The margin above a double-spaced paragraph in multiples of the font size.
boldWeight
: numberDefault: 600
The font weight used for bold text.
fontFamily
: stringDefault: `Baskerville, serif
The font family.
codeFontSize
: numberDefault: 12
The base code font size in pixels.
codeFontFamily
: numberDefault: Inconsolata, monospace
The code font family.
quotePadding
: ObjectObject properties:
top
: number, default: 10
left
: number, default: 10
right
: number, default: 10
bottom
: number, default: 10
The blockquote padding.
measureText(
text
: string, font
: Font
)
This will return the text width in pixels; measured using a canvas. If there is no DOM API, this will just return the text length.