TipCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {
ctx.font = style.font;
value = fittingString(ctx, value, w - 2);
spreadNS.CellTypes.Text.prototype.paint.apply(this, arguments);
};
function fittingString(c, str, maxWidth) {
var width = c.measureText(str).width;
var ellipsis = '…';
var ellipsisWidth = c.measureText(ellipsis).width;
if (width <= maxWidth || width <= ellipsisWidth) {
return str;
} else {
var len = str.length;
while (width >= maxWidth - ellipsisWidth && len-- > 0) {
str = str.substring(0, len);
width = c.measureText(str).width;
}
return str + ellipsis;
}
}
|