This commit is contained in:
Maciej Caderek
2022-01-26 09:44:37 +01:00
parent 0c2f804021
commit 6c401d1459
13 changed files with 308 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
const drawText = (
ctx: CanvasRenderingContext2D,
text: string,
font: string,
fontSize: number,
fontWeight: number,
x: number,
@@ -8,10 +9,12 @@ const drawText = (
align: CanvasTextAlign,
maxWidth?: number
) => {
ctx.font = `${fontWeight} ${fontSize}px Ubuntu`;
ctx.font = `${fontWeight} ${fontSize}px ${font}`;
ctx.textAlign = align;
ctx.textBaseline = "middle";
ctx.fillText(text, x, y, maxWidth);
return Math.ceil(ctx.measureText(text).width);
};
export default drawText;