sb.getStringSize
sb.getStringSize(font, font_size, string, width, data)
Calculate the area in pixels which the given string will occupy on the screen.
Parameters
| Parameter | Type | Description |
|---|---|---|
font | string | The name of the font to render in |
font_size | number | The size of the font to render in |
string | string | The string to render |
width | number | A clipping width (in pixels) for the string, used to calculate how many characters fit |
data | object | An object containing additional options. See String Size Options Object for details. |
String Size Options Object
| Key | Type | Description |
|---|---|---|
length | number | Number of characters to process. Default is to process the entire string. |
spacing | number | Letter spacing parameter. Default is 0. |
wrapping | boolean | Activate wrapping logic. Default is false. |
Return
An object with the following fields:
| Key | Type | Description |
|---|---|---|
string | string | The original string passed in |
font | string | The original font passed in |
font_size | number | The original font size passed in |
width | number | The original width passed in |
height | number | The total height of the wrapped text in pixels |
n_lines | number | The number of lines the text fills when wrapped |
Example
var options = {wrapping : true};
var t = sb.getStringSize('fonts/Roboto-ThinItalic.ttf', 72, 'How long is this string?', 600, options);