measure_text_width, measure_text_height

function measure_text_width(text) {
  var width = 0;
  var lines = text.split(/\x0d\x0a|\x0d|\x0a/);

  for(var i=0; i<lines.length; i++) {
    var line = lines[i];
    var charct = 0;

    for(var j=0; j<line.length; j++) {
      charct += line.charCodeAt(j) <= 0x7f ? 1 : 2;
    }

    if(width < charct) {
      width = charct;
    }
  }

  return width;
}

function measure_text_height(text) {
  return text.split(/\x0d\x0a|\x0d|\x0a/).length;
}