Name

createFont()

Description

Dynamically converts a font to the format used by Processing from a .ttf or .otf file inside the sketch's "data" folder or a font that's installed elsewhere on the computer. If you want to use a font installed on your computer, use the PFont.list() method to first determine the names for the fonts recognized by the computer and are compatible with this function. 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 anti-aliased or not. The charset parameter is an array of chars that specifies the characters to generate.

This function allows Processing to work with the font natively in the default renderer, so the letters are defined by vector geometry and are rendered quickly. In the P2D and P3D renderers, the function sets the project to render the font as a series of small textures. For instance, when using the default renderer, the actual native version of the font will be employed by the sketch, improving drawing quality and performance. With the P2D and P3D renderers, the bitmapped version will be used to improve speed and appearance, but the 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.

Examples

  • PFont myFont;
    
    void setup() {
      size(200, 200);
      // Uncomment the following two lines to see the available fonts 
      //String[] fontList = PFont.list();
      //printArray(fontList);
      myFont = createFont("Georgia", 32);
      textFont(myFont);
      textAlign(CENTER, CENTER);
      text("!@#$%", width/2, height/2);
    }
    
    

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
  • smooth(boolean)true for an anti-aliased font, false for aliased
  • charset(char[])array containing characters to be generated

Return

  • PFont