Search code examples
fabricjs

Fabric JS Rich Text with IText or TextBox


I saw rich text examples on fabric js http://fabricjs.com/test/misc/itext.html but I don't understand how we can handle it. Is there an example about it?

My purpose is to create a content like this: enter image description here


Solution

  • I found an example about it:

    var iText2 = new fabric.IText('hello\nworld', {
      left: 50,
      top: 50,
      fontFamily: 'Helvetica',
      fill: '#333',
      lineHeight: 1.1,
      styles: {
        0: {
          0: { textDecoration: 'underline', fontSize: 80 },
          1: { textBackgroundColor: 'red' }
        },
        1: {
          0: { textBackgroundColor: 'rgba(0,255,0,0.5)' },
          4: { fontSize: 20 }
        }
      }
    });