[−][src]Static p5_sys::global::loadFont
pub static loadFont: LoadFontInternalType
Loads an opentype font file (.otf, .ttf) from a file or a URL, and returns a PFont Object. This method is asynchronous, meaning it may not finish before the next line in your sketch is executed.
The path to the font should be relative to the HTML file that links in your sketch. Loading fonts from a URL or other remote location may be blocked due to your browser's built-in security.
Examples
let myFont;
function preload() {
myFont = loadFont('assets/inconsolata.otf');
}
function setup() {
fill('#ED225D');
textFont(myFont);
textSize(36);
text('p5*js', 10, 50);
}
function setup() {
loadFont('assets/inconsolata.otf', drawText);
}
function drawText(font) {
fill('#ED225D');
textFont(font, 36);
text('p5*js', 10, 50);
}
function preload() {
loadFont('assets/inconsolata.otf');
}
function setup() {
let myDiv = createDiv('hello there');
myDiv.style('font-family', 'Inconsolata');
}
Parameters
path
name of the file or url to load
callback?
function to be executed after
loadFont() completes
onError?
function to be executed if
an error occurs