Document Viewer
Relevant source files
The following files were used as context for generating this wiki page:
The Document Viewer is the primary functional component of the OpenHWP application, designed to open and display Korean HWP and HWPX documents across macOS, Windows, and Linux. It functions as a "thin desktop shell" that delegates complex document parsing and rendering tasks to an external engine, allowing for cross-platform compatibility without requiring Hancom Office.
Sources: README.en.md:5-9, README.md:5-9
The viewer is built using the Deno desktop runtime and utilizes Chromium (via the CEF backend) for consistent rendering. By separating the document engine from the platform shell, the project ensures that the core viewing logic remains portable and independent of the native operating system's UI limitations.
Sources: README.en.md:11-17, README.md:11-17
Architecture and Components
The Document Viewer architecture is divided into three distinct layers: the Desktop Shell, the Rendering Backend, and the Document Engine.
System Architecture Overview
The following diagram illustrates the relationship between the Deno desktop shell and the specialized document engine.
The architecture separates the platform-specific shell from the document logic.
Sources: README.en.md:11-17, README.md:11-17
Key Components
| Component | Technology | Role |
|---|---|---|
| Desktop Shell | deno desktop | Provides native windows and handles the lifecycle of the application. |
| Rendering Backend | CEF (Chromium) | Ensures identical rendering of web-based content and SVGs across all operating systems. |
| Document Engine | @rhwp/core | A Rust-based engine compiled to WebAssembly (WASM) that parses HWP/HWPX and renders pages to SVG. |
| File Access | File System Access API | Provides secure, web-standard access to local files from the localhost context. |
Sources: README.en.md:11-23, README.md:11-23
Data Flow: Opening a Document
The Document Viewer follows a specific sequence to load a document from the local file system and render it within the UI. It leverages the browser-standard showOpenFilePicker to obtain a file handle and the @rhwp/core WASM module to process the binary data.
Document Loading Sequence
This flow represents the logic for opening and rendering the first page of a document.
Sources: README.en.md:32-41, README.md:32-41
Core Rendering Logic
The viewing functionality specifically targets .hwp and .hwpx file types. The rendering process transforms the internal document structure into SVG elements that are injected directly into the application's DOM.
// Example of the viewer rendering flow
import init, { HwpDocument } from "@rhwp/core";
await init();
const doc = new HwpDocument(bytes);
document.querySelector("#viewer").innerHTML = doc.renderPageSvg(0);
Sources: README.en.md:27-33, README.md:27-33
Technical Implementation Details
Deno Desktop Integration
The viewer is served via Deno.serve() and rendered inside a native window's webview. By setting the backend to cef in deno.json, the application gains access to modern Web APIs like the File System Access API even on platforms where native Deno support for such features might be pending.
Sources: README.en.md:13-15, README.md:13-15
File Handling Specifications
The viewer uses the File System Access API to interact with the host OS. This allows the application to remain "thin" by avoiding the need for native Deno file picker bindings.
| API Method | Usage in Viewer |
|---|---|
showOpenFilePicker | Restricted to application/octet-stream with extensions .hwp and .hwpx. |
getFile | Retrieves the file blob for conversion to a buffer. |
createWritable | (Roadmap) Used for saving modifications back to the original file handle. |
Sources: README.en.md:38-51, README.md:38-51
Development and Deployment
The Document Viewer is managed through a single Deno toolchain. Developers utilize built-in Deno commands for linting, formatting, and testing to ensure the shell and engine integration remains stable.
Build and Test Commands
| Task | Command | Description |
|---|---|---|
| Development | deno task dev | Runs the viewer in development mode. |
| Testing | deno test | Executes the test suite (baseline checks). |
| Binary Build | deno desktop main.ts --backend cef | Compiles a standalone binary with the Chromium backend. |
| Packaging | deno desktop main.ts | Generates platform-specific installers (.dmg, .msi, .deb). |
Sources: CONTRIBUTING.md:13-25, README.en.md:55-66, orca.yaml:14-17
Roadmap Features
The Document Viewer is the foundation for future capabilities:
- Editor Integration: Embedding
@rhwp/editorwithin an iframe to enable document modification. - Export & Print: Utilizing the
rhwpengine for PDF export and the webview's native print path. - Native Menus: Implementing
Deno desktopmenus for better OS integration.
Sources: README.en.md:68-74, README.md:68-74
The Document Viewer represents the initial milestone of the OpenHWP project, providing a lightweight, cross-platform solution for accessing HWP documents by bridging Rust-based parsing with modern web rendering.
Sources: README.en.md:69, README.md:69