Skip to content

feat(picture): crop a new picture's sides at the same scale - #447

Merged
airmang merged 2 commits into
mainfrom
feat/picture-crop
Oct 8, 2026
Merged

airmang merged 2 commits into
mainfrom
feat/picture-crop

Conversation

@airmang

@airmang airmang commented Oct 8, 2026

Copy link
Copy Markdown
Owner

바뀐 점

그림을 만들 때(doc.add_picture, HwpxOxmlParagraph.add_picture) 네 변을 잘라 낼 수 있다: crop=(왼쪽, 위, 오른쪽, 아래), HWPUNIT.

한/글의 동작

한/글은 자른 그림을 이렇게 쓴다.

  • hp:imgDim에 그림 전체 크기, hp:imgClip에 그 안에서 남길 부분을 쓴다.
  • 그림 틀(sz·orgSz·curSz·imgRect)은 남긴 부분만 한 크기다.

그래서 축척은 그대로다. 자른 만큼 그림이 작아지고, 남은 부분이 원래 크기로 보인다.

  • 틀은 그대로 두고 imgClip만 바꾸면, 남긴 부분이 틀 전체로 늘어나 그려진다.
  • imgDim보다 큰 imgClip은 그림 밖을 빈 곳으로 그린다.

코드

  • oxml/shape_position.py: validate_picture_crop. 0 이상의 int 네 개여야 하고, 가로·세로 모두 그림이 남아야 한다. 아니면 shape-picture-crop-value로 거부한다.
  • oxml/objects.py: _create_picture_element가 crop을 받는다. 틀은 width - 왼쪽 - 오른쪽 x height - 위 - 아래로 그리고, imgDim은 width x height, imgClip은 남길 부분이다. 크기 검사를 자르기 검사보다 먼저 한다.
  • _document/media.py, document.py: 문서 수준 add_picture가 crop을 받고, 이진 항목을 넣기 전에 검사한다.
  • errors.py·docs/error-codes.md: shape-picture-crop-value.
  • docs/support-matrix.md(동봉본 동기화), README.md·README_EN.md(알려진 제약, 예제 원장 해시), 변경 로그: 자르기는 지원, 뒤집기·회전은 아직 지원하지 않는다.
  • tests/data/document_facade_surface.json: add_picture 서명.

테스트

tests/test_picture_adjustments.py:

  • 한/글 저장본 picture_cropped.hwpx(20000 x 10000에서 좌우 5000·위아래 2500을 자름)의 orgSz·sz·imgClip·imgDim과 같은 값을 쓰는지 본다. 틀은 10000 x 5000이다.
  • 그림을 다 잘라 내는 값, 네 개가 아닌 값, 음수, bool, 실수, 문자열은 거부되고, 문단과 이진 항목이 늘지 않는다.

🤖 Generated with Claude Code

add_picture takes crop=(left, top, right, bottom): that much (HWPUNIT) is
cut from the sides of the width x height picture, as Hancom crops one --
hp:imgDim keeps the whole picture's size, hp:imgClip the part kept, and
the picture is drawn as large as that part, at the same scale. A crop
that is not four ints from 0 leaving some of the picture is refused
before anything is added (shape-picture-crop-value).

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

airmang commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

리뷰 결과: 동작은 맞습니다. 병합 전에 한 줄만 다듬어 주세요.

  • src/hwpx/oxml/shape_position.py 124줄: validate_picture_crop의 조건이 공백 13칸을 사이에 두고 한 줄(약 200자)로 붙어 있습니다. 줄 이음이 깨진 것으로 보입니다. 괄호로 감싸 두 줄로 나눠 주세요.

확인한 것

  • 인자를 주지 않으면 구역 XML이 고치기 전과 같습니다.
  • crop=(10000, 5000, 10000, 5000), 40000×20000이면 orgSz·curSz·sz·imgRect가 20000×10000, imgDim이 40000×20000, imgClip이 (10000, 5000)~(30000, 15000)입니다. 한/글 저장본의 자른 그림처럼 imgClip은 imgDim 좌표에서 남길 부분의 네 모서리입니다.
  • 한/글로 열어 보면 가운데·왼쪽·오른쪽 아래·위를 자른 그림이 같은 축척으로 남은 부분만 그려집니다.
  • 가로나 세로가 남지 않는 값, 음수, 실수, 세 값, True는 거부됩니다.

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

airmang commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

다시 리뷰: 병합합니다. 4a0c4686에서 validate_picture_crop의 조건을 괄호로 감싸 두 줄로 나눴고, 동작은 앞서 확인한 그대로입니다.

@airmang
airmang merged commit c52b9f6 into main Oct 8, 2026
13 checks passed
@airmang
airmang deleted the feat/picture-crop branch October 8, 2026 13:48
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