pic-xform.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const BaseXform = require('../base-xform');
  2. const StaticXform = require('../static-xform');
  3. const BlipFillXform = require('./blip-fill-xform');
  4. const NvPicPrXform = require('./nv-pic-pr-xform');
  5. const spPrJSON = require('./sp-pr');
  6. class PicXform extends BaseXform {
  7. constructor() {
  8. super();
  9. this.map = {
  10. 'xdr:nvPicPr': new NvPicPrXform(),
  11. 'xdr:blipFill': new BlipFillXform(),
  12. 'xdr:spPr': new StaticXform(spPrJSON),
  13. };
  14. }
  15. get tag() {
  16. return 'xdr:pic';
  17. }
  18. prepare(model, options) {
  19. model.index = options.index + 1;
  20. }
  21. render(xmlStream, model) {
  22. xmlStream.openNode(this.tag);
  23. this.map['xdr:nvPicPr'].render(xmlStream, model);
  24. this.map['xdr:blipFill'].render(xmlStream, model);
  25. this.map['xdr:spPr'].render(xmlStream, model);
  26. xmlStream.closeNode();
  27. }
  28. parseOpen(node) {
  29. if (this.parser) {
  30. this.parser.parseOpen(node);
  31. return true;
  32. }
  33. switch (node.name) {
  34. case this.tag:
  35. this.reset();
  36. break;
  37. default:
  38. this.parser = this.map[node.name];
  39. if (this.parser) {
  40. this.parser.parseOpen(node);
  41. }
  42. break;
  43. }
  44. return true;
  45. }
  46. parseText() {}
  47. parseClose(name) {
  48. if (this.parser) {
  49. if (!this.parser.parseClose(name)) {
  50. this.mergeModel(this.parser.model);
  51. this.parser = undefined;
  52. }
  53. return true;
  54. }
  55. switch (name) {
  56. case this.tag:
  57. return false;
  58. default:
  59. // not quite sure how we get here!
  60. return true;
  61. }
  62. }
  63. }
  64. module.exports = PicXform;