我在画布中添加了一个IText对象,我动态地更改了文本中每个单词的样式,这里样式正在更新,但是我无法清除以前应用的样式。因此,每次在以前的
中覆盖新样式function updateStyle(){
clearItextStyle();
var letterArray =getLetterIndex(iText.getText());
var counter=1;
for(var i=0;i<selectionArr.length;i=i+2){
iText.setSelectionStart(selectionArr[i]);
iText.setSelectionEnd(selectionArr[i+1]+1);
switch(counter){
case 1:
iText.setSelectionStyles({"textDecoration":"underline"});
break;
case 2:
iText.setSelectionStyles({"textDecoration":"overline"});
break;
case 3:
iText.setSelectionStyles({"textDecoration":"line-through"});
break;
}
counter++;
if(counter>3){
counter=0;
}
}
canvas.renderAll();
}
function clearItextStyle(){
text.setSelectionStart(0);
text.setSelectionEnd(iText.getText().length-1);
text.setSelectionStyles(null);
canvas.renderAll();
}
答案 0 :(得分:2)
function clearItextStyle(){
text.remove();
text=addIText(); // Initialize IText object here again
canvas.add(text);
canvas.renderAll();
}
答案 1 :(得分:0)
清除&#34; textDecoration&#34;对于IText元素的样式,您可以将该样式设置为&#34; none&#34;,例如
text.setSelectionStyles({"textDecoration":"none"});
答案 2 :(得分:0)
重置itext对象的样式:
itext.styles = { }; // -> space is important
canvas.renderAll();
然后你可以添加样式。