Page MenuHomePhabricator

Bug 1832955 - Support font-relative units when parsing letterSpacing/wordSpacing for offscreen canvas. r=#style,#gfx-reviewers
ClosedPublic

Authored by jfkthame on Jul 31 2023, 2:01 PM.
Referenced Files
Unknown Object (File)
Dec 17 2025, 3:33 PM
Unknown Object (File)
Oct 13 2025, 4:23 AM
Unknown Object (File)
Oct 11 2025, 1:28 PM
Unknown Object (File)
Jun 17 2025, 4:26 PM
Unknown Object (File)
May 12 2025, 7:11 PM
Unknown Object (File)
May 8 2025, 2:42 AM
Unknown Object (File)
Apr 16 2025, 8:44 PM
Unknown Object (File)
Apr 14 2025, 2:48 PM
Subscribers

Event Timeline

phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
This revision is now accepted and ready to land.Jul 31 2023, 4:18 PM

This revision requires a Testing Policy Project Tag to be set before landing. Please apply one of testing-approved, testing-exception-unchanged, testing-exception-ui, testing-exception-elsewhere, testing-exception-other. Tip: this Firefox add-on makes it easy!

emilio requested changes to this revision.Jul 31 2023, 5:35 PM

The approach looks fine, but I have some nits.

dom/canvas/CanvasRenderingContext2D.cpp
2746

Probably worth returning something saner here. 16px font-size etc. But I guess this is fine too. There's some overlap here between this and https://phabricator.services.mozilla.com/D180618

layout/style/GeckoBindings.h
512

Maybe mComputedEmSize or so, to as not be confused with nsFontMetrics::EmHeight etc?

servo/components/style/values/specified/length.rs
165

It'd be more idiomatic to use get_metrics: impl Fn() -> GeckoFontMetrics, so as to keep this all safe, and keep the unsafe bits inside glue.rs

168

nit: no need for return

169

nit: Self::Em etc might be better than FontRelativeLength::Em

1117

Let's format this properly:

$ rustup run nightly rustfmt  servo/components/style/values/specified/length.rs
testing/web-platform/meta/html/canvas/offscreen/text/2d.text.drawing.style.letterSpacing.change.font.html.ini
4

Why only on Linux?

This revision now requires changes to proceed.Jul 31 2023, 5:35 PM
jfkthame added inline comments.
dom/canvas/CanvasRenderingContext2D.cpp
2746

I think this really shouldn't happen (if we fail to create a fontgroup, we're probably about to OOM-crash or something!), but if we don't want to just return zeros, we should probably do something based on the canvas default font size (10px) rather than HTML's 16px.

testing/web-platform/meta/html/canvas/offscreen/text/2d.text.drawing.style.letterSpacing.change.font.html.ini
4

On the other platforms we get a minuscule discrepancy due to floating-point calculations; we should just make the test do an approx_equals, like other measurement tests, but I didn't do it here because I've noticed there's a big reorg of these tests in progress from Chrome's side, likely to appear in the next wpt sync. So to avoid causing a merge conflict there, I figured I'd wait till that dust settles (then I want to add some more testcases as well).

jfkthame updated this revision to Diff 748765.
jfkthame marked an inline comment as done.
emilio edited projects, added testing-approved; removed needs-testing-tag.
emilio added inline comments.
servo/ports/geckolib/glue.rs
7816

We never expect a null get_font_metrics function here right? same for the Option<> around in to_computed_pixel_length_with_font_metrics... Maybe consider removing the Option<>s everywhere?

Looks good either way.

emilio removed a reviewer: Restricted Project.Aug 1 2023, 8:55 AM
This revision is now accepted and ready to land.Aug 1 2023, 8:55 AM
servo/ports/geckolib/glue.rs
7816

I was in two minds about this (still am, I guess).... yes, as it stands we'll never get a null function; the only caller is the canvas2d code being touched here and it passes a getter. So we could simply require it.

But letting the getter be optional means that the method can still provide the same functionality as previously, of parsing only absolute lengths, which seems like a possibly-useful option. (Perhaps we'll never have a need for that again, it was basically just a stopgap here?)

I think I'll leave it as optional for now, so anyone just wanting to parse a css length from random style-context-less code can do so without having to think about font metrics.