mxVsdxCanvas2D.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. */
  4. /**
  5. * Class: mxVsdxCanvas2D
  6. *
  7. * Constructor: mxVsdxCanvas2D
  8. *
  9. * Constructs a new abstract canvas.
  10. */
  11. function mxVsdxCanvas2D(zip)
  12. {
  13. mxAbstractCanvas2D.call(this);
  14. };
  15. /**
  16. * Extends mxAbstractCanvas2D
  17. */
  18. mxUtils.extend(mxVsdxCanvas2D, mxAbstractCanvas2D);
  19. /**
  20. * Variable: textEnabled
  21. *
  22. * Specifies if text output should be enabled. Default is true.
  23. */
  24. mxVsdxCanvas2D.prototype.textEnabled = true;
  25. /**
  26. * Function: init
  27. *
  28. * Initialize the canvas for a new vsdx file.
  29. */
  30. mxVsdxCanvas2D.prototype.init = function (zip)
  31. {
  32. this.filesLoading = 0;
  33. this.zip = zip;
  34. };
  35. /**
  36. * Function: createGeoSec
  37. *
  38. * Create a new geo section.
  39. */
  40. mxVsdxCanvas2D.prototype.createGeoSec = function ()
  41. {
  42. if (this.geoSec != null)
  43. {
  44. this.shape.appendChild(this.geoSec);
  45. }
  46. var geoSec = this.xmlDoc.createElement("Section");
  47. geoSec.setAttribute("N", "Geometry");
  48. geoSec.setAttribute("IX", this.geoIndex++);
  49. this.geoSec = geoSec;
  50. this.geoStepIndex = 1;
  51. this.lastX = 0;
  52. this.lastY = 0;
  53. this.lastMoveToX = 0;
  54. this.lastMoveToY = 0;
  55. };
  56. /**
  57. * Function: newShape
  58. *
  59. * Create a new shape.
  60. */
  61. mxVsdxCanvas2D.prototype.newShape = function (shape, cellState, xmlDoc)
  62. {
  63. this.geoIndex = 0;
  64. this.shape = shape;
  65. this.cellState = cellState;
  66. this.xmGeo = cellState.cell.geometry;
  67. this.xmlDoc = xmlDoc;
  68. this.geoSec = null;
  69. this.shapeImg = null;
  70. this.shapeType = "Shape";
  71. this.createGeoSec();
  72. };
  73. /**
  74. * Function: newEdge
  75. *
  76. * Create a new edge.
  77. */
  78. mxVsdxCanvas2D.prototype.newEdge = function (shape, cellState, xmlDoc)
  79. {
  80. this.shape = shape;
  81. this.cellState = cellState;
  82. this.xmGeo = cellState.cellBounds;
  83. var s = this.state;
  84. this.xmlDoc = xmlDoc;
  85. };
  86. /**
  87. * Function: endShape
  88. *
  89. * End current shape.
  90. */
  91. mxVsdxCanvas2D.prototype.endShape = function ()
  92. {
  93. if (this.shapeImg != null)
  94. {
  95. this.addForeignData(this.shapeImg.type, this.shapeImg.id);
  96. }
  97. };
  98. /**
  99. * Function: newPage
  100. *
  101. * Start a new page.
  102. */
  103. mxVsdxCanvas2D.prototype.newPage = function ()
  104. {
  105. this.images = [];
  106. };
  107. /**
  108. * Function: newPage
  109. *
  110. * Start a new page.
  111. */
  112. mxVsdxCanvas2D.prototype.getShapeType = function ()
  113. {
  114. return this.shapeType;
  115. };
  116. /**
  117. * Function: getShapeGeo
  118. *
  119. * return the current geo section.
  120. */
  121. mxVsdxCanvas2D.prototype.getShapeGeo = function ()
  122. {
  123. return this.geoSec;
  124. };
  125. /**
  126. * Function: createCellElemScaled
  127. *
  128. * Creates a cell element and scale the value.
  129. */
  130. mxVsdxCanvas2D.prototype.createCellElemScaled = function (name, val, formula)
  131. {
  132. return this.createCellElem(name, val / VsdxExport.prototype.CONVERSION_FACTOR, formula);
  133. };
  134. /**
  135. * Function: createCellElem
  136. *
  137. * Creates a cell element.
  138. */
  139. mxVsdxCanvas2D.prototype.createCellElem = function (name, val, formula)
  140. {
  141. var cell = this.xmlDoc.createElement("Cell");
  142. cell.setAttribute("N", name);
  143. cell.setAttribute("V", val);
  144. if (formula) cell.setAttribute("F", formula);
  145. return cell;
  146. };
  147. mxVsdxCanvas2D.prototype.createRowRel = function(type, index, x, y, a, b, c , d)
  148. {
  149. var row = this.xmlDoc.createElement("Row");
  150. row.setAttribute("T", type);
  151. row.setAttribute("IX", index);
  152. row.appendChild(this.createCellElem("X", x));
  153. row.appendChild(this.createCellElem("Y", y));
  154. if (a != null) row.appendChild(this.createCellElem("A", a));
  155. if (b != null) row.appendChild(this.createCellElem("B", b));
  156. if (c != null) row.appendChild(this.createCellElem("C", c));
  157. if (d != null) row.appendChild(this.createCellElem("D", d));
  158. return row;
  159. };
  160. /**
  161. * Function: begin
  162. *
  163. * Extends superclass to create path.
  164. */
  165. mxVsdxCanvas2D.prototype.begin = function()
  166. {
  167. if (this.geoStepIndex > 1) this.createGeoSec();
  168. };
  169. /**
  170. * Function: rect
  171. *
  172. * Private helper function to create SVG elements
  173. */
  174. mxVsdxCanvas2D.prototype.rect = function(x, y, w, h)
  175. {
  176. if (this.geoStepIndex > 1) this.createGeoSec();
  177. var s = this.state;
  178. w = w * s.scale;
  179. h = h * s.scale;
  180. var geo = this.xmGeo;
  181. x = ((x - geo.x + s.dx) * s.scale) /w;
  182. y = ((geo.height - y + geo.y - s.dy) * s.scale) /h;
  183. this.geoSec.appendChild(this.createRowRel("RelMoveTo", this.geoStepIndex++, x, y));
  184. this.geoSec.appendChild(this.createRowRel("RelLineTo", this.geoStepIndex++, x + 1, y));
  185. this.geoSec.appendChild(this.createRowRel("RelLineTo", this.geoStepIndex++, x + 1, y - 1));
  186. this.geoSec.appendChild(this.createRowRel("RelLineTo", this.geoStepIndex++, x, y - 1));
  187. this.geoSec.appendChild(this.createRowRel("RelLineTo", this.geoStepIndex++, x, y));
  188. };
  189. /**
  190. * Function: roundrect
  191. *
  192. * Private helper function to create SVG elements
  193. */
  194. mxVsdxCanvas2D.prototype.roundrect = function(x, y, w, h, dx, dy)
  195. {
  196. this.rect(x, y, w, h);
  197. //TODO this assume dx and dy are equal and only one rounding is needed
  198. this.shape.appendChild(this.createCellElemScaled("Rounding", dx));
  199. };
  200. /**
  201. * Function: ellipse
  202. *
  203. * Private helper function to create SVG elements
  204. */
  205. mxVsdxCanvas2D.prototype.ellipse = function(x, y, w, h)
  206. {
  207. if (this.geoStepIndex > 1) this.createGeoSec();
  208. var s = this.state;
  209. w = w * s.scale;
  210. h = h * s.scale;
  211. var geo = this.xmGeo;
  212. var gh = geo.height * s.scale;
  213. var gw = geo.width * s.scale;
  214. x = (x - geo.x + s.dx) * s.scale;
  215. y = gh + (-y + geo.y - s.dy) * s.scale;
  216. var hr = h/gh;
  217. var wr = w/gw;
  218. this.geoSec.appendChild(this.createRowRel("RelMoveTo", this.geoStepIndex++, x/gw, y/gh - hr * 0.5));
  219. var row = this.createRowRel("RelEllipticalArcTo", this.geoStepIndex++, x/gw, y/gh - hr * 0.5001, wr * 0.5 + x/gw, y/gh - hr, 0);
  220. row.appendChild(this.createCellElem("D", w/h, "Width/Height*"+(wr/hr)));
  221. this.geoSec.appendChild(row);
  222. };
  223. /**
  224. * Function: moveTo
  225. *
  226. * Moves the current path the given point.
  227. *
  228. * Parameters:
  229. *
  230. * x - Number that represents the x-coordinate of the point.
  231. * y - Number that represents the y-coordinate of the point.
  232. */
  233. mxVsdxCanvas2D.prototype.moveTo = function(x, y)
  234. {
  235. //MoveTo inside a geo usually produce incorrect fill
  236. if (this.geoStepIndex > 1) this.createGeoSec();
  237. this.lastMoveToX = x;
  238. this.lastMoveToY = y;
  239. this.lastX = x;
  240. this.lastY = y;
  241. var geo = this.xmGeo;
  242. var s = this.state;
  243. x = (x - geo.x + s.dx) * s.scale;
  244. y = (geo.height - y + geo.y - s.dy) * s.scale;
  245. var h = geo.height * s.scale;
  246. var w = geo.width * s.scale;
  247. this.geoSec.appendChild(this.createRowRel("RelMoveTo", this.geoStepIndex++, x/w, y/h));
  248. };
  249. /**
  250. * Function: lineTo
  251. *
  252. * Draws a line to the given coordinates.
  253. *
  254. * Parameters:
  255. *
  256. * x - Number that represents the x-coordinate of the endpoint.
  257. * y - Number that represents the y-coordinate of the endpoint.
  258. */
  259. mxVsdxCanvas2D.prototype.lineTo = function(x, y)
  260. {
  261. this.lastX = x;
  262. this.lastY = y;
  263. var geo = this.xmGeo;
  264. var s = this.state;
  265. x = (x - geo.x + s.dx) * s.scale;
  266. y = (geo.height - y + geo.y - s.dy) * s.scale;
  267. var h = geo.height * s.scale;
  268. var w = geo.width * s.scale;
  269. this.geoSec.appendChild(this.createRowRel("RelLineTo", this.geoStepIndex++, x/w, y/h));
  270. };
  271. /**
  272. * Function: quadTo
  273. *
  274. * Adds a quadratic curve to the current path.
  275. *
  276. * Parameters:
  277. *
  278. * x1 - Number that represents the x-coordinate of the control point.
  279. * y1 - Number that represents the y-coordinate of the control point.
  280. * x2 - Number that represents the x-coordinate of the endpoint.
  281. * y2 - Number that represents the y-coordinate of the endpoint.
  282. */
  283. mxVsdxCanvas2D.prototype.quadTo = function(x1, y1, x2, y2)
  284. {
  285. this.lastX = x2;
  286. this.lastY = y2;
  287. var s = this.state;
  288. var geo = this.xmGeo;
  289. var h = geo.height * s.scale;
  290. var w = geo.width * s.scale;
  291. x1 = (x1 - geo.x + s.dx) * s.scale;
  292. y1 = (geo.height - y1 + geo.y - s.dy) * s.scale;
  293. x2 = (x2 - geo.x + s.dx) * s.scale;
  294. y2 = (geo.height - y2 + geo.y - s.dy) * s.scale;
  295. x1 = x1 / w;
  296. y1 = y1 / h;
  297. x2 = x2 / w;
  298. y2 = y2 / h;
  299. this.geoSec.appendChild(this.createRowRel("RelQuadBezTo", this.geoStepIndex++, x2, y2, x1, y1));
  300. };
  301. /**
  302. * Function: curveTo
  303. *
  304. * Adds a bezier curve to the current path.
  305. *
  306. * Parameters:
  307. *
  308. * x1 - Number that represents the x-coordinate of the first control point.
  309. * y1 - Number that represents the y-coordinate of the first control point.
  310. * x2 - Number that represents the x-coordinate of the second control point.
  311. * y2 - Number that represents the y-coordinate of the second control point.
  312. * x3 - Number that represents the x-coordinate of the endpoint.
  313. * y3 - Number that represents the y-coordinate of the endpoint.
  314. */
  315. mxVsdxCanvas2D.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
  316. {
  317. this.lastX = x3;
  318. this.lastY = y3;
  319. var s = this.state;
  320. var geo = this.xmGeo;
  321. var h = geo.height * s.scale;
  322. var w = geo.width * s.scale;
  323. x1 = (x1 - geo.x + s.dx) * s.scale;
  324. y1 = (geo.height - y1 + geo.y - s.dy) * s.scale;
  325. x2 = (x2 - geo.x + s.dx) * s.scale;
  326. y2 = (geo.height - y2 + geo.y - s.dy) * s.scale;
  327. x3 = (x3 - geo.x + s.dx) * s.scale;
  328. y3 = (geo.height - y3 + geo.y - s.dy) * s.scale;
  329. x1 = x1 / w;
  330. y1 = y1 / h;
  331. x2 = x2 / w;
  332. y2 = y2 / h;
  333. x3 = x3 / w;
  334. y3 = y3 / h;
  335. this.geoSec.appendChild(this.createRowRel("RelCubBezTo", this.geoStepIndex++, x3, y3, x1, y1, x2, y2));
  336. };
  337. /**
  338. * Function: close
  339. *
  340. * Closes the current path.
  341. */
  342. mxVsdxCanvas2D.prototype.close = function()
  343. {
  344. //Closing with a line if last point != last MoveTo point
  345. if (this.lastMoveToX != this.lastX || this.lastMoveToY != this.lastY)
  346. this.lineTo(this.lastMoveToX, this.lastMoveToY);
  347. };
  348. /**
  349. * Function: addForeignData
  350. *
  351. * Add ForeignData to current shape using last image in the images array
  352. */
  353. mxVsdxCanvas2D.prototype.addForeignData = function(type, index)
  354. {
  355. var foreignData = this.xmlDoc.createElement("ForeignData");
  356. foreignData.setAttribute("ForeignType", "Bitmap");
  357. type = type.toUpperCase();
  358. if (type != "BMP")
  359. foreignData.setAttribute("CompressionType", type);
  360. var rel = this.xmlDoc.createElement("Rel");
  361. rel.setAttribute("r:id", "rId" + index);
  362. foreignData.appendChild(rel);
  363. this.shape.appendChild(foreignData);
  364. this.shapeType = "Foreign";
  365. };
  366. /**
  367. * Function: image
  368. *
  369. * Add image to vsdx file as a media (Foreign Object)
  370. */
  371. mxVsdxCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
  372. {
  373. //TODO image reusing, if the same image is used more than once, reuse it. Applicable for URLs specifically (but can also be applied to embedded ones)
  374. var imgName = "image" + (this.images.length + 1) + ".";
  375. var type;
  376. if (src.indexOf("data:") == 0)
  377. {
  378. var p = src.indexOf("base64,");
  379. var base64 = src.substring(p + 7); //7 is the length of "base64,"
  380. type = src.substring(11, p-1); //5 is the length of "data:image/"
  381. imgName += type;
  382. this.zip.file("visio/media/" + imgName, base64, {base64: true});
  383. }
  384. else if (window.XMLHttpRequest) //URL src, fetch it
  385. {
  386. src = this.converter.convert(src);
  387. this.filesLoading++;
  388. var that = this;
  389. var p = src.lastIndexOf(".");
  390. type = src.substring(p+1);
  391. imgName += type;
  392. //The old browsers binary workaround doesn't work with jszip and converting to base64 encoding doesn't work also
  393. var xhr = new XMLHttpRequest();
  394. xhr.open('GET', src, true);
  395. xhr.responseType = 'arraybuffer';
  396. xhr.onreadystatechange = function(e)
  397. {
  398. if (this.readyState == 4 && this.status == 200) {
  399. that.zip.file("visio/media/" + imgName, this.response);
  400. that.filesLoading--;
  401. }
  402. };
  403. xhr.send();
  404. }
  405. this.images.push(imgName);
  406. //TODO can a shape has more than one image?
  407. this.shapeImg = {type: type, id: this.images.length};
  408. //TODO support these!
  409. aspect = (aspect != null) ? aspect : true;
  410. flipH = (flipH != null) ? flipH : false;
  411. flipV = (flipV != null) ? flipV : false;
  412. var s = this.state;
  413. w = w * s.scale;
  414. h = h * s.scale;
  415. var geo = this.xmGeo;
  416. x = (x - geo.x + s.dx) * s.scale;
  417. y = (geo.height - y + geo.y - s.dy) * s.scale;
  418. this.shape.appendChild(this.createCellElemScaled("ImgOffsetX", x));
  419. this.shape.appendChild(this.createCellElemScaled("ImgOffsetY", y - h));
  420. this.shape.appendChild(this.createCellElemScaled("ImgWidth", w));
  421. this.shape.appendChild(this.createCellElemScaled("ImgHeight", h));
  422. // var s = this.state;
  423. // x += s.dx;
  424. // y += s.dy;
  425. //
  426. // if (s.alpha < 1 || s.fillAlpha < 1)
  427. // {
  428. // node.setAttribute('opacity', s.alpha * s.fillAlpha);
  429. // }
  430. //
  431. // var tr = this.state.transform || '';
  432. //
  433. // if (flipH || flipV)
  434. // {
  435. // var sx = 1;
  436. // var sy = 1;
  437. // var dx = 0;
  438. // var dy = 0;
  439. //
  440. // if (flipH)
  441. // {
  442. // sx = -1;
  443. // dx = -w - 2 * x;
  444. // }
  445. //
  446. // if (flipV)
  447. // {
  448. // sy = -1;
  449. // dy = -h - 2 * y;
  450. // }
  451. //
  452. // // Adds image tansformation to existing transform
  453. // tr += 'scale(' + sx + ',' + sy + ')translate(' + (dx * s.scale) + ',' + (dy * s.scale) + ')';
  454. // }
  455. //
  456. // if (tr.length > 0)
  457. // {
  458. // node.setAttribute('transform', tr);
  459. // }
  460. //
  461. // if (!this.pointerEvents)
  462. // {
  463. // node.setAttribute('pointer-events', 'none');
  464. // }
  465. };
  466. /**
  467. * Function: text
  468. *
  469. * Paints the given text. Possible values for format are empty string for
  470. * plain text and html for HTML markup. Background and border color as well
  471. * as clipping is not available in plain text labels for VML. HTML labels
  472. * are not available as part of shapes with no foreignObject support in SVG
  473. * (eg. IE9, IE10).
  474. *
  475. * Parameters:
  476. *
  477. * x - Number that represents the x-coordinate of the text.
  478. * y - Number that represents the y-coordinate of the text.
  479. * w - Number that represents the available width for the text or 0 for automatic width.
  480. * h - Number that represents the available height for the text or 0 for automatic height.
  481. * str - String that specifies the text to be painted.
  482. * align - String that represents the horizontal alignment.
  483. * valign - String that represents the vertical alignment.
  484. * wrap - Boolean that specifies if word-wrapping is enabled. Requires w > 0.
  485. * format - Empty string for plain text or 'html' for HTML markup.
  486. * overflow - Specifies the overflow behaviour of the label. Requires w > 0 and/or h > 0.
  487. * clip - Boolean that specifies if the label should be clipped. Requires w > 0 and/or h > 0.
  488. * rotation - Number that specifies the angle of the rotation around the anchor point of the text.
  489. * dir - Optional string that specifies the text direction. Possible values are rtl and lrt.
  490. */
  491. mxVsdxCanvas2D.prototype.text = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
  492. {
  493. if (this.textEnabled && str != null)
  494. {
  495. if (mxUtils.isNode(str))
  496. {
  497. str = mxUtils.getOuterHtml(str);
  498. }
  499. //TODO support HTML text formatting and remaining attributes
  500. if (format == 'html')
  501. {
  502. if (mxUtils.getValue(this.cellState.style, 'nl2Br', '1') != '0')
  503. {
  504. // Removes newlines from HTML and converts breaks to newlines
  505. // to match the HTML output in plain text
  506. str = str.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
  507. }
  508. // Removes HTML tags
  509. if (this.html2txtDiv == null)
  510. this.html2txtDiv = document.createElement('div');
  511. this.html2txtDiv.innerHTML = str;
  512. str = mxUtils.extractTextWithWhitespace(this.html2txtDiv.childNodes);
  513. }
  514. var s = this.state;
  515. var geo = this.xmGeo;
  516. var fontSize = this.cellState.style["fontSize"];
  517. var fontFamily = this.cellState.style["fontFamily"];
  518. var strRect = mxUtils.getSizeForString(str, fontSize, fontFamily);
  519. var wShift = 0;
  520. var hShift = 0;
  521. switch(align)
  522. {
  523. case "right": wShift = strRect.width/2; break;
  524. //case "center": wShift = 0; break;
  525. case "left": wShift = -strRect.width/2; break;
  526. }
  527. switch(valign)
  528. {
  529. case "top": hShift = strRect.height/2; break;
  530. // case "middle": hShift = 0; break;
  531. case "bottom": hShift = -strRect.height/2; break;
  532. }
  533. w = w * s.scale;
  534. h = h * s.scale;
  535. h = Math.max(h, strRect.height);
  536. w = Math.max(w, strRect.width);
  537. x = (x - geo.x + s.dx) * s.scale;
  538. y = (geo.height - y + geo.y - s.dy) * s.scale;
  539. var hw = w/2, hh = h/2;
  540. this.shape.appendChild(this.createCellElemScaled("TxtPinX", x));
  541. this.shape.appendChild(this.createCellElemScaled("TxtPinY", y));
  542. this.shape.appendChild(this.createCellElemScaled("TxtWidth", w));
  543. this.shape.appendChild(this.createCellElemScaled("TxtHeight", h));
  544. this.shape.appendChild(this.createCellElemScaled("TxtLocPinX", hw + wShift));
  545. this.shape.appendChild(this.createCellElemScaled("TxtLocPinY", hh + hShift));
  546. if (rotation != 0)
  547. this.shape.appendChild(this.createCellElemScaled("TxtAngle", (360 - rotation) * Math.PI / 180));
  548. //TODO Currently, we support a single text block formatting. Later, HTML label should be analysed and split into parts
  549. var charSect = this.xmlDoc.createElement("Section");
  550. charSect.setAttribute('N', 'Character');
  551. var charRow = this.xmlDoc.createElement("Row");
  552. charRow.setAttribute('IX', 0);
  553. var fontColor = this.cellState.style["fontColor"];
  554. if (fontColor) charRow.appendChild(this.createCellElem("Color", fontColor));
  555. if (fontSize) charRow.appendChild(this.createCellElemScaled("Size", fontSize * 0.97)); //the magic number 0.97 is needed such that text do not overflow
  556. if (fontFamily) charRow.appendChild(this.createCellElem("Font", fontFamily));
  557. charSect.appendChild(charRow);
  558. this.shape.appendChild(charSect);
  559. var text = this.xmlDoc.createElement("Text");
  560. var cp = this.xmlDoc.createElement("cp");
  561. cp.setAttribute('IX', 0);
  562. text.appendChild(cp);
  563. text.textContent = str;
  564. this.shape.appendChild(text);
  565. // elem.setAttribute('wrap', (wrap) ? '1' : '0');
  566. //
  567. // if (format == null)
  568. // {
  569. // format = '';
  570. // }
  571. //
  572. // elem.setAttribute('format', format);
  573. //
  574. // if (overflow != null)
  575. // {
  576. // elem.setAttribute('overflow', overflow);
  577. // }
  578. //
  579. // if (clip != null)
  580. // {
  581. // elem.setAttribute('clip', (clip) ? '1' : '0');
  582. // }
  583. //
  584. // if (dir != null)
  585. // {
  586. // elem.setAttribute('dir', dir);
  587. // }
  588. }
  589. };
  590. /**
  591. * Function: rotate
  592. *
  593. * Sets the rotation of the canvas. Note that rotation cannot be concatenated.
  594. */
  595. mxVsdxCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
  596. {
  597. //Vsdx has flipX/Y support separate from rotation
  598. if (theta != 0)
  599. {
  600. var s = this.state;
  601. cx += s.dx;
  602. cy += s.dy;
  603. cx *= s.scale;
  604. cy *= s.scale;
  605. this.shape.appendChild(this.createCellElem("Angle", (360 - theta) * Math.PI / 180));
  606. s.rotation = s.rotation + theta;
  607. s.rotationCx = cx;
  608. s.rotationCy = cy;
  609. }
  610. };
  611. /**
  612. * Function: stroke
  613. *
  614. * Paints the outline of the current drawing buffer.
  615. */
  616. mxVsdxCanvas2D.prototype.stroke = function()
  617. {
  618. this.geoSec.appendChild(this.createCellElem("NoFill", "1"));
  619. this.geoSec.appendChild(this.createCellElem("NoLine", "0"));
  620. };
  621. /**
  622. * Function: fill
  623. *
  624. * Fills the current drawing buffer.
  625. */
  626. mxVsdxCanvas2D.prototype.fill = function()
  627. {
  628. this.geoSec.appendChild(this.createCellElem("NoFill", "0"));
  629. this.geoSec.appendChild(this.createCellElem("NoLine", "1"));
  630. };
  631. /**
  632. * Function: fillAndStroke
  633. *
  634. * Fills the current drawing buffer and its outline.
  635. */
  636. mxVsdxCanvas2D.prototype.fillAndStroke = function()
  637. {
  638. this.geoSec.appendChild(this.createCellElem("NoFill", "0"));
  639. this.geoSec.appendChild(this.createCellElem("NoLine", "0"));
  640. };