| Name | textWidth() |
||
|---|---|---|---|
| Processing.js Behavior | Font support for the Canvas element varies across browsers. FireFox currently has the best support, but still uses a pre-defined set of fonts. (Documentation to follow soon.) Good alternatives to the browser's Canvas-font functions are available: such as the Glyph method. See also: Canvas Text, BurntToys Bauhaus.
Please use the following demos to learn how fonts can be rendered in Firefox with Processing.js: Letters, Words, width() |
||
| Examples | ![]() PFont font;
font = loadFont("FFScala.ttf");
textFont(font, 32);
char c = 'T';
float cw = textWidth(c);
text(c, 0, 40);
line(cw, 0, cw, 50);
String s = "Tokyo";
float sw = textWidth(s);
text(s, 0, 85);
line(sw, 50, sw, 100); |
||
| Description | Calculates and returns the width of any character or text string. |
||
| Syntax | textWidth(data) |
||
| Parameters |
|
||
| Returns | Float | ||
| Usage | Web & Application | ||
| Related |
loadFont() PFont text() textFont() |