-
-
Notifications
You must be signed in to change notification settings - Fork 696
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
[ADD] position: running(); content: element(); #882
Conversation
@@ -209,6 +209,9 @@ def __init__(self, enable_hinting, style_for, get_image_from_uri, | |||
self.tables = {} | |||
self.dictionaries = {} | |||
|
|||
# TODO: this is probably the wrong place to put this | |||
self.running_elements = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll have to carry around the running elements somewhere. Do you think this belongs here or should I extend the state tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the specification isn't clear enough. It's hard to know which running element you'll have in the page margin when multiple running elements are in the page. The string()
function at least has a second argument for that.
Even a sigle value, in example 5 for example, is not clear to me: what's on the second page?
- We could put '2 / Miranda v. Arizona in Context'.
- We could put '1 / Miranda v. Arizona in Context', as the running element is defined on page 1.
- We could put nothing, as no running element is defined on page 2.
(I think that we want the first answer.)
The place where to put running elements depends on the answer to this question. But if we think that running elements somehow behave like named strings, then it's the right place to set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not the first answer I wouldn't want to implement it because then it wouldn't be useful for me :-)
I define a box now that does nothing, save for setting the running element for the page. This way, the last running()
on the page wins, that's how I interpret the spec.
The not-doing-anything-box seems clumsy to me, can this be more elegant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, the last
running()
on the page wins, that's how I interpret the spec.
There's a second optional parameter for element()
to define this. We have to use the same behavior as string()
.
generally, my problem is that in https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/layout/pages.py#L348-L349, we assume inline boxes, which crashes in https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/formatting_structure/build.py#L1247. What would be the smartest way to change this? (I just started studying this library, so I'm not yet well versed with available helper functions) |
For now, you can call the functions that are in WeasyPrint/weasyprint/formatting_structure/build.py Lines 74 to 80 in e080d97
We may want to create a function for this later. |
@liZe thanks for the pointers. now this PR actually works, and I just need to wrap it up. last question: I need to have |
4e1b035
to
af6042d
Compare
af6042d
to
0acdbaa
Compare
@liZe this is ready for review now |
0acdbaa
to
b30ffb1
Compare
OK, thanks! I'll look at it. |
great. I just noticed I failed to remove the note about running elements in the docs, just pushed a fixup commit for that. Here the file I mostly used for testing: <html>
<head>
<style type="text/css">
.header {
position: running(header);
}
.footer {
position: running(footer);
text-align: center;
}
@page {
@top-center {
content: element(header);
}
@top-right {
content: string(header_string);
}
@bottom-center {
content: element(footer);
/* without this, there's a line break before the pages
span
*/
width: 100%;
}
@bottom-right {
content: counter(page);
}
}
h1 {
margin-bottom: 15cm;
string-set: header_string content();
}
.page:before {
content: counter(page);
}
.pages:before {
content: counter(pages);
}
.header_string:before {
content: string(header_string);
}
</style>
</head>
<body>
<div class="header">
Hello world file: <span class="header_string" />
</div>
<div class="footer">
<span class="page" /> of <span class="pages" />
</div>
<h1>test1</h1>
<h1>test2</h1>
<h1>test3</h1>
<h1>test4</h1>
<h1>test5</h1>
<h1>test6</h1>
<h1>test7</h1>
<h1>test8</h1>
<h1>test9</h1>
<h1>test10</h1>
<h1>test11</h1>
<h1>test12</h1>
<div class="header">
Hello world2
</div>
<h1>test13</h1>
</body>
</html> which then yields test.pdf |
Thanks a lot 👏. The global way it works seems to be OK for me. I can merge this PR, but I'll change some little things:
I have to dive into the code by fixing the points listed above, I'll check this problem afterwards. |
thanks! If you give me a few pointers I'll be happy to investigate myself, integrating weasyprint into odoo is my current pet project :-) To my understanding we will need some way to know where some box would be in the flow in order to use the correct element in the page margins, that's why I came up with the placeholder. Is your critique specifically that I made this a If you can't answer without doing the code dive yourself, I'll wait and check out the diff. |
❤️
I've made some commits already, but I'll let you some work if you prefer, no problem 😉.
The problem is that the box is removed from the page, we don't need to keep a placeholder to render it at the place it should have been, as we do for absolute boxes for example. When rendered in the margins, it's totally unrelated to its place in the page content (I hope!), unlike absolute boxes. You can see in 0a403d9 that everything works well without it. |
I just tried this feature and it is awesome! But I encountered a problem, when I add a Sample header with table:
Error:
Any idea why this is happening? I am not quite sure if this is a bug or if it is expected behavior (I am quite new to this topic). |
Hello @JanPretzel
Could you please open an issue about that? Thank you! |
Nice job! It would be awesome if we could use this feature in a near-future deployed application. Do you think that you could give a release date for v51? |
@liZe this is a result of our discussion in OCA/reporting-engine#254
This doesn't work yet, but I've a few questions so I figure it's a good idea to open this draft PR in order to talk about code