Skip to content

feat(core): bundle Liberation Sans for PDF tests and improve image handling#10

Merged
ohah merged 18 commits intomainfrom
feat/pdf-export-tests-fonts-and-images
Feb 21, 2026
Merged

feat(core): bundle Liberation Sans for PDF tests and improve image handling#10
ohah merged 18 commits intomainfrom
feat/pdf-export-tests-fonts-and-images

Conversation

@ohah
Copy link
Copy Markdown
Owner

@ohah ohah commented Feb 21, 2026

feat(core): PDF export tests, bundled fonts, documents rename

Purpose

  • PDF export 테스트가 폰트 없이도 동작하도록 Liberation Sans를 저장소에 포함
  • 이미지 임베딩 안정화 (Base64 디코딩, 투명도 제거 후 RGB 변환)
  • 스냅샷 실행 시 실제 PDF 파일을 스냅샷 디렉터리에 생성
  • Rspress 문서 사이트 디렉터리를 docs/에서 documents/로 변경하여 경로 충돌 해소

Work content

  • 폰트 번들: tests/fixtures/fonts/에 Liberation Sans TTF 4종(LiberationSans-Regular/Bold/Italic/BoldItalic) 및 LICENSE(SIL OFL 1.1), README 추가. find_font_dir()로 테스트에서 자동 사용.
  • 이미지 처리: BinData Base64 디코딩 시 공백/줄바꿈 무시(decode_bindata_base64), genpdf/printpdf 미지원 알파 채널 대응으로 to_rgb8() 후 RGB만 전달해 PDF 이미지 임베딩 안정화.
  • 실제 PDF 출력: pdf_generated 테스트 실행 시 tests/snapshots/pdf_export__noori_pdf_generated.pdf, pdf_export__table_pdf_generated.pdf 형식으로 저장.
  • 테스트 정리: PDF 메타데이터 비결정성으로 바이트 스냅샷 제거. pdf_generated_* 테스트는 유효 PDF 검사 및 파일 쓰기만 수행. content_summary 스냅샷 유지.
  • 린트: collect_summary_recordsdocument_document, find_font_dir#[allow(dead_code)] 적용.
  • documents 리네임: docs/documents/로 디렉터리 이름 변경. 루트 package.json workspaces·스크립트, @hwpjs/documents 패키지명, AGENTS.md·HEARTBEAT·README·folder-structure·commit-rules·커밋 scope, GitHub Actions(docs.yml·CI paths), 내부 경로 참조(documents/·todos) 전부 갱신.
  • PDF 뷰어/테스트: PDF 모듈·테스트·스냅샷 갱신.
  • Node/CLI: to-pdf CLI, batch --format pdf, 기본 font_dir(getDefaultFontDir), packages/hwpjs/fonts/(Noto Sans KR 포함)·download-pdf-fonts.mjs, README to-pdf·font_dir 안내, NAPI toPdf 경로·clippy 수정(generated.rs, lib.rs), dist 빌드 산출물.
  • Node 빌드: dist/hwpjs.darwin-arm64.node·dist/hwpjs.win32-x64-msvc.node 커밋, CONTRIBUTING에 맥에서 Windows(cargo-xwin)·Linux(cross/Docker) 크로스 빌드 사용법 추가. Windows x64는 cargo-xwin으로 크로스 빌드 후 반영.
  • Linux x64 크로스 빌드: Ubuntu 24.04 기반 커스텀 Dockerfile(docker/Dockerfile.x86_64-unknown-linux-gnu)과 Cross.toml 추가. LLD 링커 사용으로 Apple Silicon + QEMU 환경에서 ld 세그폴트 방지. 문서 사이트 개발 가이드에 "Linux x64 크로스 빌드 (macOS)" 절 추가(Colima·Docker·cross 설치, CROSS_BUILD_OPTS 안내), CONTRIBUTING.md에도 동일 설치법 반영.

How to test

  • bun run test:rust (또는 cargo test -p hwp-core --test pdf_export) 실행 시 PDF export 테스트 통과.
  • crates/hwp-core/tests/snapshots/ 아래에 pdf_export__table_pdf_generated.pdf 등이 생성되는지 확인.

Additional info

  • noori 픽스처는 한글 포함으로 Liberation Sans만으로는 렌더 불가(genpdf UnsupportedEncoding). 해당 테스트는 패닉 시 스킵.
  • 한글 문서 PDF는 한글 지원 폰트(예: Noto Sans KR)를 font_dir에 지정해 사용.

@ohah ohah added enhancement New feature or request documentation Improvements or additions to documentation labels Feb 21, 2026
@ohah ohah self-assigned this Feb 21, 2026
ohah added 18 commits February 21, 2026 19:20
- Add genpdf images feature and image 0.23 for embedding images
- Render Table as genpdf TableLayout with cell text from paragraphs
- Embed ShapeComponentPicture from BinData when embed_images is true
- ShapeComponent without picture still outputs [Image] placeholder
- ToPdfOptions: font_dir, embed_images
- to-pdf CLI: -o/--output required, --font-dir, --no-embed-images
- pdf_content_summary(): text summary of PDF elements for snapshot (no font)
- to_pdf_returns_valid_pdf_bytes: valid PDF magic, skip on missing font/fixture
- pdf_content_summary_snapshot_noori/table/embed_images_false: insta snapshots
- to_pdf_table_fixture_returns_valid_pdf: table.hwp roundtrip
…ndling

- Add Liberation Sans TTF (2.00.1) under tests/fixtures/fonts with LICENSE
- Add find_font_dir() in tests/common for PDF tests to use bundled fonts
- PDF: robust base64 decode for BinData, convert to RGB for genpdf (no alpha)
- PDF: write actual .pdf files on snapshot run (pdf_export__*.pdf in snapshots dir)
- pdf_generated tests: assert valid PDF and write file; drop byte snapshot (non-deterministic metadata)
- Clippy: rename document to _document in collect_summary_records; allow(dead_code) for find_font_dir
- Format and snapshot updates for content_summary tests
- 001: CLI to-pdf -o path validation (P1)
- 002: Base64/image size limits (P2)
- 003: font_dir policy doc (P2)
- 004: batch --format pdf (P2)
- 005: RN toPdf (P2)
- 006: README to-pdf/toPdf (P2)
- 007: Remove dead code + duplicate test (P2)
- 008: find_fixture_file path validation (P3)
- 009: common.rs tests_base_dir (P3)
- 010: docs/plans font bundle note (P3)
- Add MAX_BASE64_INPUT_LEN (16 MiB) and MAX_IMAGE_DECODED_LEN (12 MiB) to prevent memory exhaustion attacks
- Add length validation in try_build_image before decoding and rendering
- Update font_dir documentation: clarify it's a directory path with security warning
- Remove dead code: minimal_pdf_bytes function (previously #[allow(dead_code)])
- Rename docs/ to documents/ (Rspress 문서 사이트)
- Update root package.json workspaces and dev:docs/build:docs filter
- Rename @hwpjs/docs to @hwpjs/documents
- Update AGENTS.md, HEARTBEAT.md, README.md, folder-structure.md, commit-rules.md
- Update GitHub Actions: docs.yml paths and artifact path, CI paths-ignore
- Add scope 'documents' to commit conventions
- Update internal refs in documents/ and todos
- PDF viewer mod and test common/pdf_export adjustments
- Update pdf_export__table_pdf_generated.pdf snapshot
… clippy fixes

- to-pdf CLI and batch --format pdf, getDefaultFontDir
- packages/hwpjs/fonts/ with README, download-pdf-fonts.mjs script
- package.json files include fonts, Noto Sans KR download
- README to-pdf and font_dir usage
- NAPI toPdf options path and clippy fixes (generated.rs, lib.rs)
- dist build artifacts for CLI
…CONTRIBUTING

- Add dist/hwpjs.darwin-arm64.node for macOS ARM64
- Document macOS → Windows (cargo-xwin) and macOS → Linux (cross/Docker) in CONTRIBUTING.md
- Build with cargo-xwin (rustup target x86_64-pc-windows-msvc)
- Linux build requires cross + Docker; skipped when cross not installed
…cross-build

- Cross.toml: use docker/Dockerfile.x86_64-unknown-linux-gnu for
  x86_64-unknown-linux-gnu (Ubuntu 24.04 + Rust + LLD)
- Avoid ld segfault under QEMU on Apple Silicon when using cross
- development.mdx: add 'Linux x64 크로스 빌드 (macOS)' section with
  Colima+Docker install, cross install, build command, and
  CROSS_BUILD_OPTS for Apple Silicon
- CONTRIBUTING.md: expand Linux cross-build steps and link to guide
@ohah ohah force-pushed the feat/pdf-export-tests-fonts-and-images branch from ad90236 to e8de57d Compare February 21, 2026 10:21
@ohah ohah merged commit 32cd62d into main Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant