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

2d Canvas Polyfill to Measure Text? #88

Open
swamidass opened this issue Apr 8, 2022 · 1 comment
Open

2d Canvas Polyfill to Measure Text? #88

swamidass opened this issue Apr 8, 2022 · 1 comment

Comments

@swamidass
Copy link

A library I am using has this code to measure text.

   const element = document.createElement('canvas');
    const ctx = element.getContext("2d");
    ctx.font = `${this.opts.fontSizeLarge}pt Helvetica, Arial, sans-serif`
    
    let textMetrics = ctx.measureText(text)

Is there any way to get this to work with svgdom? If not, what is replacement code that would accomplish the same?

@Fuzzyma
Copy link
Member

Fuzzyma commented Apr 8, 2022

Just get the bounding box of the text by creating a text element and calling getBBox on it

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

No branches or pull requests

2 participants