I am using convas context measureText
to get the width of my text on the canvas. Below is the code:
ctx.fillStyle = color;
ctx.fontWeight = FONT_WEIGHT;
ctx.font = `bolder italic ${fontsize}px`;
const textWidth = ctx.measureText(text).width;
the problem is that if the font style is italic
, the right of the text will be off boundary. That because measureText
doesn't take italic
into account. How can I calculate the text width for italic
style?
Below are two screenshots for italic
font on convas. The first one is the text without italic while the second one is with italic. You can see that the second one has a little off boundaries.