JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id='canv' width=400 height=400></canvas>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
JavaScript
var canvas=new fabric.Canvas('canv');
var i = 0
var j=0
var l=0
fabric.Text.prototype.getStyleAtPosition=function(position, complete) {
var loc = this.get2DCursorLocation(position),
style = complete ? this.getCompleteStyleDeclaration(loc.lineIndex, loc.charIndex) :
this._getStyleDeclaration(loc.lineIndex, loc.charIndex);
return style || {};
}
function getStyle(object, styleName) {
return (object.getStyleAtPosition && object.isEditing) ?
object.getStyleAtPosition(object.selectionStart)[styleName] : object[styleName];
}
fabric.Text.prototype._getWidthOfCharSpacing= function() {
//console.log("test",this.text.length)
char=this.getStyleAtPosition(i)['charSp']
if (typeof char !== 'undefined') {
if(this.text.length==i){
i=0;
}
else
i++;
return char;
//return this.fontSize * char / 1000;
}
if(this.text.length==i){
i=0;
}
else
i++;
return 0;
};
fabric.Text.prototype.getHeightOfLine=function(lineIndex) {
lineh=this.getStyleAtPosition(i)['lheight']
i++;
if (this.__lineHeights[lineIndex]) {
j++
return this.__lineHeights[lineIndex];
}
var line = this._textLines[lineIndex],
// char 0 is measured before the line cycle because it nneds to char
// emptylines
maxHeight = this.getHeightOfChar(lineIndex, 0);
maxLheight=1
for (var i = 0, len = line.length; i < len; i++) {
maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
if (typeof this.getStyleAtPosition(j)['lheight'] !=="undefined"){
maxLheight=Math.max(this.getStyleAtPosition(j)['lheight'],maxLheight)}
k=lineIndex;
if( k!==l){
j++
}
l=lineIndex;
if (this.text.length == j){
j=0;
}
j++;
}
...