标签:
1、
// ZC: Draw自己画图的 基类 // ZC: 当做静态类来使用 function TdrawSvgA() {} TdrawSvgA.prototype = { IfExist_byId : function(_svgdoc, _strId) { if (! _strId) return null; return _svgdoc.getElementById(_strId); }, // *** DrawG : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var g = _svgdoc.createElementNS(_strSvgNS, "g"); _SVGElementParent.appendChild(g); if (_strId) g.setAttribute("id", _strId); return g; }, DrawLine : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId, _iX1, _iY1, _iX2, _iY2) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var line = _svgdoc.createElementNS(_strSvgNS, "line"); _SVGElementParent.appendChild(line); if (_strId) line.setAttribute("id", _strId); line.setAttribute("x1", _iX1+""); line.setAttribute("y1", _iY1+""); line.setAttribute("x2", _iX2+""); line.setAttribute("y2", _iY2+""); return line; }, DrawPolyLine : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId, _strPoints) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var polyline = _svgdoc.createElementNS(_strSvgNS, "polyline"); _SVGElementParent.appendChild(polyline); if (_strId) polyline.setAttribute("id", _strId); polyline.setAttribute("points", _strPoints); return polyline; }, DrawRect : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId, _dX, _dY, _dWidth, _dHeight) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var rect01 = _svgdoc.createElementNS(_strSvgNS, "rect"); _SVGElementParent.appendChild(rect01); if (_strId) rect01.setAttribute("id", _strId); rect01.setAttribute("x", _dX+""); rect01.setAttribute("y", _dY+""); rect01.setAttribute("width", _dWidth+""); rect01.setAttribute("height", _dHeight+""); return rect01; }, DrawUse : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId, _strSvgNsXlink, _strXlinkHref, _iX, _iY, _iWidth, _iHeight) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var use01 = _svgdoc.createElementNS(_strSvgNS, "use"); _SVGElementParent.appendChild(use01); if (_strId) use01.setAttribute("id", _strId); use01.setAttributeNS(_strSvgNsXlink, "xlink:href", _strXlinkHref); //use01.setAttribute("xlink:href", _strXlinkHref); use01.setAttribute("x", _iX+""); use01.setAttribute("y", _iY+""); use01.setAttribute("width", _iWidth+""); use01.setAttribute("height",_iHeight+""); return use01; }, DrawSymbol : function(_svgdoc, _strSvgNS, _SVGElementParent, _strSymbolId/*, _strSymbolText*/) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strSymbolId) if (diceleExist) return diceleExist; // *** var symbol = _svgdoc.createElementNS(_strSvgNS, "symbol"); // ... 待续 return symbol; }, // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // ZC: 画 <text/> //<text font-size="16" font-family="SimSun" stroke="rgb(0, 0, 0)" stroke-width="0.533333333333333" writing-mode="tb" //x="2115.86160000041" y="1122.78820000291" //transform="rotate(360.000000, 2115.861600, 1122.788200)" class=".Text">H213</text> DrawText_01 : function(_svgdoc, _strSvgNS, _SVGElementParent, _strId, _iX, _iY, _strFontSize, _strFontFamily, _strWritingMode, _strTextContent) { var diceleExist = TdrawSvgA.prototype.IfExist_byId.call(this, _strId) if (diceleExist) return diceleExist; // *** var text01 = _svgdoc.createElementNS(_strSvgNS, "text"); _SVGElementParent.appendChild(text01); if (_strId) text01.setAttribute("id", _strId); text01.setAttribute("x", _iX+""); text01.setAttribute("y", _iY+""); text01.setAttribute("font-size", _strFontSize); text01.setAttribute("font-family", _strFontFamily); if (_strWritingMode) text01.setAttribute("writing-mode", _strWritingMode); //text01.setAttribute("", ""); //console.log("ADrawText_01 --> _strTextContent : "+_strTextContent); text01.textContent = _strTextContent; //text01.innerHTML = _strTextContent; return text01; }, // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** DrawStroke : function(_SVGElement, _strStroke, _iStrokeWidth) { if (_strStroke) _SVGElement.setAttribute("stroke", _strStroke); if (_iStrokeWidth) _SVGElement.setAttribute("stroke-width", _iStrokeWidth+""); }, DrawFill : function(_SVGElement, _strFill, _iFillOpacity) { if (_strFill) _SVGElement.setAttribute("fill", _strFill); if (_iFillOpacity) _SVGElement.setAttribute("fill-opacity", _iFillOpacity+""); }, DrawTransform : function(_SVGElement, _strTransform) { if (_strTransform) _SVGElement.setAttribute("transform", _strTransform); }, };
2、
标签:
原文地址:http://www.cnblogs.com/h5skill/p/5416460.html