jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.3k stars 455 forks source link

[Enhancement] Make Canvas Invocations of measureText Node Canvas Compliant #671

Open jonobr1 opened 1 year ago

jonobr1 commented 1 year ago

Is your feature request related to a problem? Please describe. Two.js uses context.measureText from HTML5 <canvas /> tags to know what the width of a set of rendered text is in Two.Text.getBoundingClientRect.

This works in the browser, but not in headless environments

Describe the solution you'd like node-canvas is the defacto Canvas feature for node.js and one recommended for use with Two.js on its own documentation page. So, the measureText code in Two.Text should work with node-canvas as well as the browser.

This issue is based on the conversation here: https://github.com/jonobr1/two.js/issues/668