EMF SDK for Rust
emfsdk is a pure-Rust SDK for reading, inspecting, editing, and writing
Enhanced Metafile (EMF), Enhanced Metafile Format Plus (EMF+), and Windows
Metafile (WMF) data.
Known records and fields are exposed as Rust types. Unknown records, reserved extensions, padding, and opaque binary payloads are preserved so an unmodified metafile can be written without losing data.
Quick Start
use Metafile;
Use EmfMetafile, WmfMetafile, and each record's parse_data method when
you need format-specific typed access.
Compatible and Strict Parsing
Metafile::from_bytes is compatibility-first. It preserves bounded records
that are structurally readable even when a producer violates a field rule.
Compatibility is explicit and inspectable:
use Metafile;
#
Use Metafile::from_bytes_strict or validate_strict when every known record
must satisfy the Microsoft specification and reproduce exactly through its
typed parser and writer. Unknown record types remain an intentional raw
fallback; malformed known records are reported instead of silently treated as
typed.
Features
default: parsing and writing only, with no rendering dependenciesrender: enables raster rendering withimage,fontdb, andttf-parser
The minimum supported Rust version is 1.88. The workspace uses the Rust 2024 edition.
Format Coverage
The implementation follows the Microsoft Open Specifications:
- [MS-EMF]: Enhanced Metafile Format
- [MS-EMFPLUS]: Enhanced Metafile Format Plus Extensions
- [MS-WMF]: Windows Metafile Format
LibreOffice and Apache POI are used as behavioral references. Corpus and
round-trip tests live in
ooxmlsdk-test-suite.
The current standalone candidate corpus covers 950,508 EMF records, 22,824 WMF records, and 14,231 EMF+ records. Of those, 31,922 known records require compatibility preservation. The legacy Office lane covers 134 embedded EMF and 156 embedded WMF images containing another 107,578 records; 3,955 require compatibility preservation. Tests ratchet these counts and require exact whole-file bytes plus exact typed parse/write bytes for conforming records.
Project Status
Version 0.1 remains an early SDK. Byte-preserving parsing and typed record coverage are the primary focus, but compatibility fallbacks above still need to be reduced. The public API can change before 1.0.
The optional renderer is suitable for compatibility and preview workflows, but does not promise pixel-identical output with Windows GDI, GDI+, or LibreOffice.
Changelog
See CHANGELOG.md.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.