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 510f7e7adf
commit e6b58efeb3
95 changed files with 7165 additions and 8771 deletions
+13 -6
View File
@@ -9,7 +9,7 @@ from docx.opc.constants import RELATIONSHIP_TYPE
from . import Renderable
from .caption import CaptionInfo
from .image import Image
from .paragraph_sizer import ParagraphSizer
from .paragraph_sizer import ParagraphSizerResult, measure_paragraph
from ..layout_tracker import LayoutState
from ..sub_renderable import SubRenderable
from ..util import create_element
@@ -41,7 +41,7 @@ class Link:
for i, part in enumerate(parts):
docx_run = DocxRun(create_element("w:r"), self._docx_paragraph)
self._hyperlink.append(docx_run._element)
docx_run.text = text
docx_run.text = part
docx_run.style = "Hyperlink"
docx_run.bold = is_bold
docx_run.italic = is_italic
@@ -95,6 +95,7 @@ class Paragraph(Renderable):
self._docx_paragraph.style = "Normal"
self._images: list[Image] = []
self._pending_refs: list[tuple[object, str, str]] = [] # (run, type, name)
self._size_cache: dict = {}
def add_run(self, text: str, is_bold: bool = None, is_italic: bool = None, color: RGBColor = None,
strike_through: bool = None):
@@ -231,6 +232,13 @@ class Paragraph(Renderable):
def first_line_indent(self, value: Length):
self._docx_paragraph.paragraph_format.first_line_indent = value
def measure(self, previous_paragraph: DocxParagraph | None,
max_width: Length) -> ParagraphSizerResult:
"""Line count and spacing of this paragraph 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 | SubRenderable, None, None]:
remaining_space = layout_state.remaining_page_height
@@ -238,11 +246,10 @@ class Paragraph(Renderable):
if self.page_break_before:
layout_state.add_height(layout_state.remaining_page_height)
if self._docx_paragraph.text or not self._images:
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()
if previous_rendered and isinstance(previous_rendered.docx_element, DocxParagraph) else None,
layout_state.max_width)
if layout_state.current_page_height == 0 and layout_state.page > 1:
height_data.before = 0