0
這是一個在線svg編輯,它有一個文本編輯,我可以在JSVGCanvas中做到這一點?JSVGCanvas中的文本編輯
http://svg-edit.googlecode.com/svn-history/r1771/trunk/editor/svg-editor.html
這是一個在線svg編輯,它有一個文本編輯,我可以在JSVGCanvas中做到這一點?JSVGCanvas中的文本編輯
http://svg-edit.googlecode.com/svn-history/r1771/trunk/editor/svg-editor.html
起初你JSVGCanvas應該顯示空SVG是這樣的:
DOMImplementation imp = SVGDOMImplementation.getDOMImplementation();
DocumentType type = imp.createDocumentType(SVGConstants.SVG_PUBLIC_ID, SVGConstants.SVG_SYSTEM_ID, null);
Document svgDoc = imp.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", type);
JSVGCanvas canvas = new SVGCanvas(new SVGUserAgentAdapter(), true, true);
canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
canvas.setSVGDocument(svgDoc);
添加鼠標和鍵盤監聽器用於獲取x,y和文字。創建一個文本元素之後:
Element textElement = svgDoc.createElementNS(svgNS, "text");
textElement.setAttributeNS(null, "x", x);
textElement.setAttributeNS(null, "y", y);
textElement.setTextContent(text);
svgDoc.getDocumentElement().appendChild(textElement);
選擇文本由textSelectionManager從JSVGCanvas提供:
canvas.getTextSelectionManager()
沒有人知道嗎?我非常擔心! – oliver