Skip to content

Instantly share code, notes, and snippets.

@JimmyJune
Created October 29, 2014 02:39
Show Gist options
  • Select an option

  • Save JimmyJune/5b862cda10cf72f2a9c3 to your computer and use it in GitHub Desktop.

Select an option

Save JimmyJune/5b862cda10cf72f2a9c3 to your computer and use it in GitHub Desktop.
//todo:get line height is still wrong
function drawTextBG(ctx, txt, font, x, y) {
ctx.save();
ctx.font = font;
ctx.textBaseline = 'top';
ctx.fillStyle = '#f50';
var width = ctx.measureText(txt).width;
ctx.fillRect(x, y, width, parseInt(font, 10));
ctx.fillStyle = '#000';
ctx.fillText(txt, x, y);
ctx.restore();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment