line breaking

by nex on 3/18/03, 6:34 AM in antville

Suppose you have an arbitrary string of text and have to fit it into a column of rather finite width. You'll have to break the text down into several lines. That hasn't been much of a problem for thousands of years, but now it is.


If you know in advance how wide each character will be, you can transform your document in a way that produces the desired result. That's the way it's done in a PDF: Every letter has its fixed place.

If you don't know how wide each character will be, or how wide the column will be, you have no choice if you want to produce good looking output: you just save the text like it is and rely on the program that displays it to break the lines properly. That's how your text editor and word processor work.

That's also how your browser should work. However, all that lazy bastard does is put word after word on a line, and only if a word doesn't fit on the line, it advances to the next one. As soon as one word doesn't fit into the column, even on a new line, everything gets screwed up badly. What makes this even worse is that for most browsers, words are everything between whitespace, hyphens and maybe slashes. If a string of text contains semicolons, question marks and lots of other weird stuff, it's just one long word for most browsers. Preventing the aforementioned screw-up from happening is about all we can do, because one fact is set in stone with current browsers: You have to live with ragged text. Trying to justify it will only make it uglier.

Allright, so we have to break words that are too long, without knowing how long is too long and without knowing where these words will appear within a line. An intelligent solution would be to at least embed information in long words that tells the browser about good places in which to brake them; just like in your dic-tio-nary. There are several special Unicode characters for this purpose. However, as your browser is a lazy bastard, it happily ignores all of those.

The good news is that we'll get away with an extremely primitive solution, because under these circumstances, it's impossible to do anything sophisticated anyway. But where exactly would you fit your primitive solution into Antville? I'll have to think about that for a while, see you later...



 |