w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.38k stars 643 forks source link

The definition of text-wrap:balance is overprescriptive #9111

Open litherum opened 1 year ago

litherum commented 1 year ago

https://drafts.csswg.org/css-text-4/#valdef-text-wrap-balance

Line boxes are balanced when the standard deviation from the average inline-size of the remaining space in each line box is reduced over the block

I'm specifically concerned about defining balancing using a rigorous definition of "standard deviation ... of the remaining space."

This is one particular definition of balanced, but there are quite a few different definitions that could be used with different tradeoffs. In particular, implementations will likely use a fast approximation of balancing, and won't actually use this specific mathematic formula from the spec. The spec should be relaxed to not prescribe any mathematically precise definition of "balanced."

frivoal commented 1 year ago

@litherum would something like this work for you?

Line boxes are balanced when the variation in line length (including lines that end in a forced break) is minimized over the block.

The exact algorithm is UA-defined.

This would gain flexibility, potentially at the expense of some small reduction in interop. But that doesn't see overly important, as relying on an exact choice of line-breaking is already fragile for many other reasons.

nigelmegitt commented 10 months ago

See also https://github.com/w3c/csswg-drafts/issues/8640#issuecomment-1742949606 in which I argue that text-wrap: balance based on line length alone is not an appropriate solution for breaking 2 or 3 line blocks of subtitle/caption text into lines: grammatical constructions need to be taken into account as well.

fantasai commented 9 months ago

@frivoal I don't think that fix quite addresses the issue, and also the reason the spec focuses on the remaining space on the line is because addressing the line length itself doesn't work in the presence of floats.

frivoal commented 2 months ago

Should we simply replace "standard deviation" with "variation" in the original phrasing?