2015-11-30 30 views
0

我已經看到了如何使用此語法多種樣式應用到一個給定的iText對象的每行,每字符爲基礎的例子...FabricJS IText - 如何添加多種樣式的文本框?

var iTextSample = new fabric.IText('hello\nworld', { 
styles: { 
    0: { 
     0: { textDecoration: 'underline', fontSize: 80 }, 
     1: { textBackgroundColor: 'red' } 
    }, 
    1: { 
     0: { textBackgroundColor: 'rgba(0,255,0,0.5)' }, 
     4: { fontSize: 20 } 
    } 
    } 
}); 

小提琴這裏 - https://jsfiddle.net/tLy9eqj6/

是否有類似的語法只使用一組參數在一行內設置多個字符?例如,這將強調第1行的前5個字符...

var iTextSample = new fabric.IText('hello\nworld', { 
styles: { 
    0: { 
     [0,1,2,3,4]: { textDecoration: 'underline' } 
    } 
    } 
}); 

回答

0

不,還沒有(還)。

截至目前,fabricjs具有每個樣式字符或默認樣式屬性的回退。

你可以做的是優化你的風格,找出哪些是最常用的文本風格,將其分配給IText對象,然後以不同的方式設置幾個字符。