Skip to content

fix(captions,page): refuse gaps and new numbers Hancom does not keep - #417

Open
airmang wants to merge 8 commits into
mainfrom
fix/gap-and-new-number-values
Open

airmang wants to merge 8 commits into
mainfrom
fix/gap-and-new-number-values

Conversation

@airmang

@airmang airmang commented Oct 6, 2026

Copy link
Copy Markdown
Owner

바뀐 점

캡션 간격, 같은 폭 단의 간격, 새 번호에서 한/글이 그대로 두지 않는 값을 무엇도 바꾸기 전에 거부한다. 전에는 그대로 썼다.

한/글의 동작

  • 캡션 간격(hp:caption@gap)은 부호 있는 16비트 수로 읽는다.
    • −32768부터 32767까지는 그대로 둔다. 음수도 그 값대로 그린다.
    • 32768은 −32768로, 65536은 0으로 감싸 읽는다.
  • 같은 폭 단의 간격(hp:colPr@sameGap)도 부호 있는 16비트 수로 읽는다.
    • 0부터 32767까지는 그대로 둔다.
    • 32768은 −32768로 읽어 둘째 단이 첫째 단과 겹친다. 65536은 0이 된다.
    • 음수를 글자로 쓰면("-1") 0으로 읽는다.
  • 새 번호(hp:newNum@num)는 부호 없는 16비트 수로 읽는다. −1은 65535로, 65536은 0으로 감싼다.

코드

  • oxml/shape_position.py
    • validate_caption_gap: −32768 이상 32767 이하의 int만 받는다. 오류 코드는 shape-caption-gap-value.
    • 캡션 면(side) 검사(validate_caption_side)와 그 어휘(CAPTION_SIDES)를 oxml/objects.py에서 옮긴다. 동작은 같다. objects.py가 줄 수 상한(1600)에 닿아 있어 간격 검사를 넣을 자리를 만든다.
  • oxml/objects.py: 표·그림·도형이 함께 쓰는 캡션 쓰기(_write_caption)가 캡션을 만들기 전에 면과 간격을 검사한다.
  • oxml/section_format.py
    • validate_column_gap: 0 이상 32767 이하의 int만 받는다. 오류 코드는 page-column-gap-value.
    • validate_new_number: 받은 값을 전처럼 int()로 바꾼 뒤 0 이상 65535 이하만 받는다. 오류 코드는 page-new-num-value.
  • 단 간격은 같은 폭 단일 때(그 값을 쓸 때)만 검사한다. 구역의 단(set_columns), 문단의 새 단(add_column_definition), 퍼사드(doc.page.set_columns)가 무엇도 바꾸기 전에 검사한다.
  • doc.page.setup(columns=..., column_gap_mm=...)는 쪽 크기와 여백을 바꾸기 전에 단 간격을 검사한다.
  • HwpxOxmlParagraph.add_new_num은 런을 더하기 전에 새 번호를 검사한다.
  • errors.py와 docs/error-codes.md에 코드 셋을 등록하고, 변경 로그 항목을 더한다.

테스트

tests/test_gap_and_new_number_values.py를 더하고, 한/글 저장본 열을 함께 넣는다.

  • 저장본
    • 표 캡션 간격 32767·−1·32768
    • 두 단 간격 32767·32768·"-1"
    • 쪽 번호를 0·65535·65536·−1에서 다시 시작
  • 시험하는 것
    • 한/글이 저장한 값: 그대로 둔 값과 감싼 값
    • 범위 밖 값이 오류 코드와 함께 거부되고 문서가 그대로인지
      • 캡션: 표와 도형. 이미 있는 캡션도 바뀌지 않는다.
      • 단: 구역의 단과 문단의 새 단. page.setup은 쪽도 바뀌지 않는다.
      • 새 번호: 쪽 번호와 표 번호
    • 경계 안의 값(캡션 −32768·−1·0·32767, 단 0·32767, 새 번호 0·65535)이 그대로 쓰이는지

이 PR은 #415와 #416 위에 쌓았다. 앞 PR이 병합되면 그 커밋들은 이 PR의 diff에서 빠진다.

🤖 Generated with Claude Code

airmang and others added 6 commits October 6, 2026 07:25
add_picture wrote any align it was given into hp:pos@horzAlign ("BOGUS",
"  RIGHT ", "TOP"), which Hancom reads as LEFT; a non-string failed only after
the image and its paragraph were added. The alignment is now checked first,
in any case, against the schema's horizontal alignments, and anything else is
refused with shape-position-frame before anything is stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A negative width or height of a rectangle, ellipse, arc, picture or
equation box, or a negative rectangle corner ratio, was written as given;
Hancom reads it as 0. Such values, and sizes of 2**31 or more, are now
refused with typed errors before any paragraph, run or image is added
(shape-size-value, shape-rect-ratio-value). An equation's base_unit
outside 1..2**31-1 raises shape-equation-base-unit-value (a ValueError,
as before) before its paragraph is added. HwpxOxmlShape.resize refuses a
negative size too, and HwpxOxmlParagraph.add_picture builds the picture
before adding its run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hancom reads a caption's gap and the gap between columns of the same
width as signed 16-bit numbers and a new number as an unsigned one,
wrapping anything else (a column gap of 32768 makes the columns overlap;
a negative one written as text is read as 0). set_caption's gap outside
-32768..32767, a same_gap (or page setup column_gap_mm) outside 0..32767
and a restart number outside 0..65535 are now refused before anything
changes (shape-caption-gap-value, page-column-gap-value,
page-new-num-value). The caption side check moves to shape_position
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
airmang and others added 2 commits October 6, 2026 16:27
add_equation's base unit check now raises a typed error, so
oxml/paragraph.py raises one untyped error fewer. The census lock
records 202 untyped raises (paragraph.py 18), as the ratchet's
self-test expects the lock to match the tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant