News for hackers. Stuff that matters.
Re:Asm-Dom – WebAssembly Virtual DOM by gizmo on Sunday May 21, 2017 @06:54AM (#14386674)
If you do your own line wrapping, then I'm pretty sure you don't need to do any text measurements. To get the kerning information for a given font face and size you can cache the widths of all character pairs ("AA", "AB", "AC"). Last I checked just summing the width of character pairs in a string would get you a width estimate accurate to the pixel, even for reasonably long strings. You don't have cross-platform pixel-perfect text rendering anyway, so you don't need to be 100% accurate. Maybe you're already doing this, but if not it's worth exploring.
Re:Asm-Dom – WebAssembly Virtual DOM by ptx on Sunday May 21, 2017 @08:45AM (#14387027)
This might be a dumb question, but after figuring out the width of "AB" and "BC", how do you know the width of "ABC"? Do you just calculate the distances A–B and B–C as ab_distance = width("AB") - (width("A") + width("B")) ... and so on?
Re:Asm-Dom – WebAssembly Virtual DOM by gizmo on Sunday May 21, 2017 @02:14PM (#14388371)
Yep. Kerning is just the amount of space in between two characters. So to calculate the total width of a string you take the (fixed) widths of the individual characters and you add the variable widths of the space between each character pair.
Re:Asm-Dom – WebAssembly Virtual DOM by TimJYoung on Sunday May 21, 2017 @03:42PM (#14388853)
Thanks, that is very interesting. We do happen to rely on the DOM for line-wrapping, but that's just because we didn't think you could get reasonable results doing what you've suggested.

Okay, off to see what this produces... :-)

Re:Asm-Dom – WebAssembly Virtual DOM by gizmo on Tuesday May 23, 2017 @08:22AM (#14400574)
Google Docs does its own line-wrapping for proportional fonts, so that may be interesting to look at.

It's a little finicky to get it all to work consistently cross browser and cross platform, so good luck!

Re:Asm-Dom – WebAssembly Virtual DOM by panic on Sunday May 21, 2017 @05:09PM (#14389271)
What do you do if you encounter a pair like "ペア"?