Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing Print Reftests finer control over the application of CSS page size #175

Open
jwatt opened this issue Dec 9, 2023 · 1 comment

Comments

@jwatt
Copy link

jwatt commented Dec 9, 2023

For pagination/printing we need to consider both virtual pages and sheets of paper (multiple pages may be printed on a single sheet of paper).

This section of CSS Paged Media 3 talks about how to position pages on a sheet:

https://drafts.csswg.org/css-page-3/#positioning-page-box

What browsers actually do when it comes to sizing pages and sizing sheets for @page size is quite complicated. A simplified description would be that CSS page size is always applied to the pages. But what happens to the sheets depends on whether the output target is a PDF file or a printer. If it is a PDF file, and if the user is printing one page per sheet, then the CSS page size is also applied to the "sheets" written into the PDF (the size of the page and sheet then match exactly). If the target is something else (perhaps a physical or virtual printer), then the page is scaled to fit whatever size of sheet is in use (perhaps what an output printer supports, or a size specified by the user) as described in the section of the spec that I linked above.

Prior to pull 173, sheets would all be the same size in WPT Print Reftests, which meant that only the scaling behavior was tested, and testing of the application of CSS page size rules to sheets could not be tested. That pull request changes the requirements on the test harness to apply CSS page size to the PDF sheets that are output. But that means that the scaling behavior described in section of the spec linked above now can't be tested.

I've encountered this issue while looking to test a bug that Firefox has where, if a page is much smaller than a sheet, Firefox will scale it up to fit the sheet rather than centering it or positioning it in the upper-left corner. This is pretty undesirable behavior from a user's point of view, and I plan to fix Firefox to match Chrome's centering behavior. But I would like to be able to add tests for that.

I think it is sensible for WPT Print Reftests to default to applying CSS page size to the sheets too, but given that browser's have the two different behaviors (size-the-sheet vs. scale-the-page), it would be useful if WPT Print Reftests had the flexibility to test the scale-the-page behavior.

Could we have some sort of mechanism for Print Reftests to specify that they would like to have the scale-the-page behavior when encountering CSS page size? Perhaps a meta tag, something like:

<meta name=page-size-fitting content=[match-sheet-to-page|scale-page-to-sheet]>

or just:

<meta name=size-sheets content=[yes|no]>

@jgraham @mstensho

@mstensho
Copy link

https://drafts.csswg.org/css-page-3/#intro goes "CSS3 does not specify how user agents transfer page boxes to sheets".

https://drafts.csswg.org/css-page-3/#renderingpages and https://drafts.csswg.org/css-page-3/#positioning-page-box and https://drafts.csswg.org/css-page-3/#transfer-possibilities also suggest that the spec doesn't really want to define any standardized behavior here.

Firefox and Chrome certainly don't always agree here, but as long as there's no standard, should we really add WPT tests for it? And I think it's quite deliberate that the spec doesn't want to define this, since it's not just for browsers.

That said, I'm not happy about having to write internal Chromium tests (often they aren't even web tests) every time I change / fix something not covered by the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants