The loadFont() function is used to load a font from file or an URL, and return it as a PFont Object. The font loaded is an opentype font file with the formats .otf or .ttf.
This method is asynchronous in nature and therefore it may not finish before the font can be used. It is hence advised to load the font in the preload() function. The font is preferably loaded from a relative path as some browsers may prevent loading from other remote locations due to the browser’s security features.
loadFont(path, callback, onError)
Parameters: This function accepts three parameter as mentioned above and described below:
- path: It is the path from where the font has to be laoded. It can be a
- callback: This is a function which after the font is loaded and it is an optional parameter.
- onError: This is a function which is called if the font does not load due to any error and it is an optional parameter.
Return Value: It returns a p5.Font object with the given font.
Below examples illustrate the loadFont() function in p5.js:
Online editor: https://editor.p5js.org/
Note: This function can not be accessible through an online compiler because the font file is missing.
- How to get the function name inside a function in PHP ?
- D3.js | d3.hcl() Function
- D3.js | d3.lab() Function
- D3.js | d3.map.set() Function
- CSS | var() Function
- D3.js | d3.rgb() Function
- p5.js | int() function
- PHP | ord() Function
- PHP | Ds\Map get() Function
- PHP | exp() Function
- p5.js | hue() function
- p5.js | min() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.