drawKernel(ctx, img_x, windowWidth, imgHeight) {
var that = this;
ctx.font = '16px PingFangSC-Semibod, sans-serif';
ctx.setTextAlign('center');
ctx.setFillStyle("#fff");
// ctx.fillText(this.data.newCourseRecommend.title, img_x, imgHeight + 306);
var str = this.data.newCourseRecommend.title;
var height = imgHeight + 306;
var lineWidth = 0;
var lastIndex = 0; //每次开始截取的字符串的索引
for (let i = 0; i < str.length; i++) {
lineWidth += ctx.measureText(str[i]).width;
if (lineWidth > 320) {
that.drawFont(ctx, str.substring(lastIndex, i), height, img_x);
height += that.data.lineHeight;
lineWidth = 0;
lastIndex = i;
that.setData({
kernelHeight: height
})
}
if (i == str.length - 1) { //绘制剩余部分
that.drawFont(ctx, str.substring(lastIndex, i + 1), height, img_x);
}
}
},
drawFont: function(ctx, content, height, img_x) {
ctx.fillText(content, img_x, height);
},