我认为这是一个错误,但如果你有任何人知道任何工作,请让我知道。帆布希腊谷歌字体不能正确渲染
首先,字体加载101%。
我加载谷歌字体同步
我与间隔检查,以确保该字体被加载。
我用帆布成功将字符串转换成图像(以下功能)(当 我用英文字符)
呈现几个英文字符后,我尝试呈现一个希腊 字但是画布会回退到浏览器的默认字体。
Firefox根本没有任何问题,它的效果很好。 Chrome的问题是 。
娄是,从给定的字符串创建在左上角的带状标签背景图像的功能(PS:正在与其他的imageData稍后合并此函数返回的imageData):
ImageProcessor.prototype.createLabelImageData = function (str, size, font, color, backgroundColor, shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur, width, height) {
this.canvas.width = width || this.settings.width;
this.canvas.height = height || this.settings.height;
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.ctx.font = "Bold " + (size || 64) + "px " + (font || "Arial");
this.ctx.textAlign = "center";
this.ctx.textBaseline = "middle";
var labelHeight = (size || 64) + ((size || 64)/4);
var labelTop = this.canvas.height/2 - labelHeight/2;
var labelWidth = this.canvas.width;
var strLen = this.ctx.measureText(str + " ").width;
var side = Math.sqrt((strLen * strLen)/2);
var distance = Math.sqrt((side * side) - ((strLen/2) * (strLen/2)));
this.ctx.save();
this.ctx.rotate(-Math.PI/4);
this.ctx.translate(-this.canvas.width/2, -this.canvas.height/2 + distance);
this.ctx.fillStyle = (backgroundColor || '#f00');
this.ctx.beginPath();
this.ctx.moveTo(0, labelTop);
this.ctx.lineTo(labelWidth, labelTop);
this.ctx.lineTo(labelWidth, labelTop + labelHeight);
this.ctx.lineTo(0, labelTop + labelHeight);
this.ctx.closePath();
this.ctx.fill();
if (shadowColor) {
this.ctx.shadowColor = shadowColor;
this.ctx.shadowOffsetX = (shadowOffsetX || 0);
this.ctx.shadowOffsetY = (shadowOffsetY || 0);
this.ctx.shadowBlur = (shadowBlur || size || 64);
}
this.ctx.fillStyle = (color || "#fff");
this.ctx.fillText(str, this.canvas.width/2, this.canvas.height/2);
this.ctx.restore();
var imageData = this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
this.canvas.width = this.settings.width;
this.canvas.height = this.settings.height;
return imageData;
};