[csswg-drafts] [css-text] Replacement for `text-align: <string>` and solution for numeric column alignment (#10791)

Crissov has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-text] Replacement for `text-align: <string>` and solution for numeric column alignment ==
The [CSS 2.0](https://www.w3.org/TR/2008/REC-CSS2-20080411/syndata.html#value-def-string) value `<string>` for the `text-align` property has been removed from [CSS 2.1](https://www.w3.org/TR/CSS2/text.html#alignment-prop) and been punted from [CSS Text level 3](https://drafts.csswg.org/css-text-3/#justification) to [level 4](https://drafts.csswg.org/css-text-4/#justification). [XSL 1.1](https://www.w3.org/TR/xsl/#text-align) keeps it.
_Can I Use?_ data is not available yet, but has been [requested](https://github.com/Fyrd/caniuse/issues/4372). It has never been implemented in browsers as far as I know (except perhaps Presto-based Opera), but at least [Antenna House Formatter](https://www.antennahouse.com/hubfs/uploads/CSS/CSS-Print-en-2019-02-15.pdf#nameddest=text-align) does support it, while other PDF generators/print processors apparently don't (e.g. [PrinceXML](https://www.princexml.com/doc/css-props/#prop-text-align), [Weasyprint](https://doc.courtbouillon.org/weasyprint/stable/api_reference.html#css-text-module-level-3-4), [PDF Reactor](https://www.pdfreactor.com/product/doc_html/index.html#text-align), [BFO Publisher](https://publisher.bfo.com/live/help/#propindex-text-align)).

> * [`<string>`](https://drafts.csswg.org/css-values-4/#string-value)
>   The string must be a single character; otherwise the declaration is invalid and must be ignored.
>   When applied to a table cell, specifies the alignment character around which the cell’s contents will align.
>   See [below](https://drafts.csswg.org/css-text-4/#character-alignment) for further details and how this value combines with keywords.

[HTML4](https://www.w3.org/TR/html4/struct/tables.html#h-11.3.2) had the (optional) presentational attributes `char` and `charoff` for this in cell and column elements (if `align=char` was set), but the [HTML LS](https://html.spec.whatwg.org/multipage/tables.html) omits it (also from [alignment notes](https://html.spec.whatwg.org/multipage/rendering.html#align-descendants)). I don't know if this was ever implemented anywhere.
It *definitely* is a desirable feature for ergonomics of tabular data, but it seems to be difficult or expensive to implement, so has been gotten shelved for over twenty years.

In [#9877](https://github.com/w3c/csswg-drafts/issues/9877#issuecomment-1919036223), I suggested that the string value could be dropped from `text-align` altogether **if** there was a CSS way to add leading and trailing invisible zeros to selectable contents (virtually U+2007 Figure Space and U+2008 Punctuation Space as needed). I doubt this could be done with `td::after {content: …}` like [leaders](https://drafts.csswg.org/css-content/#leaders).

While the current design is basically unimplemented and maybe insufficient, I cannot offer a proposal for a better solution to this problem yet. I think alignment templates as used in[ spreadsheet applications](https://docs.oasis-open.org/office/OpenDocument/v1.4/csd01/part3-schema/OpenDocument-v1.4-csd01-part3-schema.html#element-number_number-style) or cell content type hints *could* help, but I'm not even sure whether they belonged into HTML or CSS. I actually tend to prefer the former, although a dedicated [element type](https://github.com/whatwg/html/issues/9294) might be better still. But even if the markup included information on the content that helped with its alignment, style authors would likely want to fine-tune or override it, so a CSS solution remains inevitable. A `<string>` longer than a single character *could* be interpreted as a spreadsheet-like [number formatting pattern](https://support.microsoft.com/en-us/office/review-guidelines-for-customizing-a-number-format-c0a1d1fa-d3f4-4018-96b7-9c9354dd99f5), e.g. `#,##0.0??`, and still remain backward-compatible with CSS2. (I'm not quite proposing that, though.)

A new value for the `text-align` property could help with the alignment of table cells. Called `from-content`, `auto`, `numeric` or `tabular`, it would horizontally align content like `right` if all applicable characters were numeric, whitespace or punctuation according to their Unicode properties, and like `start` (not `left`!) otherwise. (This would deal well with numbers in most notations, but lacked support for values that contain units.) [OpenDocument](https://docs.oasis-open.org/office/OpenDocument/v1.4/csd01/part3-schema/OpenDocument-v1.4-csd01-part3-schema.html#property-style_text-align-source) uses `text-align-source: fix | value-type` where the latter keyword triggers the semi-automatic behavior.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10791 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 27 August 2024 14:06:20 UTC