我認爲這是一個錯誤,但如果你有任何人知道任何工作,請讓我知道。帆布希臘谷歌字體不能正確渲染
首先,字體加載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;
};