vml-shape-xform.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const BaseXform = require('../base-xform');
  2. const VmlTextboxXform = require('./vml-textbox-xform');
  3. const VmlClientDataXform = require('./vml-client-data-xform');
  4. class VmlShapeXform extends BaseXform {
  5. constructor() {
  6. super();
  7. this.map = {
  8. 'v:textbox': new VmlTextboxXform(),
  9. 'x:ClientData': new VmlClientDataXform(),
  10. };
  11. }
  12. get tag() {
  13. return 'v:shape';
  14. }
  15. render(xmlStream, model, index) {
  16. xmlStream.openNode('v:shape', VmlShapeXform.V_SHAPE_ATTRIBUTES(model, index));
  17. xmlStream.leafNode('v:fill', {color2: 'infoBackground [80]'});
  18. xmlStream.leafNode('v:shadow', {color: 'none [81]', obscured: 't'});
  19. xmlStream.leafNode('v:path', {'o:connecttype': 'none'});
  20. this.map['v:textbox'].render(xmlStream, model);
  21. this.map['x:ClientData'].render(xmlStream, model);
  22. xmlStream.closeNode();
  23. }
  24. parseOpen(node) {
  25. if (this.parser) {
  26. this.parser.parseOpen(node);
  27. return true;
  28. }
  29. switch (node.name) {
  30. case this.tag:
  31. this.reset();
  32. this.model = {
  33. margins: {
  34. insetmode: node.attributes['o:insetmode'],
  35. },
  36. anchor: '',
  37. editAs: '',
  38. protection: {},
  39. };
  40. break;
  41. default:
  42. this.parser = this.map[node.name];
  43. if (this.parser) {
  44. this.parser.parseOpen(node);
  45. }
  46. break;
  47. }
  48. return true;
  49. }
  50. parseText(text) {
  51. if (this.parser) {
  52. this.parser.parseText(text);
  53. }
  54. }
  55. parseClose(name) {
  56. if (this.parser) {
  57. if (!this.parser.parseClose(name)) {
  58. this.parser = undefined;
  59. }
  60. return true;
  61. }
  62. switch (name) {
  63. case this.tag:
  64. this.model.margins.inset = this.map['v:textbox'].model && this.map['v:textbox'].model.inset;
  65. this.model.protection =
  66. this.map['x:ClientData'].model && this.map['x:ClientData'].model.protection;
  67. this.model.anchor = this.map['x:ClientData'].model && this.map['x:ClientData'].model.anchor;
  68. this.model.editAs = this.map['x:ClientData'].model && this.map['x:ClientData'].model.editAs;
  69. return false;
  70. default:
  71. return true;
  72. }
  73. }
  74. }
  75. VmlShapeXform.V_SHAPE_ATTRIBUTES = (model, index) => ({
  76. id: `_x0000_s${1025 + index}`,
  77. type: '#_x0000_t202',
  78. style:
  79. 'position:absolute; margin-left:105.3pt;margin-top:10.5pt;width:97.8pt;height:59.1pt;z-index:1;visibility:hidden',
  80. fillcolor: 'infoBackground [80]',
  81. strokecolor: 'none [81]',
  82. 'o:insetmode': model.note.margins && model.note.margins.insetmode,
  83. });
  84. module.exports = VmlShapeXform;