Add the ability to stroke text.

This is useful in scenarios where a background is many colors.
This commit is contained in:
Gary M. Josack
2014-10-11 21:33:06 -07:00
parent 30c326ed36
commit ebb8908812
3 changed files with 13 additions and 4 deletions
+9 -2
View File
@@ -16,7 +16,8 @@
paddingY: 0, // zero px top & bottom text padding relative to canvas or parent
fitParent: false, // text is tested to fit canvas width
lineBreak: 'auto', // text fills the element's (canvas or parent) width going to a new line on a whole word
sizeToFill: false // text is resized to fill the container (given font size is ignored)
sizeToFill: false, // text is resized to fill the container (given font size is ignored)
strokeText: false // text is stroked according to context configuration.
};
window.CanvasTextWrapper = function(canvas, text, opts) {
@@ -82,6 +83,9 @@
textPos.y = parseInt(textPos.y) + parseInt(this.lineHeight);
this.context.fillText(lines[i], textPos.x, textPos.y);
if (this.strokeText) {
this.context.strokeText(lines[i], textPos.x, textPos.y);
}
}
},
@@ -194,6 +198,9 @@
if (typeof this.sizeToFill !== 'boolean') {
throw new TypeError('From CanvasTextWrapper(): Property "sizeToFill" must be set to a Boolean.');
}
if (typeof this.strokeText !== 'boolean') {
throw new TypeError('From CanvasTextWrapper(): Property "strokeText" must be set to a Boolean.');
}
}
};
})();
})();