text to desmos
- 7 Devlogs
- 33 Total hours
Converting text to polygons for easy use in desmos graphs
Converting text to polygons for easy use in desmos graphs
Finally embedded the actual calculator (which was surprisingly easy, thanks desmos team!) Also, I fixed a bug where control points were being rounded to a grid at small font sizes.
I don’t think the current error metric for bezier curve flatness is good, since it’s a distance that depends on the size of the curve (which depends on font size). Maybe I could just scale the threshold by the font size, but I’d have to look more into it.
That’s why in the new screenshot, there are way too many samples, even though I set the tolerance slider to the max. The sampling now happens in glyph space, which is at a way larger scale (1em = around 1000 units) compared to the output space, and I forgot to change the slider’s bounds.
Also did a bunch of rewrites, and bumped the text shaping/font loading dependencies; their new API is so much simpler that I was able to get rid of a dependency I previously needed. It’s funny, but I regret that I had to deal with the old API.
Implemented recursive subdivision sampling (why was this so easy?) Basically you split each cubic curve into two cub-curves at t=0.5, and repeat until the curve is approximately a line segment. Though I need to find error metrics that are easy to understand, the current one depends on font size.
Image: sample points in black, control points in blue
Refactoring and cleaning up, in preparation for at least 2 more sampling options (fixed density and adaptive). Also removed duplicated code so that the debug view actually reflects the polygon output, instead of doing its own text shaping. Have random code screenshots now
Cleaned up the code and implemented a makeshift curve sampler. Currently I’m taking a fixed number of samples for each bezier segment in the glyph splines, so the resolution is inconsistent and there’s way more points than necessary in some places.
Can now load .woff and .woff2 fonts, and the decompressed font & its shaper are stored globally instead of re-parsing every text update. I’m just outputting control points now, but soon I can finally implement the actual sampling. Also, something weird is going on with the Fira code variable font?
Drawing text to an svg path. Also set up a debug ui to make sure the text shaping (glyph layout, ligatures, etc) is being done properly. For that, I ended up using a recent HarfBuzz port with basically no docs, which was really fun and not at all hard to understand. I also spent a lot of time searching up browser apis on MDN, and figuring out how to work with async.
Next up:
First commit, I finished setting up the tooling and a template for svelte/wasm. Now time to go learn svelte