w3c / csswg-drafts

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

Discussion request: CSS usage in WICG's Formatted Text proposal #6629

Open travisleithead opened 3 years ago

travisleithead commented 3 years ago

Hi CSS WG!

An incubation experiment (canvas formatted text) is underway in WICG in which the thesis summary is: can we leverage the power of the CSS layout engine for text line formatting outside of the DOM to provide both 1) richer text formatting options for HTML Canvas rendering and 2) detailed line metrics? The solution aspires to integrate into other existing efforts like Houdini Layout API's treatment for inline boxes). A lot more background can be found in the incubation's explainer. Note, the CSS WG discussed an early version of this proposal last July in https://github.com/w3c/css-houdini-drafts/issues/990, topic: "String based inline layout API".

A primitive JavaScript data model for holding text includes a mechanism similar to DOM Nodes for supplying CSS properties/values through a StylePropertyMap.

At this point in the incubation effort, we would like to validate and discuss the chosen approach to CSS usage with the CSS WG.

Some questions we are thinking about:

Whether CSS syntax is ultimately used as the styling input mechanism or not, the specification of line formatting behavior is expected to conform to existing CSS norms, and refer to algorithms and definitions in CSS language specifications.

Thanks!

tabatkins commented 3 years ago

Only a subset of CSS would be supported (properties applicable to inline/text layout). Is there precedent for such a subset? What precedent might this be establishing for the future?

Yes, CSS has similar subsets for things like the ::first-line pseudo. This list of properties allows text styling, without requiring the browser to expose exactly what the box-tree structure of the pseudo-element is (because ::first-line isn't tree-abiding, and can cross element boundaries in odd ways).

You aren't operating under the same constraints - you've got a well-defined box-tree structure to work with. I see that your list is longer and allows a number of box-associated properties, as a result. I'd ensure that all the text-formatting properties in ::first-line's list are supported, at least; I don't want to spend the time checking if that's the case or not right now. ^_^

I believe Timed Text was assembling a similar list of properties to apply to CC boxes - we should check if that effort ever matured, and if there needs to be some concordance there. I don't recall who in the CSSWG is most connected to that - @frivoal?

We assumed StylePropertyMap is the preferred entry point for modern CSS-OM/ Typed OM. Should legacy .style object access be included?

We don't have a precedent yet, but I believe this should be fine. You can treat the Typed OM API as purely string-based if you want (always setting strings, and getting the stringification of any values you pull out), and canvas-based use-cases might enjoy some of the perf benefits of getting to reuse object-based style values (no text parsing!) if they're animating stuff across frames.

svgeesus commented 3 years ago

There is also precedent in that SVG required support of the relevant CSS properties and property values but (at least in the mobile subsets) did not require support of stylesheets or of selectors). Instead, presentational attributes were used.