1 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @package phpMyAdmin-Designer
10 if (!window
.all
) // if IE
12 document
.attachEvent("onreadystatechange", // document load
15 if (document
.readyState
== "complete")
17 var el
= document
.getElementById("canvas");
18 var outerHTML
= el
.outerHTML
;
19 var newEl
= document
.createElement(outerHTML
);
20 el
.parentNode
.replaceChild(newEl
, el
);
22 el
.getContext = function () {
23 if (this.cont
) return this.cont
;
24 return this.cont
= new PMD_2D(this);
27 el
.style
.width
= el
.attributes
.width
.nodeValue
+ "px";
28 el
.style
.height
= el
.attributes
.height
.nodeValue
+ "px";
33 //*****************************************************************************************************
35 function convert_style(str
) {
37 m
= str
.match(/.*\((\d*),(\d*),(\d*),(\d*)\)/);
38 for(var i
= 1; i
<=3; i
++ )
39 m
[i
] = (m
[i
]*1).toString(16).length
< 2 ? '0' + (m
[i
]*1).toString(16) : (m
[i
]*1).toString(16);
40 return ['#' + m
[1] + m
[2] + m
[3], 1];
42 //------------------------------------------------------------------------------
45 this.pmd_arr
= Array();
50 this.closePath = function() {
51 this.pmd_arr
.push({type
: "close"});
54 this.clearRect = function() {
55 this.element_
.innerHTML
= "";
59 this.beginPath = function() {
63 this.moveTo = function(aX
, aY
) {
64 this.pmd_arr
.push({type
: "moveTo", x
: aX
, y
: aY
});
67 this.lineTo = function(aX
, aY
) {
68 this.pmd_arr
.push({type
: "lineTo", x
: aX
, y
: aY
});
71 this.arc = function(aX
, aY
, aRadius
, aStartAngle
, aEndAngle
, aClockwise
) {
74 aStartAngle
= aEndAngle
;
78 var xStart
= aX
+ (Math
.cos(aStartAngle
) * aRadius
);
79 var yStart
= aY
+ (Math
.sin(aStartAngle
) * aRadius
);
81 var xEnd
= aX
+ (Math
.cos(aEndAngle
) * aRadius
);
82 var yEnd
= aY
+ (Math
.sin(aEndAngle
) * aRadius
);
84 this.pmd_arr
.push({type
: "arc", x
: aX
, y
: aY
,
85 radius
: aRadius
, xStart
: xStart
, yStart
: yStart
, xEnd
: xEnd
, yEnd
: yEnd
});
88 this.rect = function(aX
, aY
, aW
, aH
) {
90 this.lineTo(aX
+ aW
, aY
);
91 this.lineTo(aX
+ aW
, aY
+ aH
);
92 this.lineTo(aX
, aY
+ aH
);
96 this.fillRect = function(aX
, aY
, aW
, aH
) {
99 this.lineTo(aX
+ aW
, aY
);
100 this.lineTo(aX
+ aW
, aY
+ aH
);
101 this.lineTo(aX
, aY
+ aH
);
106 this.stroke = function(aFill
) {
108 var a
= convert_style(aFill
? this.fillStyle
: this.strokeStyle
);
112 ' fillcolor="', color
, '"',
113 ' filled="', Boolean(aFill
), '"',
114 ' style="position:absolute;width:10;height:10;"',
115 ' coordorigin="0 0" coordsize="10 10"',
116 ' stroked="', !aFill
, '"',
117 ' strokeweight="', this.lineWidth
, '"',
118 ' strokecolor="', color
, '"',
121 for (var i
= 0; i
< this.pmd_arr
.length
; i
++) {
122 var p
= this.pmd_arr
[i
];
124 if (p
.type
== "moveTo") {
126 Str
.push(Math
.floor(p
.x
), ",",Math
.floor(p
.y
));
127 } else if (p
.type
== "lineTo") {
129 Str
.push(Math
.floor(p
.x
), ",",Math
.floor(p
.y
));
130 } else if (p
.type
== "close") {
132 } else if (p
.type
== "arc") {
134 Str
.push(Math
.floor(p
.x
- p
.radius
), ",",
135 Math
.floor(p
.y
- p
.radius
), " ",
136 Math
.floor(p
.x
+ p
.radius
), ",",
137 Math
.floor(p
.y
+ p
.radius
), " ",
138 Math
.floor(p
.xStart
), ",", Math
.floor(p
.yStart
), " ",
139 Math
.floor(p
.xEnd
), ",", Math
.floor(p
.yEnd
));
144 Str
.push("</v:shape>");
146 this.element_
.insertAdjacentHTML("beforeEnd", Str
.join(""));
147 this.pmd_arr
= Array();