This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

textFont()

Examples
example pic
PFont mono;
// The font "AndaleMono-48.vlw"" must be located in the 
// current sketch's "data" directory to load successfully
mono = loadFont("AndaleMono-32.vlw");
background(0);
textFont(mono);
text("word", 12, 60);
Description Sets the current font that will be drawn with the text() function. Fonts must be created for Processing with createFont() or loaded with loadFont() before they can be used. The font set through textFont() will be used in all subsequent calls to the text() function. If no size parameter is input, the font will appear at its original size (the size in which it was created with the "Create Font..." tool) until it is changed with textSize().

Because fonts are usually bitmapped, you should create fonts at the sizes that will be used most commonly. Using textFont() without the size parameter will result in the cleanest type.

With the default and PDF renderers, it's also possible to enable the use of native fonts via the command hint(ENABLE_NATIVE_FONTS). This will produce vector text in both on-screen sketches and PDF output when the vector data is available, such as when the font is still installed, or the font is created dynamically via the createFont() function (rather than with the "Create Font..." tool).

Font support for the canvas element varies across browsers. Firefox currently has the best support, but still uses a pre-defined set of fonts. 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()

Syntax
textFont(which)
textFont(which, size)
Parameters
which PFont: any variable of the type PFont
size float: the size of the letters in units of pixels
Returnsvoid
RelatedcreateFont()
loadFont()
text()
Updated on December 7, 2012 08:53:40am PST

Creative Commons License