Add Canvas writingMode and textOrientation#12153
Add Canvas writingMode and textOrientation#12153schenney-chromium wants to merge 9 commits intowhatwg:mainfrom
Conversation
|
cc @whatwg/canvas |
|
cc @fantasai |
| <p>Can be set, to change the writing mode. The possible values and their meanings are given | ||
| below. Other values are ignored. The default is "<code | ||
| data-x="dom-context-2d-writingMode-horizontal">horizontal</code>".</p> | ||
| </dd> |
There was a problem hiding this comment.
These domintro boxes are supposed to be self-contained. I see "given below" is an established pattern, but it seems wrong. Can we describe these new ones here and file an issue to redo the older ones?
The level of detail can be fairly low, just enough so someone knows what to do.
There was a problem hiding this comment.
I noticed this problem too. In particular the developer version of the spec does not include the "given below" descriptions. I started another PR at some point to address this but dropped it. I can pick it up again.
| object implementing the <code>CanvasTextDrawingStyles</code> interface is created, the <code | ||
| data-x="dom-context-2d-writingMode">writingMode</code> attribute must initially have the value | ||
| "<code data-x="dom-context-2d-writingMode-horizontal">horizontal</code>".</p> | ||
| </div> |
There was a problem hiding this comment.
We should make this modify an associated concept of the context instead of continuing to conflate public and private API. We should also use the modern "getter steps" and "setter steps" terminology.
source
Outdated
|
|
||
| <div algorithm> | ||
| <p>The <dfn attribute for="CanvasTextDrawingStyles"><code | ||
| data-x="dom-context-2d-textOrientation">textOrientation</code></dfn> IDL attribute, on getting, |
source
Outdated
| </dl> | ||
|
|
||
| <p>The <code data-x="dom-context-2d-writingMode">writingMode</code> attribute's allowed keywords | ||
| are as follows:</p> |
There was a problem hiding this comment.
I don't think this section adds much. Some of it should be inside the domintro and some of it should be part of the normative processing model probably.
There was a problem hiding this comment.
Got it. Will do.
source
Outdated
| <tr> | ||
| <td><span>'writing-mode'</span></td> | ||
| <td><var>target</var>'s <code data-x="dom-context-2d-writingMode">writingMode</code> | ||
| using "vertical-rl" for <code data-x="dom-context-2d-writingMode-vertical">vertical</code>. |
There was a problem hiding this comment.
This should be marked up as a string. And maybe it should link back to its definition?
There was a problem hiding this comment.
Are you referring to 'writing-mode' or "vertical-rl"?
source
Outdated
|
|
||
| <p>Horizontal position:</p> | ||
| <p>Apply the appropriate step from the following list to determine the value of | ||
| <var>inline offset</var>:</p> |
There was a problem hiding this comment.
We should use camel case for variable names. And I'd make the switch return a value. That seems clearer.
source
Outdated
| </dl> | ||
| </li> | ||
|
|
||
| <li><p>Set the <var>anchor point</var> as follows:</p> |
There was a problem hiding this comment.
Wrapping is wrong here as the <li> has multiple children.
source
Outdated
| <p>Vertical position:</p> | ||
| <li> | ||
| <p>Apply the appropriate step from the following list to determine the value of | ||
| <var>baseline offset</var>:</p> |
There was a problem hiding this comment.
Camel case plus return from the switch.
source
Outdated
|
|
||
| <li><p>Return <var>result</var>, <var>physical alignment</var>, and the inline | ||
| box.</p></li> | ||
| <li><p>Return <var>result</var>, the inline box and <var>anchor point</var>.</p></li> |
|
I think it's worth considering whether the divergence from CSS (just (Is all canvas text today single-line? How likely is it to stay that way?) |
I've thought about these issues. My reasoning on
All canvas text right now is single line. If you want multi-line you put the There have been various proposals for more complex text styling in canvas including methods for laying out multiple lines, but they have all been made redundant by HTML-in-Canvas. We've even got TAG feedback on other canvas text features saying they would rather we moved HTML-in-Canvas forward due to the accessibility benefits. I'm not great at predicting the future but HTML-in-Canvas seems more likely than not. Once it exists I think the desire for new canvas APIs for styled and multi-line text will disappear. |
While I agree with the introduction of HTML-in-Canvas, I would like to see progress on multi-line text rendering via Canvas separately. This is because I want to render text even in environments that do not assume the presence of HTML. Previously, text rendering in |
|
Hello, I am an end-user involved in the display of vertical text in Japanese. I think we need to add "central" to CanvasTextBaseline. In contrast, Canvas textBaseline="middle" represents the midpoint between em-over and em-under (i.e. a geometric midpoint). This is a different concept from the typographic central baseline, so they are not interchangeable. If this PR introduces writingMode="vertical" and textOrientation, it should be possible to select "central" to keep alignment behavior consistent with CSS. |
Thanks very much for your input. I believe we can add a |
schenney-chromium
left a comment
There was a problem hiding this comment.
Next iteration done.
Kaiido
left a comment
There was a problem hiding this comment.
Disclaimer: I am not an expert in text rendering at all, so I can't really do any technical review here.
Regarding the vertical vs vertical-lr & vertical-rl, I'd be supportive of the latter option as I believe that on top of supporting a possible future multi-line API, it would be a better DX: I assume CSS computed values is a common source of context settings, and having to manually parse from there adds more complexity. But I must admit I don't fully understand your point about textBaseline; playing a bit with Chrome's SVG impl. which does support writing-mode and alignment-baseline on <text>, I didn't see a difference while switching between vertical-lr and vertical-rl.
source
Outdated
| control the orientation of text runs. Valid values are "<dfn enum-value | ||
| for="CanvasWritingMode"><code | ||
| data-x="dom-context-2d-writingMode-horizontal">horizontal</code></dfn>" and "<dfn enum-value | ||
| for="CanvasWritingMode"><code data-x="dom-context-2d-writingMode-vertical">vertival</code></dfn>". Initially, the <span data-x="concept-CanvasTextDrawingStyles-writing-mode">writingMode</span> must |
source
Outdated
| data-x="dom-context-2d-textBaseline">textBaseline</code> attribute to the top of the bounding | ||
| rectangle of the given text, in <span data-x="'px'">CSS pixels</span>; positive numbers | ||
| indicating a distance going up from the given baseline. | ||
| <p>The distance perpendicular to the inline direction from the <span |
There was a problem hiding this comment.
If I understand correctly, this means the actualBoundingBoxAscent and Descent would be dependant on the orientation, while fontBoundingBoxAscent and Descent would always return the same values?
I'm wondering if it's going to be an issue if one were to use both in some calculations. Though I don't really have an use case in mind.
There was a problem hiding this comment.
To my mind the fontBoundingBoxAscent/Descent attributes are poorly named. I'm guessing they were added in the first TextMetrics proposal and then the emHeightAscent and friends were added later, because I would expect fontBoundingBoxAscent to be fontAscent given the naming of the other attributes.
With that view, fontBoundingBoxAscent is a font derived property independent of orientation, whereas actualBoundingBoxAscent is a measurement of the rendered shape which depends on orientation.
|
In response to comments I've added the There seems to be enough support for both |
|
I've updated based on the review comments so far. It's ready for another look. |
Add canvas text style attributes for
writingModeandtextOrientation, as discussed in #issue11449The
writingModeattribute determines the orientation of the text string when measured and rendered, whiletextOrientationcontrols the orientation of individual glyphs within the string.In addition to documenting the attributes, this PR also updates the text preparation algorithm and the
measureTextalgorithm. Some other things are re-worded to make them direction agnostic, primarily by using CSS inline direction terminology.The choices made in defining behavior, particularly around the alignment attributes and the text metric bounding box attributes, are an attempt to capture the expectations of developers. Of particular concern is anything related to text baseline metrics which have no obvious interpretation for vertical text.
/canvas.html ( diff )
/infrastructure.html ( diff )