Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reference to Default Font object #7193

Open
1 of 17 tasks
blackboxlogic opened this issue Aug 27, 2024 · 6 comments
Open
1 of 17 tasks

Add Reference to Default Font object #7193

blackboxlogic opened this issue Aug 27, 2024 · 6 comments

Comments

@blackboxlogic
Copy link

Increasing access

Proposal would simplify working with fonts.

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature request details

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.

Copy link

welcome bot commented Aug 27, 2024

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!

@jeanetteandrews
Copy link
Contributor

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.

@dhowe
Copy link
Contributor

dhowe commented Sep 6, 2024

@jeanetteandrews this is likely a valid error from the opentype library - not all fonts can be parsed by opentype

@dhowe
Copy link
Contributor

dhowe commented Sep 6, 2024

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

@blackboxlogic
Copy link
Author

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.

@dhowe
Copy link
Contributor

dhowe commented Sep 6, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants