Re: [csswg-drafts] [css-ruby] vertical-align on ruby bases (#4987)

So what Firefox currently does is that we assume that ruby base, ruby base container, and ruby container would all align on the same baseline, and size ruby base container and position ruby annotation containers based on that assumption.

A pseudo code of what's happening when reflow a ruby container is:
1. set baseline and block size of ruby container based on font metrics
2. for each [segment](https://drafts.csswg.org/css-ruby-1/#ruby-segments) in ruby container:
   1. set _ascent_ and _descent_ to zero
   2. for each [pair](https://drafts.csswg.org/css-ruby-1/#pairing) in the segment:
      1. reflow all ruby annotations of the pair
      2. reflow the ruby base of the pair
      3. set _ascent_ to max(_ascent_, ascent of the ruby base)
      4. set _descent_ to max(_descent_, descent of the ruby base)
   3. vertical align all ruby annotations in the segment
   4. use _ascent_ and _descent_ for baseline and block size of the ruby base container
   5. vertical align ruby bases in the segment with non-top/bottom `vertical-align`
   6. for each ruby annotation container in the segment:
      1. calculate the size of the ruby annotation container to wrap all its children
      2. stack it around the ruby base container
3. vertical align all ruby base containers with non-top/bottom `vertical-align`

These steps indicate that the vertical offset of ruby bases doesn't affect the block size of the ruby base container, and consequently doesn't affect the positioning of ruby annotation containers.

The observation is that, the ruby base container needs to have a baseline before its content can be vertically aligned, and because children are positioned relative to their parent's box, we would need the ascent / descent of the container to be available at that point. Theoretically, it is not impossible to update the ascent and descent after doing vertical alignment, but that means an additional step to update the (relative) position of all ruby bases again (after 2.5). Note that this extra step doesn't itself creates cycle, but it's impossible to take `vertical-align: top | bottom` into account.

So if there isn't a use case for vertical align on ruby base and have it consequently affect its annotation, I think implementation-wise this approach is simpler.

Worth noting that, because ruby annotations form a separate line, and the ruby annotation container is a container of the line (rather than an inline container), it doesn't have a baseline itself, and its size is calculated after vertical aligning ruby annotations, `vertical-align` on ruby annotations would affect levels outside it.

-- 
GitHub Notification of comment by upsuper
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4987#issuecomment-622794193 using your GitHub account

Received on Saturday, 2 May 2020 07:30:17 UTC