I ran across Brian McAllister’s slabtext jQuery plugin, and was immediately taken by the concept of algorithmically slabbing text. That, of course, led me to Erik Loyer’s slabtype algorithm. After taking a close look at the algorithm, It seemed a bit complicated to me. The algorithm first creates an optimal slab, based on the width of the box and the font-size of the container, then resizes the result to match the height of the container. The end result has the potential to create very sub-optimal slabs, when height is a factor.
I redesigned the slabbing algorithm, at the cost of a few CPU cycles, to produce a much more optimized slab, when the container height is known. Rather than basing the slabbing algorithm on font-size and a magic ratio, jSlabify bases its slabs on comparing proportions. It renders the text as a single line, and captures the dimensions and the area, in characters, of the resulting box. Then, it calculates the height, in characters (read: row count), necessary to contain the same area (read: number of characters) in a box proportional to the container. The relevant formula is:
CHECK IT OUT NOW