3

我想在我的项目中使用svg-edit插件。现在我想为曲线文本创建扩展,例如:

svgEditor.addExtension("Curve text!", function() {'use strict';
        return {
            name: "Curve text",
            svgicons: svgEditor.curConfig.extPath + "text_curve-icon.xml",

            buttons: [{
                id: "text_curve", 
                type: "mode", 
                title: "Curve the text", 
                events: {
                    'click': function() {
                        svgCanvas.setMode("text_curve");

                        var textElement = $(svgCanvas.getSelectedElems()[0]);

                        var textPath =  '<text>' +
                                        '   <textPath xlink:href="#relativeCurve">' +
                                            $(svgCanvas.getSelectedElems()[0]).text() +
                                        '   </textPath>' +
                                        '</text>';
                        $('#svgcontent').prepend('<defs><path d="m0,350c100,-100 200,-200 300,-200c100,0 200,200 300,200c100,0 200,-200 300,-200" id="relativeCurve"/></defs>');
                        $(textElement).replaceWith(textPath);
                    }
                }
            }],
            mouseDown: function() {
                if(svgCanvas.getMode() == "text_curve") {
                    return {started: true};
                }
            },

            mouseUp: function(opts) {
                if(svgCanvas.getMode() == "text_curve") {
                }
            }
        };
});

但它不起作用,我该如何创建它?

4

0 回答 0