31 lines
994 B
TypeScript
31 lines
994 B
TypeScript
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();
|
|
});
|
|
}
|
|
}; |