(textLine, options)
| 7899 | } |
| 7900 | |
| 7901 | function truncateSingleLine(textLine, options) { |
| 7902 | var containerWidth = options.containerWidth; |
| 7903 | var font = options.font; |
| 7904 | var contentWidth = options.contentWidth; |
| 7905 | |
| 7906 | if (!containerWidth) { |
| 7907 | return ''; |
| 7908 | } |
| 7909 | |
| 7910 | var lineWidth = getWidth(textLine, font); |
| 7911 | |
| 7912 | if (lineWidth <= containerWidth) { |
| 7913 | return textLine; |
| 7914 | } |
| 7915 | |
| 7916 | for (var j = 0; ; j++) { |
| 7917 | if (lineWidth <= contentWidth || j >= options.maxIterations) { |
| 7918 | textLine += options.ellipsis; |
| 7919 | break; |
| 7920 | } |
| 7921 | |
| 7922 | var subLength = j === 0 |
| 7923 | ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth) |
| 7924 | : lineWidth > 0 |
| 7925 | ? Math.floor(textLine.length * contentWidth / lineWidth) |
| 7926 | : 0; |
| 7927 | |
| 7928 | textLine = textLine.substr(0, subLength); |
| 7929 | lineWidth = getWidth(textLine, font); |
| 7930 | } |
| 7931 | |
| 7932 | if (textLine === '') { |
| 7933 | textLine = options.placeholder; |
| 7934 | } |
| 7935 | |
| 7936 | return textLine; |
| 7937 | } |
| 7938 | |
| 7939 | function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) { |
| 7940 | var width = 0; |
no test coverage detected