JavaScript
语言:
JaveScriptBabelCoffeeScript
确定
(function() {
function writeTextOnCanvas(cns, lh, rw, text) {
var cns = document.getElementById(cns);
var ctx = cns.getContext("2d");
var lineheight = lh;
var text = text;
ctx.width = cns.width;
ctx.height = cns.height;
ctx.clearRect(0, 0, ctx.width, ctx.height);
ctx.font = "16px 微软雅黑";
ctx.fillStyle = "#f00";
function getTrueLength(str) { //获取字符串的真实长度(字节长度)
var len = str.length,
truelen = 0;
for (var x = 0; x < len; x++) {
if (str.charCodeAt(x) > 128) {
truelen += 2;
} else {
truelen += 1;
}
}
return truelen;
}
function cutS