ext-xform.js 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const BaseXform = require('../base-xform');
  2. /** https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML */
  3. const EMU_PER_PIXEL_AT_96_DPI = 9525;
  4. class ExtXform extends BaseXform {
  5. constructor(options) {
  6. super();
  7. this.tag = options.tag;
  8. this.map = {};
  9. }
  10. render(xmlStream, model) {
  11. xmlStream.openNode(this.tag);
  12. const width = Math.floor(model.width * EMU_PER_PIXEL_AT_96_DPI);
  13. const height = Math.floor(model.height * EMU_PER_PIXEL_AT_96_DPI);
  14. xmlStream.addAttribute('cx', width);
  15. xmlStream.addAttribute('cy', height);
  16. xmlStream.closeNode();
  17. }
  18. parseOpen(node) {
  19. if (node.name === this.tag) {
  20. this.model = {
  21. width: parseInt(node.attributes.cx || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
  22. height: parseInt(node.attributes.cy || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
  23. };
  24. return true;
  25. }
  26. return false;
  27. }
  28. parseText(/* text */) {}
  29. parseClose(/* name */) {
  30. return false;
  31. }
  32. }
  33. module.exports = ExtXform;