Skip to content

@fabwcie/free-drawing / utils/text

utils/text ​

Variables ​

libraryUbuntu ​

const libraryUbuntu: "free-drawing-ubuntu" = 'free-drawing-ubuntu'

Defined in: packages/free-drawing/src/utils/text.ts:12

Family of the Ubuntu font of the library (@font-face of its style sheet): its own name, so the Ubuntu font of the page (installed, with its other weights) is left to it

Functions ​

cssFontFamily() ​

cssFontFamily(fontFamily): string

Defined in: packages/free-drawing/src/utils/text.ts:20

Font family of a text as the browser reads it: Ubuntu of drawings (texts, titles of frames) is the font of the library, then an installed Ubuntu; other families as they are, names with spaces quoted (as konva does)

Parameters

fontFamily

string

font family of a text (CSS list)

Returns

string

CSS list of font families


fitTextWidth() ​

fitTextWidth(text): boolean

Defined in: packages/free-drawing/src/utils/text.ts:88

Fit width of a text to its content (lines no longer wrapped), its lines stay in place whatever their alignment

Parameters

text

Text

text node to resize (moved along its x axis for center or right alignment)

Returns

boolean

true if width changed


getContentWidth() ​

getContentWidth(text): number

Defined in: packages/free-drawing/src/utils/text.ts:71

Width of a text box fitting its content: longest line as konva measures it, and padding

Parameters

text

Text

text node, measured with its style (font, size, padding)

Returns

number

width in text coordinates, rounded up, 1 at least


getFontsToLoad() ​

getFontsToLoad(shapes): string[]

Defined in: packages/free-drawing/src/utils/text.ts:112

Fonts of texts not loaded yet by the browser (a text drawn before its font is loaded uses a fallback font: exports, preview of the export dialog)

Parameters

shapes

DrawingShape[]

drawing shapes (texts of groups and frames included)

Returns

string[]

fonts of the canvas (style, size, family) to load, each once


getTexts() ​

getTexts(shapes): Text[]

Defined in: packages/free-drawing/src/utils/text.ts:60

Texts of shapes and of their groups (not shapes of frames, nor titles of frames)

Parameters

shapes

DrawingShape[]

drawing shapes (selection)

Returns

Text[]

texts among the shapes and in their groups at any depth


loadFonts() ​

loadFonts(fonts): Promise<void>

Defined in: packages/free-drawing/src/utils/text.ts:127

Loads fonts (see getFontsToLoad), an unavailable one keeps the fallback font

Parameters

fonts

string[]

fonts of the canvas (style, size, family)

Returns

Promise<void>


setupFonts() ​

setupFonts(node): void

Defined in: packages/free-drawing/src/utils/text.ts:44

Texts of a node drawn and measured with the font of the library for Ubuntu (see cssFontFamily): their font family is kept (saves, files, style of the selection). Konva clones do not keep it: copies of shapes are set up too

Parameters

node

Node

drawing shape, group, frame, copy of one

Returns

void