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

- Мелкие исправления увеличивающие работу конвертера
This commit is contained in:
Igor20264
2026-09-10 10:50:15 +03:00
parent 658036f920
commit f7136bd8bd
95 changed files with 7165 additions and 8771 deletions
+9 -17
View File
@@ -139,8 +139,6 @@ class Table(Renderable, RequiresNumbering):
def _peek_row_height(self, row_idx: int, layout_state: LayoutState) -> Length:
"""Estimate row height without attaching cell paragraphs to a table."""
from .paragraph_sizer import ParagraphSizer
row = self._rows[row_idx]
merge_row = self._merge[row_idx]
row_height = 0
@@ -158,9 +156,9 @@ class Table(Renderable, RequiresNumbering):
if merge_v != "continue":
max_w = col_w * span - CELL_OFFSET
for paragraph in row[col]:
cell_height += ParagraphSizer(
paragraph._docx_paragraph, None, max_w
).calculate_height().full
# Same measurement _build_docx_row() needs later, so the
# cell paragraph is sized once per row width.
cell_height += paragraph.measure(None, max_w).full
row_height = max(cell_height, row_height)
col += span
row_height += Pt(0.5) + (
@@ -169,24 +167,18 @@ class Table(Renderable, RequiresNumbering):
return row_height
def _start_block_height(
self, previous_rendered: RenderedInfo | None, layout_state: LayoutState
self, caption: Caption, previous_rendered: RenderedInfo | None,
layout_state: LayoutState
) -> Length:
"""Caption + header + first data row (method: no orphan title/header)."""
from docx.text.paragraph import Paragraph as DocxParagraph
from .paragraph_sizer import ParagraphSizer
# Dry-run caption sizing (temporary Caption; not yielded into the body).
cap = Caption(
self._parent, "Таблица", self._caption_info, self._number, True
)
prev_p = (
previous_rendered.docx_element
if previous_rendered and isinstance(previous_rendered.docx_element, DocxParagraph)
else None
)
total = ParagraphSizer(
cap._docx_paragraph, prev_p, layout_state.max_width
).calculate_height().full
total = caption.measure(prev_p, layout_state.max_width).full
if self._rows:
total += self._peek_row_height(0, layout_state)
if len(self._rows) > 1:
@@ -234,7 +226,8 @@ class Table(Renderable, RequiresNumbering):
# not fit, push the whole block to the next page (layout leftover;
# Word also gets keep_with_next on caption/header).
leftover = Pt(0)
start_h = self._start_block_height(previous_rendered, layout_state)
caption = Caption(self._parent, "Таблица", self._caption_info, self._number, True)
start_h = self._start_block_height(caption, previous_rendered, layout_state)
if (
layout_state.current_page_height > 0
and start_h > layout_state.remaining_page_height
@@ -244,8 +237,7 @@ class Table(Renderable, RequiresNumbering):
previous_rendered = None
caption_rendered_infos = list(
Caption(self._parent, "Таблица", self._caption_info, self._number, True)
.render(previous_rendered, copy(layout_state))
caption.render(previous_rendered, copy(layout_state))
)
if leftover and caption_rendered_infos:
first = caption_rendered_infos[0]