Fabric.js 2.0 breakWords Implementation

EDIT 6/3/2019 - It looks like the splitByGrapheme option has been fixed and is working in fabric 3.0. It is an alternate approach than the one shown here.

One of my favorite fabric.js hacks was the breakWords function. This would allow Textbox objects to hold a maximum width by forcing a line break when a long word could not be contained.

Unfortunately this functionality was broken in fabric 2.0. I busted my ass a bit trying to figure this out - here's what I came up with:

Note that there are still some problems as pointed out here. It's a start, though.

EDIT 2/5/19 - I think I have most of the issues solved. The fiddle has been updated and will work with fabric 2.6

Justin Williamson

Read more posts by this author.