0
以下は、テキストをキャンバスイメージ、上の行と下の行に描画します。問題はstroketext()
は、奇妙な多角形がテキストから出てくることです。 filltext()
とstroketext()
の両方を使用する必要があります。そのため、黒い枠線でテキストを白くすることができます。黒い枠線は、背景色に関係なく画像に表示されます。ポリゴンを削除する方法はありますか?のみfillText()
を呼び出すCanvasのfilltext()からテキストポリゴンを削除するには?
drawText = function(context, pos, text) {
var fontSize = 100;
while(1) {
context.font = "bold " + fontSize + "px Arial";
if((context.measureText(text).width < (width-15)) && (fontSize < height/10)) {
break;
}
fontSize-=2;
}
var y;
if(pos == "top")
y = fontSize + 15;
else if(pos == "bottom") {
y = height - 15;
}
context.strokeText(text, width/2, y);
context.fillText(text, width/2, y);
}
updateList = function(doc, where) {
if(where == "top")
$("#list").prepend(makeCanvas(doc));
else {
$("#list").append(makeCanvas(doc));
}
var canvas = document.getElementById(doc._id);
var context = canvas.getContext("2d");
context.textAlign = "center";
context.fillStyle = "#fff";
context.strokeStyle = "#000";
context.lineWidth = 6;
var img = new Image();
img.src = getTemplateLink(doc.name);
img.onload = function() {
context.drawImage(img, 0, 0, canvas.width, canvas.height);
drawText(context, "top", doc.text.line1);
drawText(context, "bottom", doc.text.line2);
};
}
奇妙な図形については、stroketext()でのみ修正してください。追加の文字は埋め込まれません。 – Simpleton