Working on a proposal for the algorithm of fit-to-...
# devlog-together
r
Working on a proposal for the algorithm of fit-to-width text for CSS. Planning to present it to CSSWG next week if all goes right :) I already have a technique that handles a few main use cases (https://kizu.dev/fit-to-width/), but if we want it to be native, we need to handle a bunch more: specifically, a case when a line of text has “static” elements that do not change their dimensions in response to the font-size change. This, with added handling of optical sizing of a font, requires us to basically render the same line box up to 4 times, but with 2 of those being optional (when no static elements, or no optical sizing axis present in the fonts used). So mostly working on fine-tuning the algorithm + making a prototype of it with custom elements & shadow DOM (with no runtime JS for layout, only for duplicating the content to emulate multiple renders), and also thinking about what an API for this property could look like, with possible options, etc. And will need to also think how some other edge cases will need to be handled (reverse dependence on the font-size, initial-letter, and a bunch more).
c
Oh wow this is awesome! Definitely interested in how the custom element comes out!
i
That's exciting! When you say "render the same line box up to 4 times", does that mean "paint" or just "layout" (or something else)?
r
Layout, but in isolation, without the need to recalc anything outside the line until we decide on its size.