Skip to content

fix(hwp5): read and write a picture's alpha and reverse where Hancom keeps them - #462

Open
airmang wants to merge 1 commit into
mainfrom
fix/hwp-picture-alpha-reverse
Open

airmang wants to merge 1 commit into
mainfrom
fix/hwp-picture-alpha-reverse

Conversation

@airmang

@airmang airmang commented Oct 13, 2026

Copy link
Copy Markdown
Owner

무엇

.hwp를 HWPX로 열 때 그림 두 값을 한/글이 읽는 자리에서 읽는다. HWP 5.0으로 저장할 때도 같은 자리에 쓴다.

  • 투명도: 한/글은 그림 레코드(SHAPE_COMPONENT_PICTURE)의 투명도를 그림 원래 크기 뒤의 마지막 바이트에서 읽는다.
    • 바이너리 항목 번호 바로 뒤 바이트는 읽지 않고, 저장할 때는 0으로 쓴다.
    • 지금까지는 그 바이트를 hc:img@alpha로 옮겼다. 그래서 거기에 255가 든 문서의 그림이 HWPX에서 보이지 않았다(한/글에서는 보인다).
    • 이제 마지막 바이트를 읽는다(Picture.transparency). 레코드가 그림 크기 앞에서 끝나면 0이다.
  • 반전: 그림 개체 속성(SHAPE_COMPONENT flags)의 24번 비트가 hp:pic@reverse다. 지금까지는 늘 0으로 썼다.
  • HWP 5.0 쓰기: 투명도는 마지막 바이트에, 바이너리 항목 번호 뒤 바이트는 0으로, 반전은 24번 비트에 쓴다. 그래서 HWPX → HWP → HWPX를 거쳐도 두 값이 그대로 남는다.

확인

  • 한/글로 만든 합성 문서(그림 하나, alpha 0·1·64·128·200·254·255):
    • 한/글이 HWP로 저장하면 투명도는 마지막 바이트에 들어가고, 앞 바이트는 늘 0이다.
    • 앞 바이트에만 값을 넣은 HWP는 한/글이 불투명하게 그리고 alpha="0"으로 저장한다.
  • 새 시험 8건 중 6건은 고치기 전 코드에서 실패한다.
    • 읽기: 투명도 4가지, 반전 3가지.
    • 쓰기와 다시 열기: 1건.
  • 이 PC 전체 시험: 실패는 기준선과 같고 새 실패는 0건이다. ruff·mypy·pyright·오류 코드 집계·c901도 통과했다.

🤖 Generated with Claude Code

…keeps them

Hancom reads a picture's transparency from the last byte of the picture
record, after the image's own size, and does not read the byte after the
binary item id (it writes that byte as 0). The reader took that byte as
the alpha, so a picture with 255 there opened invisible. Bit 24 of a
picture's component flags is hp:pic reverse, which was always written
as 0. The HWP 5.0 writer now puts both values in the same places.

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