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

Problem with named pages and out of normal page flow elements #1897

Closed
MWedl opened this issue Jun 20, 2023 · 1 comment · Fixed by #1899
Closed

Problem with named pages and out of normal page flow elements #1897

MWedl opened this issue Jun 20, 2023 · 1 comment · Fixed by #1899
Labels
bug Existing features not working as expected
Milestone

Comments

@MWedl
Copy link
Contributor

MWedl commented Jun 20, 2023

Problem

When rendering following HTML with weasyprint, the CSS for named-page is not applied on the first page. The first page is blue (from the default @page rule), but it contains content of the named page.

<html>
    <head>
        <style>
            #header { position: running(header); }
            #watermark { position: fixed; top: 10cm; left: 5cm; font-size: 30pt; }
            
            @page {
                size: A4;
                background-color: blue;
                @top-center { content: element(header); }
            }
            
            #named-page { page: named-page; }
            @page named-page { background-color: red; }
            
            .pagebreak { break-after: page; }
        </style>
    </head>
    <body>
        <div id="header">HEADER</div>
        <div id="watermark">WATERMARK</div>
        <div id="named-page">
            NAMED PAGE 1
            <div class="pagebreak"></div>
            NAMED PAGE 2
        </div>
    </body>
</html>

Screenshot_20230620_090329

You can get the expected result (both pages in red) by moving the HTML elements for the header and watermark below the named page. However, I think this is unexpected behavior.

Suggestion

I think the problem is in calculating the start page value of the first page. Currently the start page value of the first element (#header) is used which results in an unnamed page. I think weasyprint should exclude elements that are out of the normal page flow from the start/end page value calculation (such as position: running() and position: fixed).

This should be compliant with the CSS specification for page (https://drafts.csswg.org/css-page-3/#propdef-page):

  1. Next, a start page value and end page value is determined for each box as the value (if any) propagated from its first or last child box (respectively), else the used value on the box itself. A child propagates its own start or end page value if and only if the page property applies to it.

NOTE: A first or last child box is not always generated by a first or last child element. For example, an element could only have a previous sibling with 'display: none' which does not generate any box.

What is your opinion on that?

@liZe
Copy link
Member

liZe commented Jun 20, 2023

Hi!

According to the specification, the 'page' names should be inherited from:

The second point is slightly different from "elements in the flow" (because floats create class A break points for exemple even if they’re not in the flow), but your overall diagnostic seems to be the right one.

The code to fix this is probably in the page_values methods in boxes.py and in the places where they’re called.

@liZe liZe added the bug Existing features not working as expected label Jun 20, 2023
@liZe liZe added this to the 60.0 milestone Aug 19, 2023
liZe added a commit that referenced this issue Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants