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 | loadFont() |
||
|---|---|---|---|
| Examples | ![]()
PFont font;
// The font must be located in the sketch's
// "data" directory to load successfully
font = loadFont("LetterGothicStd-32.vlw");
textFont(font, 32);
text("word", 10, 50);
| ||
| Description |
Loads a font into a variable of type PFont. To load correctly, fonts must be located in the data directory of the current sketch. To create a font to use with Processing, select "Create Font..." from the Tools menu. This will create a font in the format Processing requires and also adds it to the current sketch's data directory. Like loadImage() and other functions that load data, the loadFont() function should not be used inside draw(), because it will slow down the sketch considerably, as the font will be re-loaded from the disk (or network) on each frame. Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network. If the file is not available or an error occurs, null will be returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned is null. For most renderers, Processing displays fonts using the .vlw font format, which uses images for each letter, rather than defining them through vector data. When hint(ENABLE_NATIVE_FONTS) is used with the default renderer, the native version of a font will be used if it is installed on the user's machine. Using createFont() (instead of loadFont) enables vector data to be used with the default renderer setting. This can be helpful when many font sizes are needed, or when using any renderer based on the default renderer, such as the PDF library. 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 | loadFont(filename) | ||
| Parameters |
| ||
| Returns | PFont | ||
| Related | textFont() PGraphics createFont() |


