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

docs seem wrong about textFont return type #4926

Closed
seldomU opened this issue Nov 30, 2020 · 5 comments · Fixed by peilingjiang/b5#91
Closed

docs seem wrong about textFont return type #4926

seldomU opened this issue Nov 30, 2020 · 5 comments · Fixed by peilingjiang/b5#91

Comments

@seldomU
Copy link

seldomU commented Nov 30, 2020

The documentation page on textFont() gives the impression that the method returns the current font object. This seems to only work when a font has been loaded before. When working with the default font, textFont() returns a string, the font name. When called with a name as argument, e.g. textFont("sans-serif"), it returns the p5 object.

Is it at all possible to get a font object for the default fonts? I'd like to run textToPoints on them.

@seldomU seldomU added the Bug label Nov 30, 2020
@dhowe
Copy link
Contributor

dhowe commented Nov 30, 2020

The way textToPoints works (if I remember correctly) is that it uses the glyph data within a .ttf or .otf font. So if there is no font loaded (by the user) there is no glyph data to be accessed.

To provide this functionality in the future we'd need to bundle a freely-usable .ttf or .otf font, for which there is some cost in the size of the package. But if we can find a small-enough font (or create one that includes only the basic characters for the locale) it might make sense to do, especially as (I think) we can only draw text in 3D with a custom loaded font, so this would solve both issues.

There are previous discussions on this issue here and here -- in the latter you can find arguments against including such a font.

@seldomU
Copy link
Author

seldomU commented Nov 30, 2020

Thank you. I figured as much after looking at the source.

@lmccart lmccart closed this as completed Dec 8, 2020
@lmccart lmccart reopened this Dec 8, 2020
@lmccart
Copy link
Member

lmccart commented Dec 8, 2020

Sorry, I accidentally closed this. Since this is a feature request, it would be helpful to have an answer to the PR template that asks: How would this new feature help increase access to p5.js?

@seldomU
Copy link
Author

seldomU commented Dec 8, 2020

The documentation for textFont()'s return value doesn't mention two cases:

  1. no font file has been loaded -- the current font name is returned as a string
  2. the argument is a font name, like "sans-serif" -- the P5 object(!) is returned

As I user, I'd have wanted to know that.

@lmccart
Copy link
Member

lmccart commented Dec 8, 2020

Ah ok, so this is more of a missing documentation bug. Thanks for clarifying!

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

Successfully merging a pull request may close this issue.

3 participants