python-hwpx 1.4__tar.gz → 1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python-hwpx-1.4/src/python_hwpx.egg-info → python-hwpx-1.5}/PKG-INFO +5 -2
- {python-hwpx-1.4 → python-hwpx-1.5}/README.md +4 -1
- {python-hwpx-1.4 → python-hwpx-1.5}/pyproject.toml +1 -1
- python-hwpx-1.5/src/hwpx/data/Skeleton.hwpx +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/document.py +18 -2
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/document.py +194 -3
- {python-hwpx-1.4 → python-hwpx-1.5/src/python_hwpx.egg-info}/PKG-INFO +5 -2
- {python-hwpx-1.4 → python-hwpx-1.5}/src/python_hwpx.egg-info/SOURCES.txt +1 -0
- python-hwpx-1.5/tests/test_tables_default_border.py +81 -0
- python-hwpx-1.4/src/hwpx/data/Skeleton.hwpx +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/LICENSE +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/setup.cfg +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/__init__.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/opc/package.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/__init__.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/body.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/common.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/header.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/parser.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/schema.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/oxml/utils.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/package.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/templates.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/__init__.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/_schemas/header.xsd +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/_schemas/section.xsd +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/object_finder.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/text_extractor.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/hwpx/tools/validator.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/python_hwpx.egg-info/dependency_links.txt +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/python_hwpx.egg-info/entry_points.txt +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/python_hwpx.egg-info/requires.txt +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/src/python_hwpx.egg-info/top_level.txt +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_document_formatting.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_inline_models.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_integration_hwpx_compatibility.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_memo_and_style_editing.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_oxml_parsing.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_section_headers.py +0 -0
- {python-hwpx-1.4 → python-hwpx-1.5}/tests/test_text_extractor_annotations.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-hwpx
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5
|
|
4
4
|
Summary: Hancom HWPX 패키지를 로드하고 편집하기 위한 Python 유틸리티 모음
|
|
5
5
|
Author: python-hwpx Maintainers
|
|
6
6
|
License: Non-Commercial License
|
|
@@ -38,7 +38,7 @@ Requires-Dist: pytest>=7.4; extra == "test"
|
|
|
38
38
|
- **문서 편집 API** – `hwpx.document.HwpxDocument`는 문단과 표, 메모, 헤더 속성을 파이썬 객체로 노출하고 새 콘텐츠를 손쉽게 추가합니다. 섹션 머리말·꼬리말을 수정하면 `<hp:headerApply>`/`<hp:footerApply>`와 마스터 페이지 링크도 함께 갱신합니다.
|
|
39
39
|
- **타입이 지정된 본문 모델** – `hwpx.oxml.body`는 표·컨트롤·인라인 도형·변경 추적 태그를 데이터 클래스에 매핑하고, `HwpxOxmlParagraph.model`/`HwpxOxmlRun.model`로 이를 조회·수정한 뒤 XML로 되돌릴 수 있도록 지원합니다.
|
|
40
40
|
- **메모와 필드 앵커** – `add_memo_with_anchor()`로 메모를 생성하면서 MEMO 필드 컨트롤을 자동 삽입해 한/글에서 바로 표시되도록 합니다.
|
|
41
|
-
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
41
|
+
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 테두리 채우기, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.border_fills`·`document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
42
42
|
- **바탕쪽·이력·버전 파트 제어** – 매니페스트에 포함된 master-page/history/version 파트를 `document.master_pages`, `document.histories`, `document.version`으로 직접 편집하고 저장합니다.
|
|
43
43
|
- **스타일 기반 텍스트 치환** – 런 서식(색상, 밑줄, `charPrIDRef`)으로 필터링해 텍스트를 선택적으로 교체하거나 삭제합니다. 하이라이트
|
|
44
44
|
마커나 태그로 분리된 문자열도 서식을 유지한 채 치환합니다.
|
|
@@ -79,6 +79,7 @@ print("sections:", len(document.sections))
|
|
|
79
79
|
# 2) 문단과 표, 메모 추가
|
|
80
80
|
section = document.sections[0]
|
|
81
81
|
paragraph = document.add_paragraph("자동 생성한 문단", section=section)
|
|
82
|
+
# 표에 사용할 기본 실선 테두리 채우기가 없으면 add_table()이 자동으로 생성합니다.
|
|
82
83
|
table = document.add_table(rows=2, cols=2, section=section)
|
|
83
84
|
table.set_cell_text(0, 0, "항목")
|
|
84
85
|
table.set_cell_text(0, 1, "값")
|
|
@@ -90,6 +91,8 @@ document.add_memo_with_anchor("배포 전 검토", paragraph=paragraph, memo_sha
|
|
|
90
91
|
document.save("output/example.hwpx")
|
|
91
92
|
```
|
|
92
93
|
|
|
94
|
+
`HwpxDocument.add_table()`은 문서에 정의된 테두리 채우기가 없으면 헤더 참조 목록에 "기본 실선" `borderFill`을 만들어 표와 모든 셀에 참조를 연결합니다.
|
|
95
|
+
|
|
93
96
|
더 많은 실전 패턴은 [빠른 시작](docs/quickstart.md)과 [사용 가이드](docs/usage.md)의 "빠른 예제 모음"에서 확인할 수 있습니다.
|
|
94
97
|
|
|
95
98
|
## 문서
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
- **문서 편집 API** – `hwpx.document.HwpxDocument`는 문단과 표, 메모, 헤더 속성을 파이썬 객체로 노출하고 새 콘텐츠를 손쉽게 추가합니다. 섹션 머리말·꼬리말을 수정하면 `<hp:headerApply>`/`<hp:footerApply>`와 마스터 페이지 링크도 함께 갱신합니다.
|
|
9
9
|
- **타입이 지정된 본문 모델** – `hwpx.oxml.body`는 표·컨트롤·인라인 도형·변경 추적 태그를 데이터 클래스에 매핑하고, `HwpxOxmlParagraph.model`/`HwpxOxmlRun.model`로 이를 조회·수정한 뒤 XML로 되돌릴 수 있도록 지원합니다.
|
|
10
10
|
- **메모와 필드 앵커** – `add_memo_with_anchor()`로 메모를 생성하면서 MEMO 필드 컨트롤을 자동 삽입해 한/글에서 바로 표시되도록 합니다.
|
|
11
|
-
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
11
|
+
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 테두리 채우기, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.border_fills`·`document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
12
12
|
- **바탕쪽·이력·버전 파트 제어** – 매니페스트에 포함된 master-page/history/version 파트를 `document.master_pages`, `document.histories`, `document.version`으로 직접 편집하고 저장합니다.
|
|
13
13
|
- **스타일 기반 텍스트 치환** – 런 서식(색상, 밑줄, `charPrIDRef`)으로 필터링해 텍스트를 선택적으로 교체하거나 삭제합니다. 하이라이트
|
|
14
14
|
마커나 태그로 분리된 문자열도 서식을 유지한 채 치환합니다.
|
|
@@ -49,6 +49,7 @@ print("sections:", len(document.sections))
|
|
|
49
49
|
# 2) 문단과 표, 메모 추가
|
|
50
50
|
section = document.sections[0]
|
|
51
51
|
paragraph = document.add_paragraph("자동 생성한 문단", section=section)
|
|
52
|
+
# 표에 사용할 기본 실선 테두리 채우기가 없으면 add_table()이 자동으로 생성합니다.
|
|
52
53
|
table = document.add_table(rows=2, cols=2, section=section)
|
|
53
54
|
table.set_cell_text(0, 0, "항목")
|
|
54
55
|
table.set_cell_text(0, 1, "값")
|
|
@@ -60,6 +61,8 @@ document.add_memo_with_anchor("배포 전 검토", paragraph=paragraph, memo_sha
|
|
|
60
61
|
document.save("output/example.hwpx")
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
`HwpxDocument.add_table()`은 문서에 정의된 테두리 채우기가 없으면 헤더 참조 목록에 "기본 실선" `borderFill`을 만들어 표와 모든 셀에 참조를 연결합니다.
|
|
65
|
+
|
|
63
66
|
더 많은 실전 패턴은 [빠른 시작](docs/quickstart.md)과 [사용 가이드](docs/usage.md)의 "빠른 예제 모음"에서 확인할 수 있습니다.
|
|
64
67
|
|
|
65
68
|
## 문서
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-hwpx"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.5"
|
|
8
8
|
description = "Hancom HWPX 패키지를 로드하고 편집하기 위한 Python 유틸리티 모음"
|
|
9
9
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
10
|
license = { text = "Non-Commercial License" }
|
|
Binary file
|
|
@@ -11,6 +11,7 @@ from typing import BinaryIO, Iterator, List, Tuple
|
|
|
11
11
|
|
|
12
12
|
from .oxml import (
|
|
13
13
|
Bullet,
|
|
14
|
+
GenericElement,
|
|
14
15
|
HwpxOxmlDocument,
|
|
15
16
|
HwpxOxmlHeader,
|
|
16
17
|
HwpxOxmlHistory,
|
|
@@ -107,6 +108,17 @@ class HwpxDocument:
|
|
|
107
108
|
"""Return the version metadata part if present."""
|
|
108
109
|
return self._root.version
|
|
109
110
|
|
|
111
|
+
@property
|
|
112
|
+
def border_fills(self) -> dict[str, GenericElement]:
|
|
113
|
+
"""Return border fill definitions declared in the headers."""
|
|
114
|
+
|
|
115
|
+
return self._root.border_fills
|
|
116
|
+
|
|
117
|
+
def border_fill(self, border_fill_id_ref: int | str | None) -> GenericElement | None:
|
|
118
|
+
"""Return the border fill definition referenced by *border_fill_id_ref*."""
|
|
119
|
+
|
|
120
|
+
return self._root.border_fill(border_fill_id_ref)
|
|
121
|
+
|
|
110
122
|
@property
|
|
111
123
|
def memo_shapes(self) -> dict[str, MemoShape]:
|
|
112
124
|
"""Return memo shapes available in the header reference lists."""
|
|
@@ -529,7 +541,7 @@ class HwpxDocument:
|
|
|
529
541
|
section_index: int | None = None,
|
|
530
542
|
width: int | None = None,
|
|
531
543
|
height: int | None = None,
|
|
532
|
-
border_fill_id_ref: str | int =
|
|
544
|
+
border_fill_id_ref: str | int | None = None,
|
|
533
545
|
para_pr_id_ref: str | int | None = None,
|
|
534
546
|
style_id_ref: str | int | None = None,
|
|
535
547
|
char_pr_id_ref: str | int | None = None,
|
|
@@ -538,6 +550,10 @@ class HwpxDocument:
|
|
|
538
550
|
) -> HwpxOxmlTable:
|
|
539
551
|
"""Create a table in a new paragraph and return it."""
|
|
540
552
|
|
|
553
|
+
resolved_border_fill: str | int | None = border_fill_id_ref
|
|
554
|
+
if resolved_border_fill is None:
|
|
555
|
+
resolved_border_fill = self._root.ensure_basic_border_fill()
|
|
556
|
+
|
|
541
557
|
paragraph = self.add_paragraph(
|
|
542
558
|
"",
|
|
543
559
|
section=section,
|
|
@@ -553,7 +569,7 @@ class HwpxDocument:
|
|
|
553
569
|
cols,
|
|
554
570
|
width=width,
|
|
555
571
|
height=height,
|
|
556
|
-
border_fill_id_ref=
|
|
572
|
+
border_fill_id_ref=resolved_border_fill,
|
|
557
573
|
run_attributes=run_attributes,
|
|
558
574
|
char_pr_id_ref=char_pr_id_ref,
|
|
559
575
|
)
|
|
@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
|
|
|
11
11
|
from lxml import etree as LET
|
|
12
12
|
|
|
13
13
|
from . import body
|
|
14
|
+
from .common import GenericElement
|
|
14
15
|
from .header import (
|
|
15
16
|
Bullet,
|
|
16
17
|
MemoProperties,
|
|
@@ -21,6 +22,7 @@ from .header import (
|
|
|
21
22
|
TrackChangeAuthor,
|
|
22
23
|
memo_shape_from_attributes,
|
|
23
24
|
parse_bullets,
|
|
25
|
+
parse_border_fills,
|
|
24
26
|
parse_paragraph_properties,
|
|
25
27
|
parse_styles,
|
|
26
28
|
parse_track_change_authors,
|
|
@@ -44,6 +46,23 @@ _DEFAULT_PARAGRAPH_ATTRS = {
|
|
|
44
46
|
_DEFAULT_CELL_WIDTH = 7200
|
|
45
47
|
_DEFAULT_CELL_HEIGHT = 3600
|
|
46
48
|
|
|
49
|
+
_BASIC_BORDER_FILL_ATTRIBUTES = {
|
|
50
|
+
"threeD": "0",
|
|
51
|
+
"shadow": "0",
|
|
52
|
+
"centerLine": "NONE",
|
|
53
|
+
"breakCellSeparateLine": "0",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_BASIC_BORDER_CHILDREN: Tuple[Tuple[str, dict[str, str]], ...] = (
|
|
57
|
+
("slash", {"type": "NONE", "Crooked": "0", "isCounter": "0"}),
|
|
58
|
+
("backSlash", {"type": "NONE", "Crooked": "0", "isCounter": "0"}),
|
|
59
|
+
("leftBorder", {"type": "SOLID", "width": "0.12 mm", "color": "#000000"}),
|
|
60
|
+
("rightBorder", {"type": "SOLID", "width": "0.12 mm", "color": "#000000"}),
|
|
61
|
+
("topBorder", {"type": "SOLID", "width": "0.12 mm", "color": "#000000"}),
|
|
62
|
+
("bottomBorder", {"type": "SOLID", "width": "0.12 mm", "color": "#000000"}),
|
|
63
|
+
("diagonal", {"type": "SOLID", "width": "0.1 mm", "color": "#000000"}),
|
|
64
|
+
)
|
|
65
|
+
|
|
47
66
|
T = TypeVar("T")
|
|
48
67
|
|
|
49
68
|
|
|
@@ -107,6 +126,59 @@ def _element_local_name(node: ET.Element) -> str:
|
|
|
107
126
|
return tag
|
|
108
127
|
|
|
109
128
|
|
|
129
|
+
def _normalize_length(value: str | None) -> str:
|
|
130
|
+
if value is None:
|
|
131
|
+
return ""
|
|
132
|
+
return value.replace(" ", "").lower()
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _border_fill_is_basic_solid_line(element: ET.Element) -> bool:
|
|
136
|
+
if _element_local_name(element) != "borderFill":
|
|
137
|
+
return False
|
|
138
|
+
|
|
139
|
+
for attr, expected in _BASIC_BORDER_FILL_ATTRIBUTES.items():
|
|
140
|
+
actual = element.get(attr)
|
|
141
|
+
if attr == "centerLine":
|
|
142
|
+
if (actual or "").upper() != expected:
|
|
143
|
+
return False
|
|
144
|
+
else:
|
|
145
|
+
if actual != expected:
|
|
146
|
+
return False
|
|
147
|
+
|
|
148
|
+
for child_name, child_attrs in _BASIC_BORDER_CHILDREN:
|
|
149
|
+
child = element.find(f"{_HH}{child_name}")
|
|
150
|
+
if child is None:
|
|
151
|
+
return False
|
|
152
|
+
for attr, expected in child_attrs.items():
|
|
153
|
+
actual = child.get(attr)
|
|
154
|
+
if attr == "type":
|
|
155
|
+
if (actual or "").upper() != expected:
|
|
156
|
+
return False
|
|
157
|
+
elif attr == "width":
|
|
158
|
+
if _normalize_length(actual) != _normalize_length(expected):
|
|
159
|
+
return False
|
|
160
|
+
elif attr == "color":
|
|
161
|
+
if (actual or "").upper() != expected.upper():
|
|
162
|
+
return False
|
|
163
|
+
else:
|
|
164
|
+
if actual != expected:
|
|
165
|
+
return False
|
|
166
|
+
|
|
167
|
+
for child in element:
|
|
168
|
+
if _element_local_name(child) == "fillBrush":
|
|
169
|
+
return False
|
|
170
|
+
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _create_basic_border_fill_element(border_id: str) -> ET.Element:
|
|
175
|
+
attrs = {"id": border_id, **_BASIC_BORDER_FILL_ATTRIBUTES}
|
|
176
|
+
element = ET.Element(f"{_HH}borderFill", attrs)
|
|
177
|
+
for child_name, child_attrs in _BASIC_BORDER_CHILDREN:
|
|
178
|
+
ET.SubElement(element, f"{_HH}{child_name}", dict(child_attrs))
|
|
179
|
+
return element
|
|
180
|
+
|
|
181
|
+
|
|
110
182
|
def _distribute_size(total: int, parts: int) -> List[int]:
|
|
111
183
|
"""Return *parts* integers that sum to *total* and are as even as possible."""
|
|
112
184
|
|
|
@@ -1525,13 +1597,15 @@ class HwpxOxmlTable:
|
|
|
1525
1597
|
*,
|
|
1526
1598
|
width: int | None = None,
|
|
1527
1599
|
height: int | None = None,
|
|
1528
|
-
border_fill_id_ref: str | int =
|
|
1600
|
+
border_fill_id_ref: str | int | None = None,
|
|
1529
1601
|
) -> ET.Element:
|
|
1530
1602
|
if rows <= 0 or cols <= 0:
|
|
1531
1603
|
raise ValueError("rows and cols must be positive integers")
|
|
1532
1604
|
|
|
1533
1605
|
table_width = width if width is not None else cols * _DEFAULT_CELL_WIDTH
|
|
1534
1606
|
table_height = height if height is not None else rows * _DEFAULT_CELL_HEIGHT
|
|
1607
|
+
if border_fill_id_ref is None:
|
|
1608
|
+
raise ValueError("border_fill_id_ref must be provided")
|
|
1535
1609
|
border_fill = str(border_fill_id_ref)
|
|
1536
1610
|
|
|
1537
1611
|
table_attrs = {
|
|
@@ -1864,10 +1938,19 @@ class HwpxOxmlParagraph:
|
|
|
1864
1938
|
*,
|
|
1865
1939
|
width: int | None = None,
|
|
1866
1940
|
height: int | None = None,
|
|
1867
|
-
border_fill_id_ref: str | int =
|
|
1941
|
+
border_fill_id_ref: str | int | None = None,
|
|
1868
1942
|
run_attributes: dict[str, str] | None = None,
|
|
1869
1943
|
char_pr_id_ref: str | int | None = None,
|
|
1870
1944
|
) -> HwpxOxmlTable:
|
|
1945
|
+
if border_fill_id_ref is None:
|
|
1946
|
+
document = self.section.document
|
|
1947
|
+
if document is not None:
|
|
1948
|
+
resolved_border_fill: str | int = document.ensure_basic_border_fill()
|
|
1949
|
+
else:
|
|
1950
|
+
resolved_border_fill = "0"
|
|
1951
|
+
else:
|
|
1952
|
+
resolved_border_fill = border_fill_id_ref
|
|
1953
|
+
|
|
1871
1954
|
run = self._create_run_for_object(
|
|
1872
1955
|
run_attributes,
|
|
1873
1956
|
char_pr_id_ref=char_pr_id_ref,
|
|
@@ -1877,7 +1960,7 @@ class HwpxOxmlParagraph:
|
|
|
1877
1960
|
cols,
|
|
1878
1961
|
width=width,
|
|
1879
1962
|
height=height,
|
|
1880
|
-
border_fill_id_ref=
|
|
1963
|
+
border_fill_id_ref=resolved_border_fill,
|
|
1881
1964
|
)
|
|
1882
1965
|
run.append(table_element)
|
|
1883
1966
|
self.section.mark_dirty()
|
|
@@ -2253,6 +2336,16 @@ class HwpxOxmlHeader:
|
|
|
2253
2336
|
self.mark_dirty()
|
|
2254
2337
|
return element
|
|
2255
2338
|
|
|
2339
|
+
def _border_fills_element(self, create: bool = False) -> ET.Element | None:
|
|
2340
|
+
ref_list = self._ref_list_element(create=create)
|
|
2341
|
+
if ref_list is None:
|
|
2342
|
+
return None
|
|
2343
|
+
element = ref_list.find(f"{_HH}borderFills")
|
|
2344
|
+
if element is None and create:
|
|
2345
|
+
element = ET.SubElement(ref_list, f"{_HH}borderFills", {"itemCnt": "0"})
|
|
2346
|
+
self.mark_dirty()
|
|
2347
|
+
return element
|
|
2348
|
+
|
|
2256
2349
|
def _char_properties_element(self, create: bool = False) -> ET.Element | None:
|
|
2257
2350
|
ref_list = self._ref_list_element(create=create)
|
|
2258
2351
|
if ref_list is None:
|
|
@@ -2267,6 +2360,10 @@ class HwpxOxmlHeader:
|
|
|
2267
2360
|
count = len(list(element.findall(f"{_HH}charPr")))
|
|
2268
2361
|
element.set("itemCnt", str(count))
|
|
2269
2362
|
|
|
2363
|
+
def _update_border_fills_item_count(self, element: ET.Element) -> None:
|
|
2364
|
+
count = len(list(element.findall(f"{_HH}borderFill")))
|
|
2365
|
+
element.set("itemCnt", str(count))
|
|
2366
|
+
|
|
2270
2367
|
def _allocate_char_property_id(
|
|
2271
2368
|
self,
|
|
2272
2369
|
element: ET.Element,
|
|
@@ -2297,6 +2394,26 @@ class HwpxOxmlHeader:
|
|
|
2297
2394
|
candidate = str(next_id)
|
|
2298
2395
|
return candidate
|
|
2299
2396
|
|
|
2397
|
+
def _allocate_border_fill_id(self, element: ET.Element) -> str:
|
|
2398
|
+
existing: set[str] = {
|
|
2399
|
+
child.get("id") or ""
|
|
2400
|
+
for child in element.findall(f"{_HH}borderFill")
|
|
2401
|
+
}
|
|
2402
|
+
existing.discard("")
|
|
2403
|
+
|
|
2404
|
+
numeric_ids: List[int] = []
|
|
2405
|
+
for value in existing:
|
|
2406
|
+
try:
|
|
2407
|
+
numeric_ids.append(int(value))
|
|
2408
|
+
except ValueError:
|
|
2409
|
+
continue
|
|
2410
|
+
next_id = 0 if not numeric_ids else max(numeric_ids) + 1
|
|
2411
|
+
candidate = str(next_id)
|
|
2412
|
+
while candidate in existing:
|
|
2413
|
+
next_id += 1
|
|
2414
|
+
candidate = str(next_id)
|
|
2415
|
+
return candidate
|
|
2416
|
+
|
|
2300
2417
|
def ensure_char_property(
|
|
2301
2418
|
self,
|
|
2302
2419
|
*,
|
|
@@ -2386,6 +2503,59 @@ class HwpxOxmlHeader:
|
|
|
2386
2503
|
return None
|
|
2387
2504
|
return ref_list.find(f"{_HH}trackChangeAuthors")
|
|
2388
2505
|
|
|
2506
|
+
def find_basic_border_fill_id(self) -> str | None:
|
|
2507
|
+
element = self._border_fills_element()
|
|
2508
|
+
if element is None:
|
|
2509
|
+
return None
|
|
2510
|
+
for child in element.findall(f"{_HH}borderFill"):
|
|
2511
|
+
if _border_fill_is_basic_solid_line(child):
|
|
2512
|
+
identifier = child.get("id")
|
|
2513
|
+
if identifier:
|
|
2514
|
+
return identifier
|
|
2515
|
+
return None
|
|
2516
|
+
|
|
2517
|
+
def ensure_basic_border_fill(self) -> str:
|
|
2518
|
+
element = self._border_fills_element(create=True)
|
|
2519
|
+
if element is None: # pragma: no cover - defensive branch
|
|
2520
|
+
raise RuntimeError("failed to create <borderFills> element")
|
|
2521
|
+
|
|
2522
|
+
existing = self.find_basic_border_fill_id()
|
|
2523
|
+
if existing is not None:
|
|
2524
|
+
return existing
|
|
2525
|
+
|
|
2526
|
+
new_id = self._allocate_border_fill_id(element)
|
|
2527
|
+
element.append(_create_basic_border_fill_element(new_id))
|
|
2528
|
+
self._update_border_fills_item_count(element)
|
|
2529
|
+
self.mark_dirty()
|
|
2530
|
+
return new_id
|
|
2531
|
+
|
|
2532
|
+
@property
|
|
2533
|
+
def border_fills(self) -> dict[str, GenericElement]:
|
|
2534
|
+
element = self._border_fills_element()
|
|
2535
|
+
if element is None:
|
|
2536
|
+
return {}
|
|
2537
|
+
|
|
2538
|
+
fill_list = parse_border_fills(self._convert_to_lxml(element))
|
|
2539
|
+
mapping: dict[str, GenericElement] = {}
|
|
2540
|
+
for border_fill in fill_list.fills:
|
|
2541
|
+
raw_id = border_fill.attributes.get("id")
|
|
2542
|
+
keys: List[str] = []
|
|
2543
|
+
if raw_id:
|
|
2544
|
+
keys.append(raw_id)
|
|
2545
|
+
try:
|
|
2546
|
+
normalized = str(int(raw_id))
|
|
2547
|
+
except ValueError:
|
|
2548
|
+
normalized = None
|
|
2549
|
+
if normalized and normalized not in keys:
|
|
2550
|
+
keys.append(normalized)
|
|
2551
|
+
for key in keys:
|
|
2552
|
+
if key not in mapping:
|
|
2553
|
+
mapping[key] = border_fill
|
|
2554
|
+
return mapping
|
|
2555
|
+
|
|
2556
|
+
def border_fill(self, border_fill_id_ref: int | str | None) -> GenericElement | None:
|
|
2557
|
+
return self._lookup_by_id(self.border_fills, border_fill_id_ref)
|
|
2558
|
+
|
|
2389
2559
|
@staticmethod
|
|
2390
2560
|
def _convert_to_lxml(element: ET.Element) -> LET._Element:
|
|
2391
2561
|
return LET.fromstring(ET.tostring(element, encoding="utf-8"))
|
|
@@ -2788,6 +2958,27 @@ class HwpxOxmlDocument:
|
|
|
2788
2958
|
raise RuntimeError("charPr element is missing an id")
|
|
2789
2959
|
return char_id
|
|
2790
2960
|
|
|
2961
|
+
@property
|
|
2962
|
+
def border_fills(self) -> dict[str, GenericElement]:
|
|
2963
|
+
mapping: dict[str, GenericElement] = {}
|
|
2964
|
+
for header in self._headers:
|
|
2965
|
+
mapping.update(header.border_fills)
|
|
2966
|
+
return mapping
|
|
2967
|
+
|
|
2968
|
+
def border_fill(self, border_fill_id_ref: int | str | None) -> GenericElement | None:
|
|
2969
|
+
return HwpxOxmlHeader._lookup_by_id(self.border_fills, border_fill_id_ref)
|
|
2970
|
+
|
|
2971
|
+
def ensure_basic_border_fill(self) -> str:
|
|
2972
|
+
if not self._headers:
|
|
2973
|
+
return "0"
|
|
2974
|
+
|
|
2975
|
+
for header in self._headers:
|
|
2976
|
+
existing = header.find_basic_border_fill_id()
|
|
2977
|
+
if existing is not None:
|
|
2978
|
+
return existing
|
|
2979
|
+
|
|
2980
|
+
return self._headers[0].ensure_basic_border_fill()
|
|
2981
|
+
|
|
2791
2982
|
@property
|
|
2792
2983
|
def memo_shapes(self) -> dict[str, MemoShape]:
|
|
2793
2984
|
shapes: dict[str, MemoShape] = {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-hwpx
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5
|
|
4
4
|
Summary: Hancom HWPX 패키지를 로드하고 편집하기 위한 Python 유틸리티 모음
|
|
5
5
|
Author: python-hwpx Maintainers
|
|
6
6
|
License: Non-Commercial License
|
|
@@ -38,7 +38,7 @@ Requires-Dist: pytest>=7.4; extra == "test"
|
|
|
38
38
|
- **문서 편집 API** – `hwpx.document.HwpxDocument`는 문단과 표, 메모, 헤더 속성을 파이썬 객체로 노출하고 새 콘텐츠를 손쉽게 추가합니다. 섹션 머리말·꼬리말을 수정하면 `<hp:headerApply>`/`<hp:footerApply>`와 마스터 페이지 링크도 함께 갱신합니다.
|
|
39
39
|
- **타입이 지정된 본문 모델** – `hwpx.oxml.body`는 표·컨트롤·인라인 도형·변경 추적 태그를 데이터 클래스에 매핑하고, `HwpxOxmlParagraph.model`/`HwpxOxmlRun.model`로 이를 조회·수정한 뒤 XML로 되돌릴 수 있도록 지원합니다.
|
|
40
40
|
- **메모와 필드 앵커** – `add_memo_with_anchor()`로 메모를 생성하면서 MEMO 필드 컨트롤을 자동 삽입해 한/글에서 바로 표시되도록 합니다.
|
|
41
|
-
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
41
|
+
- **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 테두리 채우기, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.border_fills`·`document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
|
|
42
42
|
- **바탕쪽·이력·버전 파트 제어** – 매니페스트에 포함된 master-page/history/version 파트를 `document.master_pages`, `document.histories`, `document.version`으로 직접 편집하고 저장합니다.
|
|
43
43
|
- **스타일 기반 텍스트 치환** – 런 서식(색상, 밑줄, `charPrIDRef`)으로 필터링해 텍스트를 선택적으로 교체하거나 삭제합니다. 하이라이트
|
|
44
44
|
마커나 태그로 분리된 문자열도 서식을 유지한 채 치환합니다.
|
|
@@ -79,6 +79,7 @@ print("sections:", len(document.sections))
|
|
|
79
79
|
# 2) 문단과 표, 메모 추가
|
|
80
80
|
section = document.sections[0]
|
|
81
81
|
paragraph = document.add_paragraph("자동 생성한 문단", section=section)
|
|
82
|
+
# 표에 사용할 기본 실선 테두리 채우기가 없으면 add_table()이 자동으로 생성합니다.
|
|
82
83
|
table = document.add_table(rows=2, cols=2, section=section)
|
|
83
84
|
table.set_cell_text(0, 0, "항목")
|
|
84
85
|
table.set_cell_text(0, 1, "값")
|
|
@@ -90,6 +91,8 @@ document.add_memo_with_anchor("배포 전 검토", paragraph=paragraph, memo_sha
|
|
|
90
91
|
document.save("output/example.hwpx")
|
|
91
92
|
```
|
|
92
93
|
|
|
94
|
+
`HwpxDocument.add_table()`은 문서에 정의된 테두리 채우기가 없으면 헤더 참조 목록에 "기본 실선" `borderFill`을 만들어 표와 모든 셀에 참조를 연결합니다.
|
|
95
|
+
|
|
93
96
|
더 많은 실전 패턴은 [빠른 시작](docs/quickstart.md)과 [사용 가이드](docs/usage.md)의 "빠른 예제 모음"에서 확인할 수 있습니다.
|
|
94
97
|
|
|
95
98
|
## 문서
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Integration tests for automatic table border fills."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import xml.etree.ElementTree as ET
|
|
6
|
+
|
|
7
|
+
from hwpx.document import HwpxDocument
|
|
8
|
+
|
|
9
|
+
HP_NS = "http://www.hancom.co.kr/hwpml/2011/paragraph"
|
|
10
|
+
HH_NS = "http://www.hancom.co.kr/hwpml/2011/head"
|
|
11
|
+
HP = f"{{{HP_NS}}}"
|
|
12
|
+
HH = f"{{{HH_NS}}}"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_add_table_injects_basic_border_fill_when_missing() -> None:
|
|
16
|
+
document = HwpxDocument.new()
|
|
17
|
+
|
|
18
|
+
header = document.headers[0]
|
|
19
|
+
ref_list = header.element.find(f"{HH}refList")
|
|
20
|
+
if ref_list is not None:
|
|
21
|
+
existing = ref_list.find(f"{HH}borderFills")
|
|
22
|
+
if existing is not None:
|
|
23
|
+
ref_list.remove(existing)
|
|
24
|
+
header.reset_dirty()
|
|
25
|
+
|
|
26
|
+
section = document.sections[0]
|
|
27
|
+
section.reset_dirty()
|
|
28
|
+
|
|
29
|
+
table = document.add_table(2, 2, section=section)
|
|
30
|
+
assert table is not None
|
|
31
|
+
|
|
32
|
+
updates = document.oxml.serialize()
|
|
33
|
+
|
|
34
|
+
assert header.part_name in updates
|
|
35
|
+
header_root = ET.fromstring(updates[header.part_name])
|
|
36
|
+
|
|
37
|
+
border_fills_element = header_root.find(f".//{HH}borderFills")
|
|
38
|
+
assert border_fills_element is not None
|
|
39
|
+
assert border_fills_element.get("itemCnt") == "1"
|
|
40
|
+
|
|
41
|
+
border_fill_element = border_fills_element.find(f"{HH}borderFill")
|
|
42
|
+
assert border_fill_element is not None
|
|
43
|
+
border_id = border_fill_element.get("id")
|
|
44
|
+
assert border_id == "0"
|
|
45
|
+
assert border_fill_element.get("threeD") == "0"
|
|
46
|
+
assert border_fill_element.get("shadow") == "0"
|
|
47
|
+
assert border_fill_element.get("centerLine") == "NONE"
|
|
48
|
+
assert border_fill_element.get("breakCellSeparateLine") == "0"
|
|
49
|
+
|
|
50
|
+
slash = border_fill_element.find(f"{HH}slash")
|
|
51
|
+
assert slash is not None
|
|
52
|
+
assert slash.get("type") == "NONE"
|
|
53
|
+
|
|
54
|
+
back_slash = border_fill_element.find(f"{HH}backSlash")
|
|
55
|
+
assert back_slash is not None
|
|
56
|
+
assert back_slash.get("type") == "NONE"
|
|
57
|
+
|
|
58
|
+
for child_name in ("leftBorder", "rightBorder", "topBorder", "bottomBorder"):
|
|
59
|
+
child = border_fill_element.find(f"{HH}{child_name}")
|
|
60
|
+
assert child is not None
|
|
61
|
+
assert child.get("type") == "SOLID"
|
|
62
|
+
assert child.get("width") == "0.12 mm"
|
|
63
|
+
assert child.get("color") == "#000000"
|
|
64
|
+
|
|
65
|
+
diagonal = border_fill_element.find(f"{HH}diagonal")
|
|
66
|
+
assert diagonal is not None
|
|
67
|
+
assert diagonal.get("type") == "SOLID"
|
|
68
|
+
assert diagonal.get("width") == "0.1 mm"
|
|
69
|
+
assert diagonal.get("color") == "#000000"
|
|
70
|
+
|
|
71
|
+
assert section.part_name in updates
|
|
72
|
+
section_root = ET.fromstring(updates[section.part_name])
|
|
73
|
+
|
|
74
|
+
table_element = section_root.find(f".//{HP}tbl")
|
|
75
|
+
assert table_element is not None
|
|
76
|
+
assert table_element.get("borderFillIDRef") == border_id
|
|
77
|
+
|
|
78
|
+
cells = section_root.findall(f".//{HP}tc")
|
|
79
|
+
assert cells
|
|
80
|
+
for cell in cells:
|
|
81
|
+
assert cell.get("borderFillIDRef") == border_id
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|