whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.13k stars 2.67k forks source link

canvas TextMetrics APIs should define rounding better #4072

Open dbaron opened 6 years ago

dbaron commented 6 years ago

This is filed based on a subset of the comments in https://github.com/w3ctag/design-reviews/issues/302#issuecomment-422999075 about the definitions of TextMetrics. In particular:

  • the API methodsproperties don't say anything about what rounding is performed. Is the expectation that the results be round numbers of CSS pixels, round numbers of device pixels, or unrounded?
yiyix commented 5 years ago

it's unrounded. We will update the spec to reflect this.

annevk commented 5 years ago

cc @whatwg/canvas

annevk commented 5 years ago

So having looked at the PR I'm a little confused by this request as the document CSS pixels links to https://drafts.csswg.org/css-values/ does not use or define "unrounded". And unless otherwise stated everything in standards is usually precise up to implementation-defined limits.

Is there some kind of precedent here we should follow or some particular concern that prompted this question?

fserb commented 5 years ago

I agree with @annevk's point.

dbaron commented 5 years ago

I guess I feel like there's a bit of a history of Gecko implementing things whose values are pixels unrounded and other implementations doing rounding in various ways, and then Gecko having to change to match the rounding done elsewhere. Though perhaps that's the distant past now? So I'm a little hesitant about the "unless otherwise stated everything in standards is usually precise" since I'm not so sure how widely-shared that understanding is. I think it's useful to state that things are unrounded explicitly; the explicit statement also encourages people to write tests for it.

annevk commented 5 years ago

That would make sense to me if that were the practice in CSS and CSS defined "unrounded" and what it would mean for CSS pixels. That is, I don't think this is something HTML could adopt on its own. It would have to be a universal practice to convey meaning and not end up being confusing.

fserb commented 5 years ago

Is there a note we could add to remember implementers that those values are CSS-values and therefore abide by the same rules of precision?

dbaron commented 5 years ago

What I'm talking about is primarily about APIs and not about CSS layout -- though it might be reasonable for such definitions to live in cssom-view rather than HTML.

annevk commented 3 years ago

Sorry for responding very late, but how is CSS layout (or style sheets rather) not an API? In the end all of these things end up invoking a set of drawing primitives and ideally those would be consistent between CSS and <canvas>, no?