- fix Не появляется пустая странициа перед названием таблицы - fix Не появляется пустая страница перед альбомной ориентацией - fix При отказе от изменений создаётся новый файл - fix Замена "..." на «...» больше не затрагивает uml и mermaid блоки
This commit is contained in:
@@ -67,14 +67,23 @@ class Caption(Renderable):
|
||||
layout_state.max_width
|
||||
).calculate_height()
|
||||
|
||||
if self._before and ((height_data.lines + 2 - 1) * height_data.line_spacing + 1) * height_data.line_height \
|
||||
> layout_state.remaining_page_height:
|
||||
self._docx_paragraph.paragraph_format.page_break_before = True
|
||||
# Table/listing captions use keep_with_next. pageBreakBefore + keepWithNext
|
||||
# on a paragraph that Word already wraps to a new page produces a blank
|
||||
# page that the layout tracker / debug overlay never sees.
|
||||
leftover = 0
|
||||
need_new_page = (
|
||||
self._before
|
||||
and layout_state.current_page_height > 0
|
||||
and ((height_data.lines + 2 - 1) * height_data.line_spacing + 1) * height_data.line_height
|
||||
> layout_state.remaining_page_height
|
||||
)
|
||||
if need_new_page:
|
||||
leftover = layout_state.remaining_page_height
|
||||
height_data = ParagraphSizer(
|
||||
self._docx_paragraph,
|
||||
None,
|
||||
layout_state.max_width
|
||||
).calculate_height()
|
||||
|
||||
yield RenderedInfo(self._docx_paragraph, height_data.full + (layout_state.remaining_page_height
|
||||
if self._docx_paragraph.paragraph_format.page_break_before else 0))
|
||||
self._docx_paragraph.paragraph_format.page_break_before = False
|
||||
yield RenderedInfo(self._docx_paragraph, height_data.full + leftover)
|
||||
|
||||
@@ -123,21 +123,13 @@ class Listing(Renderable, RequiresNumbering):
|
||||
def _emit_page_break_and_optional_caption(
|
||||
self, layout_state: LayoutState
|
||||
) -> Generator[RenderedInfo, None, None]:
|
||||
mode = self._continuation_mode
|
||||
if mode == "legacy":
|
||||
continuation_paragraph = self._make_continuation_paragraph()
|
||||
continuation_paragraph.page_break_before = True
|
||||
info = next(continuation_paragraph.render(None, copy(layout_state)))
|
||||
layout_state.add_height(info.height)
|
||||
yield info
|
||||
return
|
||||
|
||||
page_break_info = next(PageBreak(self._parent).render(None, layout_state))
|
||||
layout_state.add_height(page_break_info.height)
|
||||
yield page_break_info
|
||||
|
||||
continuation_paragraph = self._make_continuation_paragraph()
|
||||
continuation_paragraph._docx_paragraph.paragraph_format.keep_with_next = True
|
||||
continuation_paragraph._docx_paragraph.paragraph_format.page_break_before = False
|
||||
info = next(continuation_paragraph.render(None, copy(layout_state)))
|
||||
layout_state.add_height(info.height)
|
||||
yield info
|
||||
|
||||
@@ -154,23 +154,15 @@ class Table(Renderable, RequiresNumbering):
|
||||
self, layout_state: LayoutState
|
||||
) -> Generator[RenderedInfo, None, None]:
|
||||
"""For legacy/caption only: break page and insert «Продолжение Таблицы N»."""
|
||||
mode = self._continuation_mode
|
||||
|
||||
if mode == "legacy":
|
||||
continuation_paragraph = self._make_continuation_paragraph()
|
||||
continuation_paragraph.page_break_before = True
|
||||
info = next(continuation_paragraph.render(None, copy(layout_state)))
|
||||
layout_state.add_height(info.height)
|
||||
yield info
|
||||
return
|
||||
|
||||
# caption
|
||||
page_break_info = next(PageBreak(self._parent).render(None, layout_state))
|
||||
layout_state.add_height(page_break_info.height)
|
||||
yield page_break_info
|
||||
|
||||
# Never page_break_before on «Название таблицы»: keep_with_next +
|
||||
# pageBreakBefore makes a blank page that debug does not count.
|
||||
continuation_paragraph = self._make_continuation_paragraph()
|
||||
continuation_paragraph._docx_paragraph.paragraph_format.keep_with_next = True
|
||||
continuation_paragraph._docx_paragraph.paragraph_format.page_break_before = False
|
||||
info = next(continuation_paragraph.render(None, copy(layout_state)))
|
||||
layout_state.add_height(info.height)
|
||||
yield info
|
||||
|
||||
@@ -7,7 +7,6 @@ from docx.enum.text import WD_TAB_LEADER, WD_TAB_ALIGNMENT, WD_PARAGRAPH_ALIGNME
|
||||
from docx.shared import Parented
|
||||
|
||||
from . import Paragraph
|
||||
from .page_break import PageBreak
|
||||
from .renderable import Renderable
|
||||
from ..layout_tracker import LayoutState
|
||||
from ..rendered_info import RenderedInfo
|
||||
@@ -142,4 +141,5 @@ class ToC(Renderable):
|
||||
|
||||
for rendered_info in self._paragraph.render(previous_rendered, copy(layout_state)):
|
||||
yield RenderedInfo(rendered_info.docx_element, 0)
|
||||
yield from PageBreak(self._parent).render(None, copy(layout_state))
|
||||
# Page break after TOC is a section break in Renderer (body + PAGE).
|
||||
# An extra w:br here + NEW_PAGE section = blank portrait page.
|
||||
|
||||
Reference in New Issue
Block a user