Name

textFont()

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 specified, the font size defaults to the original size (the size in which it was created with the "Create Font..." tool) overriding any previous calls to textFont() or textSize().

When fonts are rendered as an image texture (as is the case with the P2D and P3D renderers as well as with loadFont() and vlw files), 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.
 

Examples

  • size(400,400);
    PFont mono;
    // The font "andalemo.ttf" must be located in the 
    // current sketch's "data" directory to load successfully
    mono = createFont("andalemo.ttf", 128);
    background(0);
    textFont(mono);
    text("word", 48, 240);
    Image output for example 1

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

Return

  • void