w3c / csswg-drafts

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

Float positioning "as high as possible" prohibits non-greedy line-breaking #3756

Open gsnedders opened 5 years ago

gsnedders commented 5 years ago

From https://news.ycombinator.com/item?id=19473277:

[Doing better line breaking in web browsers] comes up on every thread related to web typography, and the answer as always is that it's not possible in the general case, at least not with the specs as they are today. The biggest problem is that the CSS specification demands that a float be placed as high as possible (CSS 2.1 section 9.5.1, rule 8 1). But float ceilings can be anywhere in the middle of a paragraph. By its nature, Knuth line breaking means that any particular unit (word), and therefore any float ceiling, might not be as high as possible. In fact, the only algorithm that can be used in this case to satisfy the spec is the greedy one. Therefore, Knuth line breaking cannot be used on the Web.

It might be possible to use Knuth line breaking in specific circumstances, such as when paragraphs have no floats. But not in general.

If I'm not mistaken, Prince doesn't do this, and I'm dubious that this is the intention of the "as high as possible" rule. Quite how we should phrase the rule if we want to loosen this is a… harder question.

pcwalton commented 5 years ago

Servo doesn't implement this rule properly and the result is a lot of broken pages. Web compat is something we need to carefully consider if we relax this constraint.

gsnedders commented 5 years ago

If it is the case the web relies on this, we should just make it explicitly required to do greedy line breaking (probably in CSS Text, rather than CSS 2.1). Relying on an implication from here isn't great. (Adding the css-text-3 label on that basis.)

pcwalton commented 5 years ago

It might only be a subset of cases that the Web relies on though. I don't mean to kill the attempts at better line breaking without a proper investigation.

gsnedders commented 5 years ago

@pcwalton can you find any of the Servo issues about this? or pages that are broken in Servo? Would be a decent starting point to start looking!

pcwalton commented 5 years ago

Here are some examples: https://github.com/servo/servo/issues/12092 https://github.com/servo/servo/issues/14807

Main issue: https://github.com/servo/servo/issues/13683

pcwalton commented 5 years ago

Note that these particular pages won't be broken with Knuth line breaking, but to me it indicates that web compat investigation is needed. I wouldn't be surprised if there are pages that do depend on float ceiling and greedy line breaking interaction.

astearns commented 5 years ago

I think the set of pages that depend on greedy/float interactions would already be broken in some circumstances. If you are depending on line breaking for a particular float ceiling placement, then a change in font or user font size preference could mess with your intentions. We have never had complete interoperability in line breaks, even with everyone using nearly identical greedy algorithms.

I think it would be reasonable to interpret the 'as possible' float positioning rules as penalties in line breaking scores. A set of line breaks that placed a float higher would score better than a set that placed a left float lower but more left.