Skip to content
/ emf-rs Public

Library to parse EMF(Enhanced Metafile) and convert to SVG (WIP).

License

Notifications You must be signed in to change notification settings

mythrnr/emf-rs

Repository files navigation

emf-rs

Library to parse EMF and convert to SVG (WIP).

crates

  • emf-core
    • parser module ... Parsing according to MS-EMF specifications.
    • converter module ... Converting parsed records to SVG.
  • emf-cli ... An example runner for emf-core.

Requirements

  • Rust 1.82.0+ (For Development)
  • wasm-pack
  • Yarn 1.22.22+ (To run example)

Optionals

Installation

[dependencies]
emf-core = { git = "https://github.com/mythrnr/emf-rs.git", tag = "0.0.1", package = "emf-core" }

Examples

Run as CLI

More details, see emf-cli crate.

$ cargo run --package emf-cli -- --help
Usage: emf-cli [OPTIONS] --input <INPUT>

Options:
  -i, --input <INPUT>    The EMF file path to convert to SVG
  -o, --output <OUTPUT>  The destination file path to save converted SVG [default: output.svg]
  -q, --quiet            Omit logs except error log
      --verbose          Print debug logs
  -h, --help             Print help
  -V, --version          Print version

Run as WASM on browser

make serve
  • Enable to set log level by running setLogLevel(level: "trace" | "debug" | "info" | "warn" | "error")
    • Default is info level.
    • NOTE: trace and debug levels are very slow to execute.
  • If you want more small WASM, disable tracing feature. But no logs will be out in console.
    • Running setLogLevel has no effect.
<script type="module">
import init, { convertEmf2Svg, setLogLevel } from './emf_wasm.js';

async function run() {
  await init();
  setLogLevel('debug');

  document.getElementById('input').addEventListener('change', () => {
    const input = document.getElementById('input');
    const files = input.files;

    if (files === null || files.length === 0) {
      return;
    }

    const fileReader = new FileReader();

    fileReader.onload = function (e) {
      const bytes = new Uint8Array(e.target.result);
      const output = convertEmf2Svg(bytes);

      document.getElementById('output').innerHTML = output;
    };

    fileReader.readAsArrayBuffer(files[0]);
  });
}

run();
</script>

About

Library to parse EMF(Enhanced Metafile) and convert to SVG (WIP).

Resources

License

Stars

Watchers

Forks

Languages