canvas-compositor/Compositor/TextNode.ts

31 lines
994 B
TypeScript
Raw Normal View History

2023-06-11 17:44:05 +03:00
import Node from "./Node";
export default class TextNode extends Node
{
public color : string = "#000000";
public text: string;
public fontSize : number = 18;
constructor(text: string){
super();
this.text = text;
this.handleDrawBefore(function(){
this.height = this.fontSize;
this.context.context.save();
this.context.context.font = this.fontSize+"px system-ui";
this.width = this.context.context.measureText(this.text).width;
this.context.context.restore();
console.log(this.width)
});
this.handleDraw(function(canvasBuffer,area){
let ctx = canvasBuffer.context;
ctx.font = this.fontSize+"px system-ui";
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.textAlign = 'left';
ctx.textBaseline = 'top';
ctx.fillText(this.text, 0,0);
ctx.closePath();
});
}
};