绘制文字

绘制文字

window.onload = function (){
    var cvs = document.getElementById("cvs");
    var ctx = cvs.getContext("2d");

    ctx.fillText("Hello LiKang.", 0, 100); // 绘制文字
}

设置文字样式

window.onload = function (){
var cvs = document.getElementById("cvs");![](/assets/testbaseline.png)
    var ctx = cvs.getContext("2d");

    ctx.font = "100px Arial"; // 设置字体
    ctx.fillStyle = "coral"; // 设置文字颜色
    ctx.fillText("Hello LiKang.", 0, 100); // 绘制文字
}

度量文字

ctx.measureText(text).width // 获取text的宽度

文字对齐

基线

results matching ""

    No results matching ""