Live data from Hacker News

Knuth and Plass line breaking algorithm in JavaScript

bramstein.com

11–20 of 44 posts

Re: Knuth and Plass line breaking algorithm in JavaScript

#14
post #11

The web is now twenty and browsers are still incapable of something as basic and commonplace as hyphenation and justification. It’s a real shame that this problem has to be solved with JavaScript in 2010. How old is TeX again?

I've been asking for years why browsers do not have this. The only reply I've gotten is for performance considerations, which is a bad answer for several reasons.

Re: Knuth and Plass line breaking algorithm in JavaScript

#15
post #6

Earlier quoted context omitted.

That's probably a bug, what browser and operating system are you using?

Same here, Chrome 8.0.552.215, Mac OS X 10.6.5.

I have the same Chrome version, but I'm running Ubuntu. Perhaps it is a font issue. I will check it out later when I have access to a Mac. Thanks for reporting.

Re: Knuth and Plass line breaking algorithm in JavaScript

#17
post #14
post #11

The web is now twenty and browsers are still incapable of something as basic and commonplace as hyphenation and justification. It’s a real shame that this problem has to be solved with JavaScript in 2010. How old is TeX again?

I've been asking for years why browsers do not have this. The only reply I've gotten is for performance considerations, which is a bad answer for several reasons.

Internet Explorer actually has this through the (almost standardized) text-justify CSS property. It still doesn't do hyphenation, but Hyphenator.js (http://code.google.com/p/hyphenator/) fills that gap pretty nicely.

Performance isn't a good argument in my opinion. The algorithm isn't that expensive. The most expensive part right now is retrieving all the text metrics, but you would get that a lot cheaper in the browsers rendering engine.

I briefly looked at hacking it into Webkit, but then gave up due to a lack of time.

Re: Knuth and Plass line breaking algorithm in JavaScript

#18

Does anyone know if there is a good jQuery plugin for this, or do I need to take the code from this demo and make my own plugin?

As far as I know, this is the only implementation in JavaScript. It might be possible to turn this into a jQuery plugin at some point, but there are probably quite a couple of bugfixes and changes needed to turn this from a tech demo into a drop-in plugin.

Re: Knuth and Plass line breaking algorithm in JavaScript

#19
post #6

Earlier quoted context omitted.

Same here, Chrome 8.0.552.215, Mac OS X 10.6.5.

I have the same Chrome version, but I'm running Ubuntu. Perhaps it is a font issue. I will check it out later when I have access to a Mac. Thanks for reporting.

I set font family to Times, and, indeed, I can see hyphens.

Re: Knuth and Plass line breaking algorithm in JavaScript

#20
post #14
post #11

The web is now twenty and browsers are still incapable of something as basic and commonplace as hyphenation and justification. It’s a real shame that this problem has to be solved with JavaScript in 2010. How old is TeX again?

I've been asking for years why browsers do not have this. The only reply I've gotten is for performance considerations, which is a bad answer for several reasons.

Another reason I've heard before was internationalization. Not sure how many languages have draconian hyphenation rules like English though.
Post reply on HN