You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
963 B
JavaScript

function printText(text, positionX, positionY, alignment = 'left', baseline = 'alphabetic', style = 'normal', weight = 'normal', size = '10', font = 'Arial', colour = '#000', strokeStyle = false, lineWidth = false, strokeOnly = false){
// Save the styling, and content already on the canvas
ctx.save();
// Do the alterations and print the text
ctx.textAlign = alignment;
ctx.textBaseline = baseline;
// Set the font styling
ctx.font = style+' '+weight+' '+size+'pt'+' '+font;
//ctx.font-style = fontStyle; // normal, italic, oblique
ctx.fillStyle = colour;
if(strokeStyle && lineWidth){
// Set the stroke styling
ctx.strokeStyle = strokeStyle;
ctx.lineWidth = lineWidth;
// Add the stroke (first, before fill) as it looks better
ctx.strokeText(text, positionX, positionY);
}
if(!strokeOnly){
// Actually add the text
ctx.fillText(text, positionX, positionY);
}
// Restore the prior existing canvas content
ctx.restore();
}