Open blackboxlogic opened 2 months ago
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!
Hi! A quick alternative is to load a URL to a remote font, like this:
font = loadFont('https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxP.ttf');
This way you won't need to download the font file and include it in your project.
However I found that some URLs return Error: Unsupported OpenType signature wOF2: https://editor.p5js.org/jeanetteandrews/sketches/9qDCQXgG4 I'm not sure if this is a bug or is due to browser security.
@jeanetteandrews this is likely a valid error from the opentype library - not all fonts can be parsed by opentype
To use textBounds() or textToPoints(), you first need to call loadFont() to get a reference to a p5.Font object. Creating a reference like defaultFont or currentFont would bypass the need to find a font file, include it in your project, and load it if the user is happy with the default p5js font.
This is a good suggestion - there are issues to be considered with a) the size that it adds to the package, and b) the licensing for this 'default' font
I thought this could be possible without the p5js developers adding a whole font file. Since a 'text("hi", 0, 0)' works without referencing a font, it seems a default font gets acquired either from the browser or the operating system, and that same font could be exposed by reference.
This default font is a font supplied by the browser... we can use it, but we don't get all the font data that would be needed to create a p5.Font object (for example, the paths for each glyph).
This was a compromise that allowed for simple uses (drawing text) but didn't t add to the size of the package. However its something we could potentially revisit in the new version, assuming there was a small enough font with appropriate licensing (of course the font's size is often proportional to the number of characters it supports, which may well raise other access-related issues)
Increasing access
Proposal would simplify working with fonts.
Most appropriate sub-area of p5.js?
Feature request details
To use
textBounds()
ortextToPoints()
, you first need to callloadFont()
to get a reference to ap5.Font
object. Creating a reference likedefaultFont
orcurrentFont
would bypass the need to find a font file, include it in your project, and load it if the user is happy with the default p5js font.