|
@@ -35,6 +35,54 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ function drawText(obj) {
|
|
|
+ console.log('渲染文字')
|
|
|
+ this.ctx.save(); this.ctx.setFillStyle(obj.color);
|
|
|
+ this.ctx.setFontSize(obj.size);
|
|
|
+ this.ctx.setTextAlign(obj.align);
|
|
|
+ this.ctx.setTextBaseline(obj.baseline);
|
|
|
+ if (obj.bold) {
|
|
|
+ console.log('字体加粗')
|
|
|
+ this.ctx.fillText(obj.text, obj.x, obj.y - 0.5);
|
|
|
+ this.ctx.fillText(obj.text, obj.x - 0.5, obj.y);
|
|
|
+ }
|
|
|
+ this.ctx.fillText(obj.text, obj.x, obj.y);
|
|
|
+ if (obj.bold) {
|
|
|
+ this.ctx.fillText(obj.text, obj.x, obj.y + 0.5);
|
|
|
+ this.ctx.fillText(obj.text, obj.x + 0.5, obj.y);
|
|
|
+ }
|
|
|
+ this.ctx.restore();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+* 文本换行
|
|
|
+*
|
|
|
+* @param {Object} obj
|
|
|
+*/
|
|
|
+ function textWrap(obj) {
|
|
|
+ console.log('文本换行')
|
|
|
+ var td = Math.ceil(obj.width / (obj.size));
|
|
|
+ var tr = Math.ceil(obj.text.length / td);
|
|
|
+ for (var i = 0; i < tr; i++) {
|
|
|
+ var txt = {
|
|
|
+ x: obj.x,
|
|
|
+ y: obj.y + (i * obj.height),
|
|
|
+ color: obj.color,
|
|
|
+ size: obj.size,
|
|
|
+ align: obj.align,
|
|
|
+ baseline: obj.baseline,
|
|
|
+ text: obj.text.substring(i * td, (i + 1) * td),
|
|
|
+ bold: obj.bold
|
|
|
+ };
|
|
|
+ if (i < obj.line) {
|
|
|
+ if (i == obj.line - 1) {
|
|
|
+ txt.text = txt.text.substring(0, txt.text.length - 3) + '......';
|
|
|
+ }
|
|
|
+ this.drawText(txt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
createDynamicImage.prototype.createTextImage = function () {
|
|
|
var canvas = document.createElement('canvas');
|
|
|
canvas.width = this.imageWidth || 1000;
|