0
以下內容將畫布圖像繪製到頂部和底部。問題在於stroketext()
會使文字出現怪異的多邊形形狀。需要使用filltext()
和stroketext()
,以便文本可以帶有黑色邊框的白色,無論背景顏色如何,這些邊框都可以在任何圖像上看到。有沒有辦法去除多邊形?如何從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 2012-01-02 16:23:53