Skip to content

Fixing the styling issues of the empty pages caused by pagebreak#2182

Merged
laurmaedje merged 8 commits intotypst:mainfrom
LuxxxLucy:lucy-fix-pagebreak-style-br
Sep 25, 2023
Merged

Fixing the styling issues of the empty pages caused by pagebreak#2182
laurmaedje merged 8 commits intotypst:mainfrom
LuxxxLucy:lucy-fix-pagebreak-style-br

Conversation

@LuxxxLucy
Copy link
Contributor

@LuxxxLucy LuxxxLucy commented Sep 18, 2023

Updated Sep 23

Revise the modification according as suggested, now the logic is a little bit deep, but now we get rid of the mutable reference.

The two newly added tests are functioning the same, as expected.

Old

Caveat: Added an API to get mutable reference

This is solving two related issues #2095 and #2162. Tests for both issues are appended.

The problems of the styles of pagebreaks stem from the fact that when we scan the following command

  1. something A
  2. a pagebreak(odd)
  3. something B

The layout engine would simply scan A, and when it scans the pagebreak, it stores a local flag clear_next (in layout/mod.rs (docbuilder) and only notify the next page that, when it layout B it needs to insert a new page before B. However, problem arises when A and B uses different styles, the empty page would follow the style of the next page. Which is against intuition that the style of the empty page should be identical to previous page.

Essentially, the first way to solve this problem is to introduce the pagebreak in the parsing and then look one step ahead; but that does not seem possible to add pagebreak as a syntax kind. Rather, we would do it when we parse into contents.

In order to do that, we first introduce a function API to access the last page, and we set a flag to notify the page to create an empty page after it. Note that there is a special case that someone would do a pagebreak first and then start the first page, to handle this special case, we add an extra routine to prepend an emtpy page.

@laurmaedje
Copy link
Member

Since PageElem::layout is only called in DocumentElem::layout I think it might be simpler to handle this there. Basically for page elem n pass it page elem n+1's clear_to configuration. That way, we don't need any of the mutation logic.

@LuxxxLucy
Copy link
Contributor Author

Since PageElem::layout is only called in DocumentElem::layout I think it might be simpler to handle this there. Basically for page elem n pass it page elem n+1's clear_to configuration. That way, we don't need any of the mutation logic.

Updated with a revised approach that get rid of the get mut reference.

@laurmaedje laurmaedje merged commit 079ccd5 into typst:main Sep 25, 2023
@laurmaedje
Copy link
Member

Thanks! I've pushed a minor revision to not require an extra field on PageElem.

@LuxxxLucy
Copy link
Contributor Author

Thanks! I've pushed a minor revision to not require an extra field on PageElem.

Great! Thank you! It is much more neat solution. I am still transfering from C and not quite familiar to the option handling conventions of Rust.

BTW, should we be able to close the two issues #2162 and #2095 since this is merged?

@laurmaedje
Copy link
Member

BTW, should we be able to close the two issues #2162 and #2095 since this is merged?

Done!

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

Successfully merging this pull request may close these issues.

2 participants