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

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

Open
travisleithead opened this issue Sep 17, 2021 · 2 comments
Open

Comments

@travisleithead
Copy link
Member

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 w3c/css-houdini-drafts#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:

  • The proposed data model isn't specifically tied to HTML canvas. It doesn't necessarily need to follow typical Canvas conventions. We like leveraging the familiar CSS properties versus introducing a parallel set of new JS APIs that do basically the same thing.
  • 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?
  • We assumed StylePropertyMap is the preferred entry point for modern CSS-OM/ Typed OM. Should legacy .style object access be included?

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

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

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.

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