Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gsnedders opened this issue Mar 24, 2019 · 7 comments
Open

Comments

@gsnedders
Copy link
Contributor

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.

@gsnedders gsnedders added the CSS2 label Mar 24, 2019
@pcwalton
Copy link

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
Copy link
Contributor Author

gsnedders commented Mar 24, 2019

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.)

@gsnedders gsnedders added the css-text-3 Current Work label Mar 24, 2019
@pcwalton
Copy link

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
Copy link
Contributor Author

@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
Copy link

Here are some examples: servo/servo#12092 servo/servo#14807

Main issue: servo/servo#13683

@pcwalton
Copy link

pcwalton commented Mar 24, 2019

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
Copy link
Member

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.

@fantasai fantasai added css-text-4 and removed css-text-3 Current Work labels Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants