diff --git a/CHANGELOG.md b/CHANGELOG.md index a49e3740..e915bc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,8 @@ - 한/글은 공백과 머리표·번호도 글로 본다. 그 줄을 개체 아래에 전체 폭으로 두고, 다음 문단은 그 줄 아래에 둔다. - 공백도 머리도 없을 때만 줄을 개체 윗선에 폭 0으로 둔다. - 공백은 본문과 표 칸 모두, 머리표·번호는 본문에서 따른다. + - 공백만 있는 한 줄 문단의 표가 그 자리에서 시작하지 못하면 표 혼자인 문단처럼 놓는다. 표는 다음 쪽 맨 + 위에서 시작하고, 문단 줄은 제자리에 남으며, 뒤 글은 그 줄 아래에 이어진다. 나누지 않게 둔 표도 같다. - 쪽 수 추정(실험, `estimate_pages`)이 줄 캐시 없는 표 칸에서 위아래 배치 표 하나가 든 문단을 지원 밖 (`a nested table`)으로 두던 것을 고친다. 이제 그림·도형처럼 칸이 그 표의 아래 끝(행으로 잰 표 높이와 바깥 여백)까지 닿고, 칸의 다음 줄은 그 아래에서 이어진다. 위로 띄운 표는 문단 윗선에 선다. 그런 행이 쪽을 넘어 줄 사이에서 diff --git a/src/hwpx/layout/pages.py b/src/hwpx/layout/pages.py index b478abe9..d6a71960 100644 --- a/src/hwpx/layout/pages.py +++ b/src/hwpx/layout/pages.py @@ -1108,6 +1108,9 @@ class _Para: hides: bool = False #: its lines are Hancom's own, from the paragraph's valid layout cache kept: bool = False + #: an object anchored in this paragraph holding nothing else but spaces on one line: a table of it starting + #: on the next page goes there as when the paragraph holds it alone, the paragraph's line staying + spaced: bool = False #: the top-and-bottom objects stacked in this paragraph, which holds nothing else (see :func:`_stack`) stack: tuple[_Stacked, ...] = () #: a square-wrapped object anchored here and flowing with the text went past the body's foot: Hancom sets @@ -1905,6 +1908,8 @@ def _paragraph(measure: _Measure, page: _Page, paragraph: Any, wrap: _Wrap | Non paragraph.get("pageBreak") == "1", paragraph.get("columnBreak") == "1", table, notes, cached, anchor, wrap_anchor=around, hides=page.hide_empty and _holds_nothing(runs)) + if anchored is not None and text and not text.strip(" ") and para.lines == 1: + para = replace(para, spaced=True) if reflow and text: again = _Reflow(measure, text, tuple(sizes), None if looks is None else tuple(looks), style, shape) return again.at(para, page.column_width, 0) @@ -2779,6 +2784,9 @@ def _anchored(self, index: int, paras: list[_Para], para: _Para, start: int) -> if anchor.table is not None: table = anchor.table later = _starts_later(table, top + table.above, self.body) + if later and para.spaced and not head.lines: # spaces only: as the table alone in its paragraph + self._flow(replace(para, anchor=None, table=table), table, start) + return if table.mode == "NONE" and not head.lines and top != self.reserved.get(self.frame, 0) + para.prev \ and (later or top + table.above + sum(row.height for row in table.rows) + table.below + tail.height(0) > self.body): # set not to split: it goes on with the line below it diff --git a/tests/fixtures/hancom_saved/pages_table_not_split_then_a_space_starting_on_the_next_page.hwpx b/tests/fixtures/hancom_saved/pages_table_not_split_then_a_space_starting_on_the_next_page.hwpx new file mode 100644 index 00000000..7ce672d4 Binary files /dev/null and b/tests/fixtures/hancom_saved/pages_table_not_split_then_a_space_starting_on_the_next_page.hwpx differ diff --git a/tests/fixtures/hancom_saved/pages_table_then_a_space_starting_on_the_next_page.hwpx b/tests/fixtures/hancom_saved/pages_table_then_a_space_starting_on_the_next_page.hwpx new file mode 100644 index 00000000..7ca6d0de Binary files /dev/null and b/tests/fixtures/hancom_saved/pages_table_then_a_space_starting_on_the_next_page.hwpx differ diff --git a/tests/fixtures/hancom_saved/pages_table_then_nothing_starting_on_the_next_page.hwpx b/tests/fixtures/hancom_saved/pages_table_then_nothing_starting_on_the_next_page.hwpx new file mode 100644 index 00000000..6d9e86c3 Binary files /dev/null and b/tests/fixtures/hancom_saved/pages_table_then_nothing_starting_on_the_next_page.hwpx differ diff --git a/tests/test_layout_page_estimate.py b/tests/test_layout_page_estimate.py index e4790a4c..89be9b11 100644 --- a/tests/test_layout_page_estimate.py +++ b/tests/test_layout_page_estimate.py @@ -182,6 +182,12 @@ "pages_picture_alone_in_a_bulleted_paragraph": 1, # a bullet is text: the line under the picture "pages_picture_alone_in_a_numbered_paragraph": 1, # so is a number "pages_table_alone_in_a_bulleted_paragraph": 1, + # The same 60762 down (10 pt text spaced 160%), the table (rows 8000, 1282 and 1282 tall) not starting + # there: it starts at the next page's top, the paragraph's line staying, a space after the table or not, + # and the text after goes on under that line. + "pages_table_then_nothing_starting_on_the_next_page": 2, + "pages_table_then_a_space_starting_on_the_next_page": 2, + "pages_table_not_split_then_a_space_starting_on_the_next_page": 2, # set not to split: the same # A cell of a flowing table, a picture 20000 x 10000 placed top and bottom from a paragraph of it: "pages_table_cell_picture_first": 1, # alone in the first: the line on its top, the row as tall as it "pages_table_cell_picture_second": 1, # alone in the second, after a line: from that paragraph's top