mxVsdxCanvas2D.js 19 KB

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