GWAK
November 11, 2022, 10:01am
1
[P5] Is there a default font provided by WEB?
In ‘Processing-P5’, you can load a font with ‘loadFont’.
Example source code:
let myFont;
function preload() {
myFont = loadFont('assets/inconsolata.otf');
}
However, since the capacity of the font is large, if it is loaded as above, loading will be longer. So, users may feel stuffy.
In ‘JAVA Mode’, you can search for the default font.
String[] fontList = PFont.list();
printArray(fontList);
In conclusion, is there a way to search or find the default font in ‘Processing-P5’?
josephh
November 11, 2022, 11:16am
2
Hi @GWAK ,
In the documentation page of textFont()
, they say:
If textFont() is called without any argument, it will return the current font if one has been set already.
So you can try:
console.log(textFont());
// => sans-serif
You can also look in the source code where they set the default font for the canvas drawing context :
}
getFilterGraphicsLayer() {
// create hidden webgl renderer if it doesn't exist
if (!this.filterGraphicsLayer) {
// the real _pInst is buried when this is a secondary p5.Graphics
const pInst =
this._pInst instanceof p5.Graphics ?
this._pInst._pInst :
this._pInst;
// create secondary layer
this.filterGraphicsLayer =
new p5.Graphics(
this.width,
this.height,
constants.WEBGL,
pInst
);
}
if (
3 Likes
GWAK
November 12, 2022, 12:24pm
3
@josephh
Thanks for your reply.
Based on your words, you can find out about the current font.
However, the reason I uploaded this is that when the font is loaded, the loading time becomes longer due to the file size.
So, I wonder if there is a default font provided by ‘WEB’ or ‘P5’ without loading a file like ‘JAVA Mode’.
For example, you can use ‘PFont.list();’ without needing to have a font file.
I wonder if there is something like this on the web as well.
josephh
November 12, 2022, 9:53pm
4
Oh my bad I understand what you mean now!
You might want to look at Web safe fonts which are fonts that are commonly accessible on most operating systems without having to load them.
2 Likes
GWAK
November 13, 2022, 3:40am
5
@josephh
Thank you. Thanks for the kind explanation.
What I was wondering about is this.
1 Like