@@ -16,6 +16,14 @@ from md2gost.renderable.caption import CaptionInfo
|
||||
from md2gost.renderable.image import Image
|
||||
from md2gost.renderable.table import Table
|
||||
from md2gost.renderer import Renderer
|
||||
from docx.oxml.ns import qn
|
||||
|
||||
|
||||
def _section_page_start(section):
|
||||
pg = section._sectPr.find(qn("w:pgNumType"))
|
||||
if pg is None:
|
||||
return None
|
||||
return pg.get(qn("w:start"))
|
||||
|
||||
|
||||
def test_content_size_landscape_wider():
|
||||
@@ -57,6 +65,50 @@ def test_renderer_landscape_section_for_table():
|
||||
assert doc.sections[-1].orientation == WD_ORIENT.PORTRAIT
|
||||
assert int(doc.sections[-1].page_width) < int(doc.sections[-1].page_height)
|
||||
|
||||
# Landscape and return-to-portrait must not restart PAGE (no w:start).
|
||||
for section in land2:
|
||||
assert _section_page_start(section) is None
|
||||
assert _section_page_start(doc.sections[-1]) is None
|
||||
|
||||
|
||||
def test_landscape_sections_have_no_page_restart():
|
||||
"""+landscape must not leave w:pgNumType/@w:start on album / following portrait."""
|
||||
doc = Document(os.path.join(package_dir(), "Template.docx"))
|
||||
body = doc._body._element
|
||||
for child in list(body):
|
||||
if child.tag.endswith("}sectPr"):
|
||||
continue
|
||||
body.remove(child)
|
||||
|
||||
from md2gost.renderable.heading import Heading
|
||||
from md2gost.renderable.paragraph import Paragraph
|
||||
from md2gost.renderable.toc import ToC
|
||||
|
||||
h = Heading(doc._body, 1, False)
|
||||
h.add_run("СОДЕРЖАНИЕ")
|
||||
toc = ToC(doc._body, toc_mode="native")
|
||||
para = Paragraph(doc._body)
|
||||
para.add_run("Текст перед широкой таблицей.")
|
||||
table = Table(doc._body, 2, 3, CaptionInfo("wide", "Карта", landscape=True))
|
||||
for r in range(2):
|
||||
for c in range(3):
|
||||
table.add_paragraph_to_cell(r, c).add_run(f"{r}{c}")
|
||||
after = Paragraph(doc._body)
|
||||
after.add_run("Текст после альбома.")
|
||||
|
||||
Renderer(doc, skip_numbering=True).process([h, toc, para, table, after])
|
||||
|
||||
land = [s for s in doc.sections if s.orientation == WD_ORIENT.LANDSCAPE]
|
||||
assert land
|
||||
for section in land:
|
||||
assert _section_page_start(section) is None, "landscape restarted PAGE"
|
||||
# Body portrait after landscape also continuous.
|
||||
assert doc.sections[-1].orientation == WD_ORIENT.PORTRAIT
|
||||
assert _section_page_start(doc.sections[-1]) is None
|
||||
# Non-first sections must not restart (first may still carry template start).
|
||||
for section in list(doc.sections)[1:]:
|
||||
assert _section_page_start(section) is None
|
||||
|
||||
|
||||
def test_parser_propagates_landscape_to_table():
|
||||
doc = Document(os.path.join(package_dir(), "Template.docx"))
|
||||
|
||||
Reference in New Issue
Block a user