-
Notifications
You must be signed in to change notification settings - Fork 45
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
Better fix: don't ignore page breaks on empty nodes #234
Conversation
Previous fix (2 commits ago) was wrong, and was adding too many wrong page breaks. This reverts some bits from it, and fix that hopefully the right way.
@Frenzie : requesting your specs reading and interpretation wit. What situation do you think item 3 applies to?
From https://www.w3.org/TR/CSS2/page.html#allowed-page-breaks (not clearer in https://www.w3.org/TR/css-break-3/ or https://www.w3.org/TR/CSS22/page.html#page-breaks) What could be that gap ? (I get the content edge is inside the padding - so what can be between the outer padding and the inner margin ?) |
At a glance I'm not sure. I don't really have time to think about it right now. Perhaps https://www.princexml.com/doc-prince/#page-breaks has something useful to say? |
yeah, doesn't make sense to me either, based on https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model, content edge should the be same as first child's margin edge. |
Or maybe, it's a twisted way of saying the following :) A page break can not occur between a parent (margin|border|padding) and it's first child margin:
(*) : or can it? can we vertically align a child in its container (when the later has a specified height)? so there would then be a gap at top ( |
Easily: |
OK, another question, although not related to page break, but still to margins. There's something I don't get that is shown on the sample from http://test.weasyprint.org/suite-css21/chapter8/section3/test35/ <style type="text/css">
body
{
background-color: blue;
margin: 8px;
}
div#parent-block-container
{
background-color: red;
margin: 0px;
width: 100%;
}
div#child-block
{
background-color: lime;
margin: 100px 0px;
}
</style>
</head>
<body>
<div id="parent-block-container">
<div id="child-block">
There should be no red in this page
</div>
</div>
</body> You get a single lime line over a full blue background: I don't understand why there is not red (as the test say there shouldn't be any red).
No matter what margin value you set, you don't get any red. Only when adding some padding to My brain may be too formatted by crengine box rendering model, and that's why I don't get it - so, is this behaviour expected and clear to you? If yes, can you explain what's happening and why there is no red background? It looks to me that this thing I noted should have no impact regarding this situation: crengine/crengine/src/lvrend.cpp Lines 21 to 34 in a783b53
|
But it is? There's no border or padding, so the top margins of both elements are collapsed. It's the second scenario described on this page: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing |
It has 0 margin, so there's not much margins to collapse :) But, may be it's the last (vague) sentence of the paragraph you point to that implies this behaviour?:
meaning all inner margins are set to zero, so all their content boxes are the same, so no room to apply any intermediate background-color on? |
I don't think the second sentence is vague. :-) It's a logical consequence of parent and first/last-child margins collapsing.
It's written right here: ;-)
|
I mean it looks like an insignificant small and ending sentence (and I didn't focus much on it, given all the other infos), but it has some huge consequence on the algorithm you take to have a go at that... So, my naive way of going at it (because margins are transparent, and used only for positionning): parent has Anyway, OK, I get the why of that behaviour. |
Another question, where the relevant specs are not cleared about their combinations: What should happen when collapsing margins meet forced page-breaks?
If there were no page break, if I understand margin collapsing right, this should end up with a 30px margin between the 2 text parts. (and what should we end up when there is a need for an unforced page split at this point? the specs say the used values of both margin are 0, so, no margin top, really?) With this forced page-break, I don't know what we should get:
Closest specs I found, not even talking about collapsing, just adjoining, not saying which happen first, are: And what should happen with:
3 pages, or just 2, the 2 page-breaks collapsing (as the margin they are on)? And with which values of resulting top margin? |
It's not really something I've had to deal with before. Without having read the specs, as a rule of thumb I'd say that when in doubt, create a test case and see what Prince does. It's likely to be right, or at the very least to do something sensible. |
Thanks for the hint about Prince. <div class=orange style="margin-bottom: 1em">
<div class=yellow style="margin-bottom: 16em">
<div class=green style="margin-bottom: 1em">
some text in previous nested block elements
</div>
</div>
</div>
<div class=red style="margin-top: 1em">
<div class=blue style="margin-top: 7em; page-break-before: always">
<div class=green style="margin-top: 1em">
<div class=orange style="margin-top: 12em; page-break-before: always">
<div class=yellow style="margin-top: 1em">
some text in these nested block elements
</div>
</div>
</div>
</div>
</div> or <div class=orange style="margin-bottom: 1em">
<div class=yellow style="margin-bottom: 16em">
<div class=green style="margin-bottom: 1em">
some text in previous nested block elements
</div>
</div>
</div>
<div class=red style="margin-top: 1em">
<div class=blue style="margin-top: 12em; page-break-before: always">
<div class=green style="margin-top: 1em">
<div class=orange style="margin-top: 7em; page-break-before: always">
<div class=yellow style="margin-top: 1em">
some text in these nested block elements
</div>
</div>
</div>
</div>
</div> Only one page break, top margin on next page of 12em. <div class=yellow style="margin-bottom: 16em">
[...] many lines so that last one is drawn at end of page
<div class=orange>some other text</div>
<div class=green>some text</div>
<div class=orange>some other text</div>
</div>
<div class=red style="margin-top: 1em">
<div class=blue style="margin-top: 12em;">
<div class=green style="margin-top: 1em">
<div class=orange style="margin-top: 7em; page-break-before: always">
<div class=yellow style="margin-top: 1em">
some text in these nested block elements
</div>
</div>
</div>
</div>
</div> margin bottom dropped on previous page, margin top of 12em on next page <div class=yellow style="margin-bottom: 16em">
[...] many lines so that last one is drawn at end of page
<div class=orange>some other text</div>
<div class=green>some text</div>
<div class=orange>some other text</div>
</div>
<div class=red style="margin-top: 1em">
<div class=blue style="margin-top: 12em;">
<div class=green style="margin-top: 1em">
<div class=orange style="margin-top: 7em;">
<div class=yellow style="margin-top: 1em">
some text in these nested block elements
</div>
</div>
</div>
</div>
</div> So, same as previous one with all page-break-before removed, and an unforced page split happening between the 2 main blocks: |
It's not only an excellent renderer in general, but for paged media it implements all the fancy paged media stuff that web-focused renderers may not because it's not where there focus lies. :-) (Although it seems they do a lot more than they used to.) |
Most of the things questioned above have been implemented (correctly I hope) in #299. |
Previous fix (in #233) was wrong, and was adding too many wrong page breaks (noticed by unit tests in koreader/koreader#4217).
This reverts some bits from it, and fix that hopefully the right way.
Note that this fix (to solve koreader/koreader#4207) may still add some new page breaks (and blank pages) that might be bothering (to me at least :) or feel uneeded. But in my tests, they look like they obey HTML and CSS.
For example if one HTML file in an epub (so, making a DocFragment, which generates a page-break by itself) contains:
Previously, the empty div that would have carried the page-break (from DocFragment) was ignored, and the DocFragment page-break was lost, but the one implied by the H3 (we have in epub.css a page-break before H1 H2 and H3) was rendered.
Now, both will be rendered and generate a blank page.
This happened before with some EPUBs for some other reason, and we have a Style Tweak to avoid that (
Avoid blank page on chapter start
). So, I guess those like me who don't like blank page will have to use that tweak more often.The diff from before the previous fix looks like this: