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

feat: support measuring text with font weight #884

Merged
merged 4 commits into from
Nov 14, 2024
Merged

Conversation

quanho
Copy link
Collaborator

@quanho quanho commented Nov 14, 2024

This PR to support measure text with styling e.g bold and/or italic
Checklist

@quanho quanho changed the title feat: support measuring text with font style and font weight feat: support measuring text with font weight Nov 14, 2024
@quanho quanho requested a review from cbt1 November 14, 2024 13:05
@quanho quanho merged commit 3ac2af7 into master Nov 14, 2024
12 checks passed
@quanho quanho deleted the hva/font-style branch November 14, 2024 13:33
} else {
g.font = `${t['font-size']} ${t['font-family']}`;
}
g.font = [t['font-style'], t['font-weight'], t['font-size'], t['font-family']].filter((v) => !!v).join(' ');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpicking here but it does not seem optional from a performance perspective to

  1. Create an array
  2. filter to create another array
  3. join array

...everytime we render a text.

I would think string concat is a faster and provides a somewhat clean syntax. Some simpified tested in the browser console at least gave to a 50% performance increase compered to current method.

Example:

g.font = (t["font-style"] ?? "").concat(t['font-weight'] ?? ", t['font-size'] ?? "", t['font-family'] ?? "")

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