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

Type 2.0 #7356

Open
wants to merge 71 commits into
base: dev-2.0
Choose a base branch
from
Open

Type 2.0 #7356

wants to merge 71 commits into from

Conversation

dhowe
Copy link
Contributor

@dhowe dhowe commented Nov 3, 2024

Initial PR for typography module 2.0

There are 6 new functions added to the p5 prototype that should be discussed:

  • textBounds: tight bounds, now supported for all fonts, not just those with paths as in v1
  • fontBounds: gives the (loose) bounds for the font, regardless of characters used
  • fontWidth: gives the (loose) width of a string of given length in the font, regardless of the characters
  • textProperty: allows set/get for one of about 20 font-related properties
  • textProperties: allows batch set/get for one or more of about 20 font-related properties
  • textToPoints: a quick/dirty version using pixel-sampling that doesn't require font paths

Additionally textAscent and textDescent now operate differently depending on whether a specific string is passed in. If so, they return the metrics for that specific string, if not, then for the font itself (the max ascent and descent)

Issues/Questions:

  • It seems that there should be a direct get/set option for CanvasRenderingContext2D.font, as one would often like to grab a long css font-string and apply it directly in p5. This cannot be done using textFont without major changes, so I would argue for a new function to handle this.

@limzykenneth limzykenneth changed the base branch from main to dev-2.0 November 3, 2024 19:31
@limzykenneth
Copy link
Member

The last one failing test is a false negative I think. We'll probably need to revert the screenshots.

@dhowe
Copy link
Contributor Author

dhowe commented Nov 5, 2024

there should be no screenshots at all in this pr

@davepagurek
Copy link
Contributor

I'll need to check to see what's up with that one failing test case, it looks like lines are rendering behind the fills. I'm not 100% sure just yet what's going on there because I've seen it on a few people's computers before but not on CI. In any case, it seems completely unrelated to your code, so feel free to merge if it's just that one test failing (and in general just ping me if you see weird visual test failures like that, it's probably not your doing!)

});

test('loadFont.then', () => {
myp5.loadFont(fontFile).then(pFont => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to make this test function async and then await this to make sure the assertions happen within this test case

});

test('loadFont.callback', () => {
myp5.loadFont(fontFile, (pFont) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to wrap this in a promise and await it, or use the done callback to make sure the test only completes when the async stuff finishes:

test('loadFont.callback', (done) => {
  myp5.loadFont(fontFile, (pFont) => {
    // ...
    done()
  });
});

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

Successfully merging this pull request may close these issues.

4 participants