版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # js-wmf
  2. Processor for Windows MetaFile (WMF) files in JS (for the browser and nodejs).
  3. ## Installation
  4. With [npm](https://www.npmjs.org/package/wmf):
  5. ```bash
  6. $ npm install wmf
  7. ```
  8. In the browser:
  9. ```html
  10. <script src="wmf.js"></script>
  11. ```
  12. The browser exposes a variable `WMF`.
  13. ## Usage
  14. The `data` argument is expected to be an `ArrayBuffer`, `Uint8Array` or `Buffer`
  15. - `WMF.image_size(data)` extracts the image offset and extents, returns an Array
  16. `[width, height]` where both metrics are measured in pixels.
  17. - `WMF.draw_canvas(data, canvas)` parses the WMF and draws to a `Canvas`.
  18. ### Notes
  19. - The library assumes the global `ImageData` is available. For nodejs-powered
  20. canvas implementations, a shim must be exposed as a global. Using the `canvas`
  21. npm package:
  22. ```js
  23. const { createImageData } = require("canvas");
  24. global.ImageData = createImageData;
  25. ```
  26. - `OffscreenCanvas` in Chrome and some other Canvas implementations require
  27. the dimensions in the constructor:
  28. ```js
  29. const size = WMF.image_size(data);
  30. const canvas = new OffscreenCanvas(size[0], size[1]);
  31. ```
  32. ## Examples
  33. <details>
  34. <summary><b>Browser Fetch into canvas</b> (click to show)</summary>
  35. ```js
  36. // assume `canvas` is a DOM element
  37. (async() => {
  38. const res = await fetch("url/for/image.wmf");
  39. const ab = await res.arrayBuffer();
  40. WMF.draw_canvas(ab, document.getElementById("canvas"));
  41. })();
  42. ```
  43. </details>
  44. <details>
  45. <summary><b>NodeJS (using `canvas` npm module)</b> (click to show)</summary>
  46. ```js
  47. const { createCanvas, createImageData } = require("canvas");
  48. global.ImageData = createImageData;
  49. const size = WMF.image_size(data);
  50. const canvas = createCanvas(size[0], size[1]);
  51. WMF.draw_canvas(data, canvas);
  52. ```
  53. </details>
  54. ## License
  55. Please consult the attached LICENSE file for details. All rights not explicitly
  56. granted by the Apache 2.0 License are reserved by the Original Author.
  57. ## References
  58. - `MS-WMF`: Windows Metafile Format