- From: Glenn Maynard <glenn@zewt.org>
- Date: Tue, 17 Apr 2012 19:15:34 -0500
- To: Silvia Pfeiffer <silviapfeiffer1@gmail.com>
- Cc: Frank Olivier <Frank.Olivier@microsoft.com>, "public-texttracks@w3.org" <public-texttracks@w3.org>
- Message-ID: <CABirCh_B2qY0kSog3qxnMBNbrDLtpc4xPYVfKs9pN=R4se5cdA@mail.gmail.com>
On Tue, Apr 17, 2012 at 4:45 PM, Silvia Pfeiffer <silviapfeiffer1@gmail.com>wrote: > I've had a bit of a chat with some people on the Chrome team that work > on CSS and the balanced text wrapping mode that we are after indeed is > not easy to implement using CSS. It basically requires a new CSS > algorithm. > Right, it belongs in CSS. (I found the earlier discussion: http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-December/034026.html"basic algorithm should be ...".) It shouldn't be difficult--at least, no more difficult than any other wrapping algorithm. We're considering this to be a new value for text-wrap - something > like "text-wrap: balance;". It would states something along the lines > of what you outlined - basically that it minimizes white space in the > last line of a multi-line paragraph by re-distributing this white > space over all lines and thus making the individual lines shorter. How > a browser implements this would be up to the browser. > > What we likely need to do is: write a proposal (in a wiki page or so) > for this new mode, explaining our use case. We should then send it out > to the www-style list for general discussion. If you are keen, do go > ahead with preparing such a proposal. > I don't know if I'll have the bandwidth to explain this from scratch to yet another audience. I'll try to get to it eventually if someone else doesn't get to it first... The suggested algorithm is: 1: Wrap the text using the ordinary word-wrapping algorithm, and let L be the resulting number of lines. 2: For each possible width W, starting at 1 and ending at the maximum wrapping width, do the following: 2.1. Wrap the text to width W, using the ordinary word-wrapping algorithm. 2.2. If the resulting number of lines is less than or equal to than L, return the wrapped text. Otherwise, continue to the next possible width. This simply finds the narrowest width that doesn't require additional lines than ordinary wrapping. This runs in linear time on the size of the input text. (Of course, this can be optimized without changing the results, by performing a binary search on W instead of a linear one, but that's an implementation detail.) This may not produce great results for large paragraphs, but it should work well for caption-size text, where the common case is only a few lines. (Apparently this has been tried before, but it was attempting to find the *optimal* solution, which turns out to be O(n^2). I believe this solution is more than adequate for WebVTT's needs, and good enough to be of general use; Ian mentioned headings, which this should work well for too.) -- Glenn Maynard
Received on Wednesday, 18 April 2012 00:16:05 UTC