v0.5.3
- Мелкие исправления увеличивающие работу конвертера
This commit is contained in:
@@ -9,7 +9,7 @@ from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
||||
from md2gost.layout_tracker import LayoutState
|
||||
from md2gost.renderable import Renderable
|
||||
from md2gost.rendered_info import RenderedInfo
|
||||
from .paragraph_sizer import ParagraphSizer
|
||||
from .paragraph_sizer import ParagraphSizerResult, measure_paragraph
|
||||
from ..util import create_element
|
||||
|
||||
|
||||
@@ -35,8 +35,16 @@ class Caption(Renderable):
|
||||
self._parent = parent
|
||||
self._before = before
|
||||
self._category = category
|
||||
self._size_cache: dict = {}
|
||||
self._docx_paragraph = DocxParagraph(create_element("w:p"), parent)
|
||||
|
||||
# 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. Written here
|
||||
# rather than at the end of render() so that measuring the caption twice
|
||||
# (fit check, then emit) sees the same paragraph.
|
||||
self._docx_paragraph.paragraph_format.page_break_before = False
|
||||
|
||||
style_name = CAPTION_STYLES.get(category, "Caption")
|
||||
try:
|
||||
self._docx_paragraph.style = style_name
|
||||
@@ -58,18 +66,20 @@ class Caption(Renderable):
|
||||
def center(self):
|
||||
self._docx_paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
||||
|
||||
def measure(self, previous_paragraph: DocxParagraph | None, max_width) -> ParagraphSizerResult:
|
||||
"""Line count and spacing of the caption line against a given predecessor."""
|
||||
return measure_paragraph(
|
||||
self._size_cache, self._docx_paragraph, previous_paragraph, max_width
|
||||
)
|
||||
|
||||
def render(self, previous_rendered: RenderedInfo, layout_state: LayoutState) -> Generator[
|
||||
"RenderedInfo | Renderable", None, None]:
|
||||
height_data = ParagraphSizer(
|
||||
self._docx_paragraph,
|
||||
height_data = self.measure(
|
||||
previous_rendered.docx_element
|
||||
if previous_rendered and isinstance(previous_rendered.docx_element, DocxParagraph) else None,
|
||||
layout_state.max_width
|
||||
).calculate_height()
|
||||
)
|
||||
|
||||
# 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
|
||||
@@ -79,11 +89,6 @@ class Caption(Renderable):
|
||||
)
|
||||
if need_new_page:
|
||||
leftover = layout_state.remaining_page_height
|
||||
height_data = ParagraphSizer(
|
||||
self._docx_paragraph,
|
||||
None,
|
||||
layout_state.max_width
|
||||
).calculate_height()
|
||||
height_data = self.measure(None, layout_state.max_width)
|
||||
|
||||
self._docx_paragraph.paragraph_format.page_break_before = False
|
||||
yield RenderedInfo(self._docx_paragraph, height_data.full + leftover)
|
||||
|
||||
Reference in New Issue
Block a user