canvas实现文字自动换行,段落居中,单行的时候居中

您所在的位置:网站首页 文字居中微信小程序 canvas实现文字自动换行,段落居中,单行的时候居中

canvas实现文字自动换行,段落居中,单行的时候居中

2024-07-12 20:58| 来源: 网络整理| 查看: 265

canvas实现文字自动换行,段落居中,单行的时候居中方法,主要用到以下方法:

/****绘制自动换行的字符串****/     //ctx_2d        getContext("2d") 对象       //lineheight    段落文本行高       //bytelength    设置单字节文字一行内的数量       //text          写入画面的段落文本       //startleft     开始绘制文本的 x 坐标位置(相对于画布)       //starttop      开始绘制文本的 y 坐标位置(相对于画布)       //ctx_fillStyle      字体颜色     //ctx_font      字体     //istrue 是否设置     function writeTextOnCanvas(ctx_2d, lineheight, bytelength, text ,startleft, starttop,ctx_fillStyle,ctx_font,istrue){           function getTrueLength(str){//获取字符串的真实长度(字节长度)               var len = str.length, truelen = 0;               for(var x = 0; x  128){                       truelen += 2;                   }else{                       truelen += 1;                   }               }               return truelen;           }           function cutString(str, leng){//按字节长度截取字符串,返回substr截取位置               var len = str.length, tlen = len, nlen = 0;               for(var x = 0; x  128){                       if(nlen + 2 


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3