简体   繁体   English

SVG在Fabric JS中不包含文本装饰属性

[英]SVG doesn't contain the text decoration property in fabric js

I am applying these text decoration properties like underline, overline, line through to the text object on canvas, but resulted SVG doesn't have that properties. 我将这些文本修饰属性(例如下划线,上划线,直行)应用到画布上的文本对象,但导致SVG没有该属性。

Code

$('.text_decoration').click(function () {
    var status;
    $( this ).toggleClass( 'highlight' );
    if($(this).hasClass('highlight'))
    {
        status = true;
    }
    else
    {
        status = false;
    }


    //var text_decoration = $(this).val();
    var text_decoration = $(this).attr('data-action');
    var tObj = canvas.getActiveObject();
    //Check that text is selected
    if(tObj==undefined)
    {
        alert('Please select a Text');
        return false;
    }

    if(text_decoration=='underline')
    {
        tObj.set({
            underline: status
        });
    }
    else if(text_decoration=='linethrough')
    {
        tObj.set({
            linethrough: status
        });
    }
    else if(text_decoration=='overline')
    {
        tObj.set({
            overline: status
        });
    }
    canvas.renderAll();
});

Codepen Codepen

https://codepen.io/dhavalsisodiya/pen/EEbXvJ https://codepen.io/dhavalsisodiya/pen/EEbXvJ

Steps 脚步

1) Add text 1)添加文字
2) Then apply the underline, overline and line through property 2)然后应用下划线,上划线和直通属性
3) Click on "Show SVG" button. 3)点击“显示SVG”按钮。

Now the resulted svg doesn't have those properties, so how to resolve it? 现在生成的svg没有这些属性,那么如何解决呢?

Your codepen is linked to a beta version of fabricJS, that was transitioning from 1.x api to api 2. 您的Codepen已链接到beta版本的fabricJS,该版本已从1.x api过渡到api 2。

Please update to latest from version 2, and the snippet will work 请从版本2更新到最新版本,该代码段将起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM