* @public * @param {string} text * @param {string} font * @return {number} width
(text, font)
| 7600 | * @return {number} width |
| 7601 | */ |
| 7602 | function getWidth(text, font) { |
| 7603 | font = font || DEFAULT_FONT$1; |
| 7604 | var key = text + ':' + font; |
| 7605 | if (textWidthCache[key]) { |
| 7606 | return textWidthCache[key]; |
| 7607 | } |
| 7608 | |
| 7609 | var textLines = (text + '').split('\n'); |
| 7610 | var width = 0; |
| 7611 | |
| 7612 | for (var i = 0, l = textLines.length; i < l; i++) { |
| 7613 | // textContain.measureText may be overrided in SVG or VML |
| 7614 | width = Math.max(measureText(textLines[i], font).width, width); |
| 7615 | } |
| 7616 | |
| 7617 | if (textWidthCacheCounter > TEXT_CACHE_MAX) { |
| 7618 | textWidthCacheCounter = 0; |
| 7619 | textWidthCache = {}; |
| 7620 | } |
| 7621 | textWidthCacheCounter++; |
| 7622 | textWidthCache[key] = width; |
| 7623 | |
| 7624 | return width; |
| 7625 | } |
| 7626 | |
| 7627 | /** |
| 7628 | * @public |
no test coverage detected