Skip to content

Latest commit

 

History

History
95 lines (68 loc) · 2.36 KB

README.md

File metadata and controls

95 lines (68 loc) · 2.36 KB

wmf-rs

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

crates

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

Requirements

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

Optionals

Installation

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

Examples

Run as CLI

More details, see wmf-cli crate.

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

Options:
  -i, --input <INPUT>    The WMF 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, { convertWmf2Svg, setLogLevel } from './wmf_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 = convertWmf2Svg(bytes);

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

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

run();
</script>