iecanvas.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. *
  4. * @package PhpMyAdmin-Designer
  5. */
  6. /**
  7. *
  8. */
  9. if (!window.all) // if IE
  10. {
  11. document.attachEvent("onreadystatechange", // document load
  12. function () {
  13. if (document.readyState == "complete") {
  14. var el = document.getElementById("canvas");
  15. var outerHTML = el.outerHTML;
  16. var newEl = document.createElement(outerHTML);
  17. el.parentNode.replaceChild(newEl, el);
  18. el = newEl;
  19. el.getContext = function () {
  20. if (this.cont) {
  21. return this.cont;
  22. }
  23. return this.cont = new PMD_2D(this);
  24. };
  25. el.style.width = el.attributes.width.nodeValue + "px";
  26. el.style.height = el.attributes.height.nodeValue + "px";
  27. }
  28. }
  29. );
  30. //*****************************************************************************************************
  31. function convert_style(str) {
  32. var m = [];
  33. m = str.match(/.*\((\d*),(\d*),(\d*),(\d*)\)/);
  34. for (var i = 1; i<=3; i++) {
  35. m[i] = (m[i]*1).toString(16).length < 2 ? '0' + (m[i]*1).toString(16) : (m[i]*1).toString(16);
  36. }
  37. return ['#' + m[1] + m[2] + m[3], 1];
  38. }
  39. //------------------------------------------------------------------------------
  40. function PMD_2D(th) {
  41. this.element_ = th;
  42. this.pmd_arr = [];
  43. this.strokeStyle;
  44. this.fillStyle;
  45. this.lineWidth;
  46. this.closePath = function() {
  47. this.pmd_arr.push({type: "close"});
  48. };
  49. this.clearRect = function() {
  50. this.element_.innerHTML = "";
  51. this.pmd_arr = [];
  52. };
  53. this.beginPath = function() {
  54. this.pmd_arr = [];
  55. };
  56. this.moveTo = function(aX, aY) {
  57. this.pmd_arr.push({type: "moveTo", x: aX, y: aY});
  58. };
  59. this.lineTo = function(aX, aY) {
  60. this.pmd_arr.push({type: "lineTo", x: aX, y: aY});
  61. };
  62. this.arc = function(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  63. if (!aClockwise) {
  64. var t = aStartAngle;
  65. aStartAngle = aEndAngle;
  66. aEndAngle = t;
  67. }
  68. var xStart = aX + (Math.cos(aStartAngle) * aRadius);
  69. var yStart = aY + (Math.sin(aStartAngle) * aRadius);
  70. var xEnd = aX + (Math.cos(aEndAngle) * aRadius);
  71. var yEnd = aY + (Math.sin(aEndAngle) * aRadius);
  72. this.pmd_arr.push({type: "arc", x: aX, y: aY,
  73. radius: aRadius, xStart: xStart, yStart: yStart, xEnd: xEnd, yEnd: yEnd});
  74. };
  75. this.rect = function(aX, aY, aW, aH) {
  76. this.moveTo(aX, aY);
  77. this.lineTo(aX + aW, aY);
  78. this.lineTo(aX + aW, aY + aH);
  79. this.lineTo(aX, aY + aH);
  80. this.closePath();
  81. };
  82. this.fillRect = function(aX, aY, aW, aH) {
  83. this.beginPath();
  84. this.moveTo(aX, aY);
  85. this.lineTo(aX + aW, aY);
  86. this.lineTo(aX + aW, aY + aH);
  87. this.lineTo(aX, aY + aH);
  88. this.closePath();
  89. this.stroke(true);
  90. };
  91. this.stroke = function(aFill) {
  92. var Str = [];
  93. var a = convert_style(aFill ? this.fillStyle : this.strokeStyle);
  94. var color = a[0];
  95. Str.push('<v:shape',
  96. ' fillcolor="', color, '"',
  97. ' filled="', Boolean(aFill), '"',
  98. ' style="position:absolute;width:10;height:10;"',
  99. ' coordorigin="0 0" coordsize="10 10"',
  100. ' stroked="', !aFill, '"',
  101. ' strokeweight="', this.lineWidth, '"',
  102. ' strokecolor="', color, '"',
  103. ' path="');
  104. for (var i = 0; i < this.pmd_arr.length; i++) {
  105. var p = this.pmd_arr[i];
  106. if (p.type == "moveTo") {
  107. Str.push(" m ");
  108. Str.push(Math.floor(p.x), ",",Math.floor(p.y));
  109. } else if (p.type == "lineTo") {
  110. Str.push(" l ");
  111. Str.push(Math.floor(p.x), ",",Math.floor(p.y));
  112. } else if (p.type == "close") {
  113. Str.push(" x ");
  114. } else if (p.type == "arc") {
  115. Str.push(" ar ");
  116. Str.push(Math.floor(p.x - p.radius), ",",
  117. Math.floor(p.y - p.radius), " ",
  118. Math.floor(p.x + p.radius), ",",
  119. Math.floor(p.y + p.radius), " ",
  120. Math.floor(p.xStart), ",", Math.floor(p.yStart), " ",
  121. Math.floor(p.xEnd), ",", Math.floor(p.yEnd));
  122. }
  123. }
  124. Str.push(' ">');
  125. Str.push("</v:shape>");
  126. this.element_.insertAdjacentHTML("beforeEnd", Str.join(""));
  127. this.pmd_arr = [];
  128. }
  129. }
  130. }