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

Inconsistent headers with named pages and running headers #507

Closed
dmoonfire opened this Issue Sep 18, 2017 · 8 comments

Comments

Projects
None yet
3 participants
@dmoonfire

dmoonfire commented Sep 18, 2017

Salutations. I was finally trying to implement #57 in my system and I encountered a strange difficult. I have just as simple set of div.chapter objects with a running header that has the author and title except for the first page of each chapter, which doesn't. When I run this against the latest (6971959), the headers inconsistently disappear on the page.

I have attached a sample which demonstrates this. This is from Frankenstein. The letters all have the headers I expect, but the first page after chapter doesn't, however, I don't have anything different with those so I'm not sure why it disappeared. Likewise, pages 23-34 (the third and fourth page of chapter 2) are doing this.

@dmoonfire dmoonfire changed the title from Difficulties with named pages and running headers to Inconsistent headers with named pages and running headers Sep 18, 2017

@liZe liZe self-assigned this Sep 18, 2017

@liZe liZe added the bug label Sep 18, 2017

@Tontyna

This comment has been minimized.

Contributor

Tontyna commented Jan 19, 2018

Can't reproduce this bug with weasyprint 0.42

@liZe

This comment has been minimized.

Member

liZe commented Jan 21, 2018

Can't reproduce this bug with weasyprint 0.42

I can, what a strange issue.

@liZe liZe added this to the 43 milestone Jan 21, 2018

@liZe

This comment has been minimized.

Member

liZe commented Jan 21, 2018

Justification of the paragraphs' first lines is also broken.

liZe added a commit that referenced this issue Jan 21, 2018

@liZe

This comment has been minimized.

Member

liZe commented Jan 21, 2018

Justification of the paragraphs' first lines is also broken.

At least I've fixed that (and added a test).

@Tontyna

This comment has been minimized.

Contributor

Tontyna commented Jan 22, 2018

Managed to reproduce the missing headers: It only happens on pages where the top line is the first line of a paragraph. WeasyPrint applies @page chapter to those pages. Instead of @page:left or @page:right -- as it does with the other left and right pages of the containing <div class="chapter">.

I expected to achieve a cascade and consistent behaviour by moving the @page chapter - definition in the css above the definitions of @page:left and @page:right -- but without success.

Workaround: Wrapping with an inner <div>

<div style="page: chapter"> 
  <h1>Chapter 1</h1>
  <div> <!-- workaround-wrapper -->
  <!-- 
     the <p>aragraphs of the chapter. 
     :right and :left headers as expected
  -->
  </div>
</div> <!-- end of named page -->      

@liZe liZe closed this in 4ceb8c9 Jan 22, 2018

@liZe

This comment has been minimized.

Member

liZe commented Jan 22, 2018

Thanks a lot for your really helpful issue, I'll try to be clear about what I've done and how to get what you want.

  1. First lines of justified paragraphs with text-indent were broken (unrelated to your reported issue). It's been fixed by 13bba98.

  2. Headers were broken when boxes with defined page attribute were broken inside top-level children. It's been fixed by 4ceb8c9. It's actually the contrary of what's reported: with given CSS, the right behavior is when the header is not drawn.

  3. If you use page: chapter on div.chapter, you'll get chapter pages everywhere there's a chapter content. What you want is to have headers everywhere, except when there's a chapter title. Here's the diff to get what you want:

@@ -73,8 +81,7 @@
   page-break-before: right; }
 
 div.chapter, div.appendix {
-  padding-top: 10rem;
-  page: chapter; }
+  padding-top: 10rem; }
   div.chapter p, div.appendix p {
     text-indent: 1cm;
     padding: 0;
@@ -94,6 +101,7 @@
   font-size: 1.5em; }
 
 h1 {
+  page: chapter;
   text-align: center; }
   h1.element-title {
     padding-bottom: 10rem; }

You can also remove headers and footers from empty pages:

@@ -53,6 +53,14 @@
   @top-left {
     content: ""; } }
 
+@page :blank {
+  @bottom-center {
+    content: ""; }
+  @top-right {
+    content: ""; }
+  @top-left {
+    content: ""; } }
+
 body {
   hyphens: manual; }

I hope that it'll be helpful. Have fun with WeasyPrint!

@Tontyna

This comment has been minimized.

Contributor

Tontyna commented Jan 23, 2018

Yes, that's what I thought: There shouldn't have been headers at all.

@liZe added #562 'named pages with pseudo-class' to the 43 milestone.
Then the following css will produce the desired result:

@page :left {
   @top-left {
     content: "..."; } }
}
@page :right {
   @top-right {
     content: "..."; } }
}
@page chapter:first {
   @top-right {
    content: ""; }
   @top-left {
     content: ""; } }
}
@dmoonfire

This comment has been minimized.

dmoonfire commented Mar 17, 2018

I just had a chance to integrate the code into my mfgames-writing-js and it worked beautifully (though there were some differences in how I implemented the page breaks).

Between this and the inability to reset page numbers, I ended up having to generate 3 PDFs for every chapter in my novels with the previous implementation.

  • One using the previous page style to get the right number of pages.
  • One to render the first page of a chapter.
  • One to render the rest of the chapter.

Then I combined everything the two previous ones together. page1 + pageN. The combine those to the previous chapters to build up the document part-by-part. (So 3N PDFS where N is the number of chapters.)

With the changes for this, I got it down to 2. Not 2N, 2. That also made the builds 6x faster for my latest published novel.

Thank you, this has been very helpful and I appreciate all the help you put into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment