bhushan6 / babylon-msdf-text

library to render text in Babylon js using MSDF technique
15 stars 5 forks source link

Knuth-Plass Full Text Justification #7

Open peter-wasilko opened 2 weeks ago

peter-wasilko commented 2 weeks ago

Would it be possible to integrate the Knuth-Plass line-break algorithm from https://github.com/robertknight/tex-linebreak ?

bhushan6 commented 2 weeks ago

Seems doable but can't commit, will look into it as soon as I can.

peter-wasilko commented 1 week ago

There is a newer repo at https://www.npmjs.com/package/tex-linebreak2 that builds on tex-linebreak. It suggests using https://github.com/ytiurin/hyphen to inject soft-hyphens after which one can leverage https://www.npmjs.com/package/string-pixel-width to work out word widths if one strips out the soft hyphens ( \u+00AD) first ; from there one can get an array of positioned items with xOffset members to position each word. However it looks like the package will occasionally break on soft hyphens without rendering corresponding hyphenation characters, so one would have to infer their location from the presence of penalty objects in the positioned items array. I hope these pointers help. Not having Three.js's fully justified Troika Text https://protectwise.github.io/troika/troika-three-text/ could be a show stopper for some use cases. Troika's other killer feature is its curveRadius support for creating the illusion of a large format curved monitor.