| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of view; | 5 part of view; |
| 6 | 6 |
| 7 // TODO(jacobr): handle splitting lines on symbols such as '-' that aren't | 7 // TODO(jacobr): handle splitting lines on symbols such as '-' that aren't |
| 8 // whitespace but are valid word breaking points. | 8 // whitespace but are valid word breaking points. |
| 9 /** | 9 /** |
| 10 * Utility class to efficiently word break and measure text without requiring | 10 * Utility class to efficiently word break and measure text without requiring |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if (lines == maxLines) { | 96 if (lines == maxLines) { |
| 97 // Overflow case... there may be more lines of text than we can handle. | 97 // Overflow case... there may be more lines of text than we can handle. |
| 98 // Add a few characters to the last line so that the browser will | 98 // Add a few characters to the last line so that the browser will |
| 99 // render ellipses correctly. | 99 // render ellipses correctly. |
| 100 // TODO(jacobr): make this optional and only add characters until | 100 // TODO(jacobr): make this optional and only add characters until |
| 101 // the first whitespace character encountered. | 101 // the first whitespace character encountered. |
| 102 end = Math.min(end + 50, text.length); | 102 end = Math.min(end + 50, text.length); |
| 103 } | 103 } |
| 104 if (sb != null) { | 104 if (sb != null) { |
| 105 if (lines > 1) { | 105 if (lines > 1) { |
| 106 sb.add('<br>'); | 106 sb.write('<br>'); |
| 107 } | 107 } |
| 108 // TODO(jacobr): HTML escape this text. | 108 // TODO(jacobr): HTML escape this text. |
| 109 sb.add(text.substring(start, end)); | 109 sb.write(text.substring(start, end)); |
| 110 } | 110 } |
| 111 }); | 111 }); |
| 112 return lines; | 112 return lines; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void lineBreak(String text, num lineWidth, int maxLines, | 115 void lineBreak(String text, num lineWidth, int maxLines, |
| 116 Function callback) { | 116 Function callback) { |
| 117 _context.font = font; | 117 _context.font = font; |
| 118 int lines = 0; | 118 int lines = 0; |
| 119 num currentLength = 0; | 119 num currentLength = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } else if (wordStartIndex == null && !whitespace) { | 154 } else if (wordStartIndex == null && !whitespace) { |
| 155 wordStartIndex = i; | 155 wordStartIndex = i; |
| 156 } | 156 } |
| 157 lastWhitespace = whitespace; | 157 lastWhitespace = whitespace; |
| 158 } | 158 } |
| 159 if (currentLength > 0) { | 159 if (currentLength > 0) { |
| 160 callback(startIndex, text.length, currentLength); | 160 callback(startIndex, text.length, currentLength); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| OLD | NEW |