In the new textframe world, I've reorganized our implementation of
whitespace collapsing.

The situation is confusing because there are really three kinds of
whitespace collapsing and elimination:
1) Collapsing of multiple consecutive spaces (including spaces
consecutive across node boundaries) into one; the first space is
retained and all the others are eliminated.
2) Elimination of any space at the start of a line.
3) Elimination of any space at the end of a line.

All of these are suppressed by CSS white-space:pre and related styles.

I've made step 1) happen entirely at textrun construction time. This
reduces the size of textruns and makes us more efficient at measuring
and drawing. It's also actually very simple to do it this way instead
of "on the fly".

Step 3) has to happen at reflow time because we don't know which
spaces are at the end of lines. So I adapted the existing textframe
code that does that; the space is in the textrun but the textframe
doesn't draw or measure it. Line layout calls TrimTrailingWhitespace
on the last textframe(s) in the line to tweak the text frame's
metrics. This could stand some cleanup but the code we have works not
too badly.

Step 2) has been a problem. I was doing it at textrun construction
time in conjunction with step 1. That is normally fine because reflow
normally puts all space at the end of lines which is then handled by
step 3), so space at the start of lines normally only happens at block
boundaries, which is easily detected at textrun construction time. But
in general things are more complicated. For example, a white-space:pre
"\n" or a <br> element might be followed by spaces all on a single
line after frame construction but before reflow. Having textrun
construction detect that these spaces will be at the start of a line
is going to be too complex and fragile, I think --- it depends on
knowing everything that can induce a line break, or exposing that via
some new API. So I'm going to move this back to reflow time as well.

_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout

Reply via email to