美文网首页Canvas
canvas-07 文本

canvas-07 文本

作者: 呆桃冲鸭冲鸭 | 来源:发表于2020-08-14 00:00 被阅读0次

文本的属性:

        字体:font

                 ctx.font = "bold 100px serif"

                 ctx.fillText("测试font",50,300);

        水平对齐:textAlign=start\left\end\right\center

                <!-- dir 文字方向 rtl 右边到左  ltr 左到右 -->

                <!-- <html lang="en" dir="rtl">  -->

                ctx.strokeStyle = "#999";

                ctx.setLineDash([8]);

                ctx.moveTo(300,50);

                ctx.lineTo(300,600);

                ctx.stroke();

                ctx.font = "bold 24px serif";

                // ctx.fillText("测试font",50,300);

                ctx.textAlign = "start";

                ctx.fillText("测试start",300,50);

                ctx.textAlign = "left";

                ctx.fillText("测试left",300,100);

                ctx.textAlign = "end";

                ctx.fillText("测试left",300,150);

                ctx.textAlign = "right";

                ctx.fillText("测试left",300,200);

                ctx.textAlign = "center";

                ctx.fillText("测试left",300,250);

textAlign 

        垂直对齐:textBaseline:top middle  bottom  hanging  alphabatic  ideographic

                ctx.strokeStyle = "#999";

                ctx.setLineDash([8]);

                ctx.moveTo(30,200);

                ctx.lineTo(700,200);

                ctx.stroke();

                ctx.font = " 24px serif";

                ctx.textBaseline = "top";

                ctx.fillText("测试top",50,200);

                ctx.textBaseline = "middle";

                ctx.fillText("测试middle",150,200);

                ctx.textBaseline = "bottom";

                ctx.fillText("测试middle",300,200);

textBaseline 

文本绘制方法:

        填充文字  fillText(text,x,y,maxWidth)

        描边文字 strokeText(text,x,y,maxWidth)

                const text = "劳动最光荣";

                ctx.font = "bold 100px arial";

                ctx.strokeStyle = "orange";

                ctx.fillStyle = "green";

                ctx.lineWidth = 5;

                // 填充文字 fillText(text,x,y,maxWidth)

                // 描边文字 strokeText(text,x,y,maxWidth)

                ctx.fillText(text,300,200,300);

                ctx.strokeText(text,300,400,400)

fillText(text,x,y,maxWidth)  、strokeText(text,x,y,maxWidth)

  获取文字宽度的方法:measureText(text)

            const getWdith =  ctx.measureText(text);

            console.log(getWdith)

measureText

相关文章

  • canvas-07 文本

    文本的属性: 字体:font ctx.font="bold100pxserif" ctx.fillText...

  • 这是一篇测试文章

    测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测...

  • golang记录

    1.ddddd 文本1 文本2 文本3 dd 文本1 文本2 文本3 ddd 文本1 文本2 文本32192873

  • markdown列表测试

    无序列表 文本 文本 文本 有序列表 文本 文本 文本

  • 2018-12-13

    二级标题 文本1 文本2 文本3 文本 文本 文本百度

  • flutter 文本widget

    文本文本 富文本富文本

  • Photoshop快捷键|文本操作快捷键大全(Photoshop

    Adobe Photoshop软件的文本操作包括:文本选择、文本移动、文本显示及新建、文本缩放、文本对齐、文本间距...

  • 测试标题

    测试文本内容测试文本内容测试文本内容测试文本内容测试文本内容测试文本内容测试文本内容 'test'

  • MarkDown语法

    ~~无序列表 ~~ 文本1 文本2 文本3 有序列表 标题2 文本3 文本1 文本2 文本3 文本4 链接和图片...

  • 测试文本 2019-04-10

    测试文本测试文本测试文本测试文本

网友评论

    本文标题:canvas-07 文本

    本文链接:https://www.haomeiwen.com/subject/roqbdktx.html