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

Compatibility problems #54

Open
lidongsevenlee opened this issue Sep 22, 2023 · 2 comments
Open

Compatibility problems #54

lidongsevenlee opened this issue Sep 22, 2023 · 2 comments
Labels

Comments

@lidongsevenlee
Copy link

https://github.com/mapbox/tiny-sdf/blob/5bd130204f341acfd974081a791be9397fb10c39/index.js#L58C27-L58C133

const {
width: glyphAdvance,
actualBoundingBoxAscent,
actualBoundingBoxDescent,
actualBoundingBoxLeft,
actualBoundingBoxRight
} = this.ctx.measureText(char);
const glyphWidth = Math.max(0, Math.min(this.size - this.buffer, Math.ceil(actualBoundingBoxRight - actualBoundingBoxLeft)));
const glyphHeight = Math.min(this.size - this.buffer, glyphTop + Math.ceil(actualBoundingBoxDescent));

const imgData = ctx.getImageData(buffer, buffer, glyphWidth, glyphHeight);

actualBoundingBoxRight, actualBoundingBoxLeft, actualBoundingBoxDescent
These values ​​may be undefined in low-end machine environments, which will cause the glyphWidth and glyphHeight to be calculated as NaN, which will cause the ctx.getImageData method to throw a DOMException error.

@mourner
Copy link
Member

mourner commented Sep 22, 2023

As of v2, tiny-sdf no longer supports legacy browser environments (IE11 and such), and full TextMetrics API is universally supported: https://caniuse.com/mdn-api_textmetrics_actualboundingboxleft

Perhaps we should throw a more meaningful error when this happens, but I don't think we should go back to supporting this case.

@lidongsevenlee
Copy link
Author

I understand, thank you for the reply, but you still need to avoid the situation where the glyphWidth and glyphHeight are calculated as NaN, because this will cause ctx.getImageData to throw an error and hinder subsequent logic.

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

No branches or pull requests

2 participants