Skip to main content
Version: v2

getTextLayout(text_string, options)

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Calculate the height and width of the target text after the layout is completed, and does not actually render it, only performs the layout calculation.

Can be used to calculate the height of a multi-line text layout with a fixed width, or the width of a single-line text layout.

Type

(text_string: string, options: object) => result

Parameters

ParameterDescriptionRequiredType
text_stringText content of the layout to be calculatedYESstring
optionsOptionsYESOptions

Options

PropertiesDescriptionRequiredType
text_sizeText sizeYESnumber
text_widthWidth of a single line of textYESnumber
wrappedwhether the text is line feed, 0: no line feed; 1: line feedNOnumber

result: object

PropertiesDescriptionType
widthWidth pixel valuenumber
heightHeight pixel valuenumber

Code example

import { getTextLayout } from '@zos/ui'

const { width, height } = getTextLayout('turn right and go alone the road', {
text_size: 30,
text_width: 200
})

console.log('width', width)
console.log('height', height)
import { getTextLayout } from '@zos/ui'

const { width, height } = getTextLayout('turn right and go alone the road', {
text_size: 30,
text_width: 0,
wrapped: 0
})

console.log('width', width)
console.log('height', height)