Reference for Processing version 1.5. 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

### createFont()

Examples

    PFont myFont;

    void setup() {
      size(200, 200);
      // Uncomment the following two lines to see the available fonts
      //String[] fontList = PFont.list();
      //println(fontList);
      myFont = createFont("FFScala", 32);
      textFont(myFont);
      text("!@#$%", 10, 50);
    }

Description

Dynamically converts a font to the format used by Processing from either a font name that's installed on the computer, or from a .ttf or .otf file inside the sketches "data" folder. This function is an advanced feature for precise control. On most occasions you should create fonts through selecting "Create Font..." from the Tools menu.
Use the PFont.list() method to first determine the names for the fonts recognized by the computer and are compatible with this function. Because of limitations in Java, not all fonts can be used and some might work with one operating system and not others. When sharing a sketch with other people or posting it on the web, you may need to include a .ttf or .otf version of your font in the data directory of the sketch because other people might not have the font installed on their computer. Only fonts that can legally be distributed should be included with a sketch.
The size parameter states the font size you want to generate. The smooth parameter specifies if the font should be antialiased or not, and the charset parameter is an array of chars that specifies the characters to generate.
This function creates a bitmapped version of a font in the same manner as the Create Font tool. It loads a font by name, and converts it to a series of images based on the size of the font. When possible, the text() function will use a native font rather than the bitmapped version created behind the scenes with createFont(). For instance, when using the default renderer setting (JAVA2D), the actual native version of the font will be employed by the sketch, improving drawing quality and performance. With the P2D, P3D, and OPENGL renderer settings, the bitmapped version will be used. While this can drastically improve speed and appearance, results are poor when exporting if the sketch does not include the .otf or .ttf file, and the requested font is not available on the machine running the sketch.

Syntax

    createFont(name, size)
    createFont(name, size, smooth)
    createFont(name, size, smooth, charset)

Parameters

name | String: name of the font to load
size | float: point size of the font
charset | char[]: array containing characters to be generated
smooth | boolean: true for an antialiased font, false for aliased

Returns | PFont
Usage | Web & Application
Related | PFont textFont() text() loadFont()

Updated on August 30, 2010 04:29:39pm EDT