Javascript String shrink(size, font)
String.prototype.shrink = function(size, font) { if(size > this.width()) return this;/*w w w .j a v a2s . c o m*/ var count = 0; var l = 0; var w = 0; do { l += Math.floor(((size - w) / size) * l) + 1; console.log(l); w = this.substring(0, l).width(font); count += 1; } while(w < size && count < 1000); return this.substring(0, l); }