I made a justified text engine

Enter any text you want to justify into the "text" variable. (Right now it only works on pen size 12, though.)
(If you don't know, justified text is when the width of the space character is changed so that each line always ends at the same point.)


Very nice!

A few suggestions:

  1. The text crashes right into the right edge of the stage. I would reduce the max width by two or three pixels, or whatever the left margin is.

  2. It's great that you take care to handle the case where you can fit only one word on the line (which happens when you have a couple of sesquipedalian words in a row) without crashing. The Official Right Thing in such cases is to add spacing between the letters of the word, although it's really ugly unless the word almost fills the line anyway. (The really right thing of course is to rephrase the sentence!)

  3. It would be very cool if it could hyphenate. That turns out to be harder than it sounds; many of the gory details are explained in The TeXbook.

I'm pretty sure this is caused by different operating systems having different size fonts. I've fixed that in the new version.

If you mean telling when to cut the word in half and put the other half on the next line, yeah, that sounds pretty hard. :P

It's one of those things where 90% of the cases are pretty easy and the other 10% are impossible.