Skip to content

fix(writer): produce spec-compliant HWP 5.0 files that Hancom Office accepts - #10

Open
helenanova wants to merge 1 commit into
Indosaram:mainfrom
helenanova:fix/spec-compliant-hwp5-writer
Open

helenanova wants to merge 1 commit into
Indosaram:mainfrom
helenanova:fix/spec-compliant-hwp5-writer

Conversation

@helenanova

Copy link
Copy Markdown

Problem

Files generated by HwpWriter were rejected by Hancom Office with "파일이 손상되었습니다" (file is corrupted) even for a minimal document (#4).

Root causes

The writer emitted structurally invalid HWP 5.0 output in several independent ways:

  • Missing \005HwpSummaryInformation stream
  • FaceName record didn't follow spec 4.1.4 (truncated panose, extra substitute byte, wrong flags)
  • CharShape referenced face name IDs in language categories with no registered face names
  • TabDef missing its count field; ParaShape 58 bytes instead of 54
  • CommonControl headers (tbl , gso ) missing the description BSTR (HWP 5.0.0.5+)
  • Table body and cell list headers used wrong tag IDs (0x4F/0x4C instead of HWPTAG_TABLE 0x4D / HWPTAG_LIST_HEADER 0x48) and wrong internal layouts
  • BorderFill dropped the color-pattern fill block on serialize
  • Reader-side FaceName/TabDef/BorderFill parsing didn't match the spec either, so real files were misparsed

Fix

  • Spec-compliant serialization for all of the above, verified byte-by-byte against a real Hancom-produced file (hwplib's blank.hwp)
  • Face names are now tracked per language category (new FaceNameLanguage) so ID_MAPPINGS counts and CharShape references are always valid; new fonts register in all 7 categories
  • \005HwpSummaryInformation property-set stream is written
  • New HwpWriter::set_compressed() API; compressed output uses raw deflate (nowrap), matching hwplib and pyhwp

Testing

  • 12 new regression tests in tests/writer_hancom_compat_test.rs assert the structural invariants of valid HWP 5.0 files
  • Full suite: 162 tests pass
  • Every writer example's output now parses cleanly with pyhwp (hwp5txt/hwp5html), including tables, images, and page layouts
  • Round-trip: hwplib's blank.hwp parses and re-serializes into a clean file

Note: I don't have Hancom Office available in this environment, so compatibility is verified against pyhwp and a real Hancom-produced file rather than the application itself. A final smoke test of examples/create_document.rs output in Hancom Office would be appreciated.

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