I am working on fabric js application & I need to increase/decrease the font size when we resize the font with mouse
my tried code
While perhaps not the best approach (I'm new to Fabric), this is working for me with version 4.3.0:
canvas.on('text:changed', function (e) {
console.log('Text:', e.target.text, e.target.text.length)
let objectSelection = canvas.getActiveObject()
switch (e.target.text.length) {
case 10:
console.log(`Text is ${e.target.text.length} characters in length.`)
objectSelection.set('fontSize', 100)
break
case 15:
console.log(`Text is ${e.target.text.length} characters in length.`)
objectSelection.set('fontSize', 85)
break
case 25:
console.log(`Text is ${e.target.text.length} characters in length.`)
objectSelection.set('fontSize', 60)
break
}
})
canvas.on('text:editing:exited', function (e) {
console.log('Text edited!')
})
I took inspiration from another answer, which does the job.