| 1858 | // Change some spaces to NBSP to prevent the browser from collapsing |
| 1859 | // trailing spaces at the end of a line when rendering text (issue #1362). |
| 1860 | function splitSpaces(text, trailingBefore) { |
| 1861 | if (text.length > 1 && !/ /.test(text)) { return text } |
| 1862 | var spaceBefore = trailingBefore, result = ""; |
| 1863 | for (var i = 0; i < text.length; i++) { |
| 1864 | var ch = text.charAt(i); |
| 1865 | if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) |
| 1866 | { ch = "\u00a0"; } |
| 1867 | result += ch; |
| 1868 | spaceBefore = ch == " "; |
| 1869 | } |
| 1870 | return result |
| 1871 | } |
| 1872 | |
| 1873 | // Work around nonsense dimensions being reported for stretches of |
| 1874 | // right-to-left text. |