v0.6.0 BigUpdate
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled

This commit is contained in:
Igor20264
2026-10-20 11:38:06 +03:00
parent daa84f8bce
commit 8223e0ac14
77 changed files with 12158 additions and 117 deletions
+34
View File
@@ -56,6 +56,10 @@ class Renderer:
self._after_toc = False
self._body_section_started = False
self._landscape_depth = 0
# Exit from landscape is delayed so the next +landscape table/figure
# stays in the same section. Closing and reopening here is two
# next-page breaks with nothing between them: a blank portrait page.
self._portrait_return_pending = False
max_height, max_width = content_size(landscape=False)
self._layout_tracker = LayoutTracker(max_height, max_width)
@@ -87,6 +91,11 @@ class Renderer:
apply_centered_page_footer(new_section)
def _enter_landscape(self) -> None:
if self._portrait_return_pending:
# Previous block already left us in the landscape section.
self._portrait_return_pending = False
self._landscape_depth += 1
return
if self._landscape_depth > 0:
self._landscape_depth += 1
return
@@ -109,12 +118,34 @@ class Renderer:
self._landscape_depth -= 1
if self._landscape_depth > 0:
return
self._portrait_return_pending = True
def _commit_portrait_return(self) -> None:
"""Close the landscape section once the next block is portrait content."""
if not self._portrait_return_pending:
return
self._portrait_return_pending = False
section = self._document.add_section(WD_SECTION.NEW_PAGE)
apply_section_geometry(section, landscape=False)
apply_centered_page_footer(section)
max_height, max_width = content_size(landscape=False)
self._layout_tracker.set_page_size(max_height, max_width)
@staticmethod
def _hosts_only_landscape_figures(renderable: Renderable) -> bool:
"""Paragraph whose only content is +landscape figures.
The paragraph itself is not marked landscape; the figure opens the
section. Returning to portrait before that figure inserts a blank page
between two photos in a row.
"""
images = getattr(renderable, "_images", None)
if not images or not all(getattr(img, "landscape", False) for img in images):
return False
paragraph = getattr(renderable, "_docx_paragraph", None)
text = (paragraph.text or "").strip() if paragraph is not None else ""
return text == ""
def process(self, renderables: list[Renderable]):
items = self._ensure_appendix_index(list(renderables))
for i in range(len(items)):
@@ -124,6 +155,7 @@ class Renderer:
self.render(items[i])
self._flush_to_new_screen()
self._commit_portrait_return()
# If document had no TOC, still add page numbers to the only section
if not self._body_section_started:
section = self._document.sections[0]
@@ -316,6 +348,8 @@ class Renderer:
if wants_landscape:
self._enter_landscape()
elif not self._hosts_only_landscape_figures(renderable):
self._commit_portrait_return()
try:
if not self._skip_numbering and isinstance(renderable, RequiresNumbering):