| 2996 | // Change some spaces to NBSP to prevent the browser from collapsing |
| 2997 | // trailing spaces at the end of a line when rendering text (issue #1362). |
| 2998 | function splitSpaces(text, trailingBefore) { |
| 2999 | if (text.length > 1 && !/ /.test(text)) { |
| 3000 | return text |
| 3001 | } |
| 3002 | var spaceBefore = trailingBefore, |
| 3003 | result = "" |
| 3004 | for (var i = 0; i < text.length; i++) { |
| 3005 | var ch = text.charAt(i) |
| 3006 | if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) { |
| 3007 | ch = "\u00a0" |
| 3008 | } |
| 3009 | result += ch |
| 3010 | spaceBefore = ch == " " |
| 3011 | } |
| 3012 | return result |
| 3013 | } |
| 3014 | |
| 3015 | // Work around nonsense dimensions being reported for stretches of |
| 3016 | // right-to-left text. |