Closed Bug 1607308 Opened 6 years ago Closed 5 years ago

wrong text-underline-offset zero position with text-underline-position:under

Categories

(Core :: CSS Parsing and Computation, defect, P3)

73 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: aja, Assigned: jfkthame)

References

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0

Expected results:

Seems that with text-underline-position:under the text-underline-offset:auto Underline Offset Origin (Zero Position) is incorrectly relative to alphabetic baseline rather than the text-under edge.

Possible blocker for bug 1606997 "Let CSS text-underline-position property ride the train to release".

This is part of a broader set of changes that were just made to the CSS Text Decoration spec last week; see

https://drafts.csswg.org/css-text-decor-4/#text-underline-position-property
https://drafts.csswg.org/css-text-decor-4/#underline-offset
https://drafts.csswg.org/css-text-decor-4/#line-offset-zero

Briefly, the from-font value of text-underline-offset (which we already support) is removed and instead a from-font value is added to text-underline-position; and then text-underline-offset is measured from a newly-defined "zero position" that depends on the value of position.

Also, both text-underline-offset and text-decoration-thickness are extended to support percentage values. We should do that in a separate bug, I guess.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Component: General → CSS Parsing and Computation
See Also: → 1608503
Assignee: nobody → jfkthame
Status: NEW → ASSIGNED

After reviews, if you push a try build with this and patch from 1607534 including Win64, I'd be happy to test before it hits autoland.

Thanks Bill! There's actually a try build already at https://treeherder.mozilla.org/#/jobs?repo=try&revision=9c79c4e2ffeba83e1c562ff9b270a4a71be9ea7b you could test - I don't remember if the patches there are exactly what's under review now but it's certainly close, and behavior ought to be the same I think.

I'll do another try build after any last adjustments, but if you have a chance to test that build already and let me know if it behaves as expected, that'd be great.

Don't know if it's offsetting incorrectly from text-under edge, or according to spec,
but text-underline-position:under and text-underline-offset:auto has descenders touching the underline.
Setting offset to 1px, the descenders and underline don't touch.
16px Times New Roman.

Same with setting offset to .0625em or 6.25% (1/16px).

FWIW, viewed at 200% Zoom, it looks like that with an extra 1px or .0625em or 6.25% offset, it'd match Chromium's text-underline-position:under (they don't currently implement text-underline-offset property).

Hmm... it's not entirely clear to me what text-underline-offset:auto ought to do when text-underline-position:under is in effect; I was assuming it should result in a zero offset, but AFAICS the spec does not explicitly require that (or any other particular behavior), so we may want to adjust it.

But in any case, close examination indicates that we're not getting the "zero position" quite right, so that position:under and offset:0 places the underline slightly higher than it should, regardless of whether auto should behave like zero in this case or not. So I'll look into that; it may indicate an issue with the font metrics we're retrieving to determine where the descent should be.

(In reply to Jonathan Kew (:jfkthame) from comment #8)

But in any case, close examination indicates that we're not getting the "zero position" quite right, so that position:under and offset:0 places the underline slightly higher than it should, regardless of whether auto should behave like zero in this case or not. So I'll look into that; it may indicate an issue with the font metrics we're retrieving to determine where the descent should be.

OK, I see what's going on here -- we're using the wrong "descent" metric for position: under. We should base the under position on the font's maxDescent value, which comes directly from the descent field in the hhea or OS/2 table of the font, not on emDescent which is a synthetic value based on partitioning the em-height into ascent and descent portions, in proportion to the font's declared ascent and descent. This is used to determine where to put the baseline within the overall em height, but if the font's ascent+descent ≠ em-size then it may not match the actual font metrics.

Switching use of emDescent to maxDescent when handling position:under fixes the "zero position" of the underline.

The remaining question is what to do for offset:auto in this case: the spec leaves this up to implementations ("the UA chooses an appropriate offset for underlines") in all cases except when position:from-font was used, so it's not "wrong" for us to use an offset of zero here (as the patch currently does), but on consideration, I think it'd be better to apply the font's underlinePosition so that the resulting underline is slightly below the font's descent, just as the default underline is slightly below the alphabetic baseline. An author who wants the underline exactly at the descent can use offset:0 to achieve this.

Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e55052ed4064 Move the from-font value from text-underline-offset to text-underline-position, as per recent spec changes, and fix interaction between position and offset. r=emilio
Failed to create upstream wpt PR due to merge conflicts. This requires fixup from a wpt sync admin.

Ah, this actually causes a currently-failing test to start passing, so we need to adjust the metadata. Sorry I missed that. (The test concerned is still dubious, as noted in the issue pointed to by the annotation, but it now happens to pass on android at least.)

Flags: needinfo?(jfkthame)
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/ae6fc7e3e68f Move the from-font value from text-underline-offset to text-underline-position, as per recent spec changes, and fix interaction between position and offset. r=emilio

Nice work.
text-underline-offset:auto text-underline-position:under with above patch now looks to be a proper accounting-style underline...
it clears the descenders (with all text-decoration styles, i.e. dashed, dotted, double, solid, and wavy ).
Will test again when the autoland build with the refactoring in Bug 1612822 is complete.

Same as above with Bug 1612822 refactor, so text-underline-offset:auto with text-underline-position:under seems okay now.
I also tried text-underline-offset:0 with text-underline-position:under and that does NOT clear the descenders, however.

(In reply to Bill Goldstein [:aja] (UTC-6) from comment #17)

Same as above with Bug 1612822 refactor, so text-underline-offset:auto with text-underline-position:under seems okay now.

Great, that's what I would expect - thanks for testing.

I also tried text-underline-offset:0 with text-underline-position:under and that does NOT clear the descenders, however.

Right, this will place the underline at (not slightly below) the font's descender metric, which (depending how the font designer has set the ascent/descent metrics) is likely to just touch the bottom of typical descenders. I believe that's the expected behavior.

I'd expect zero offset for position under not to touch descenders at all, and therefore be unaffected by ink skip, as is now the case for auto offset.

FWIW, looks like https://bugs.chromium.org/p/chromium/issues/detail?id=785230 is now "Assigned" (though I don't see an assignee).
Zero position interop should be the main concern.

I'd expect zero offset for position under not to touch descenders at all

The spec says that the zero position should be the "text-under edge", but I'm not sure where (or whether) that term is defined... I took it to mean the font's descent metric, but maybe this needs to be clarified. (It's complicated by the fact that OpenType font files contain up to three different "descent" metrics, which may all differ.)

There is also no guarantee that the "descent" metric provided by the font, and used by Firefox as the "text-under edge" here, actually corresponds to the bottom of the descenders of the glyphs.

If you're concerned that the interpretation of the zero-offset position for under here is wrong, I think it'd be helpful to bring this up with the CSS working group and seek clarification. It's not clear to me what other basis besides "the descent metric from the font" we could usefully rely on.

Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/21754 for changes under testing/web-platform/tests
Flags: needinfo?(jkew)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: