| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 intl; | 5 part of intl; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Bidi stands for Bi-directional text. | 8 * Bidi stands for Bi-directional text. |
| 9 * According to [Wikipedia](http://en.wikipedia.org/wiki/Bi-directional_text): | 9 * According to [Wikipedia](http://en.wikipedia.org/wiki/Bi-directional_text): |
| 10 * Bi-directional text is text containing text in both text directionalities, | 10 * Bi-directional text is text containing text in both text directionalities, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 TextDirection direction}) { | 101 TextDirection direction}) { |
| 102 if (direction == null) direction = estimateDirection(text, isHtml: isHtml); | 102 if (direction == null) direction = estimateDirection(text, isHtml: isHtml); |
| 103 var result; | 103 var result; |
| 104 if (!isHtml) text = HTML_ESCAPE.convert(text); | 104 if (!isHtml) text = HTML_ESCAPE.convert(text); |
| 105 var directionChange = contextDirection.isDirectionChange(direction); | 105 var directionChange = contextDirection.isDirectionChange(direction); |
| 106 if (_alwaysSpan || directionChange) { | 106 if (_alwaysSpan || directionChange) { |
| 107 var spanDirection = ''; | 107 var spanDirection = ''; |
| 108 if (directionChange) { | 108 if (directionChange) { |
| 109 spanDirection = ' dir=${direction.spanText}'; | 109 spanDirection = ' dir=${direction.spanText}'; |
| 110 } | 110 } |
| 111 result= '<span$spanDirection>$text</span>'; | 111 result = '<span$spanDirection>$text</span>'; |
| 112 } else { | 112 } else { |
| 113 result = text; | 113 result = text; |
| 114 } | 114 } |
| 115 return result + (resetDir? _resetDir(text, direction, isHtml) : ''); | 115 return result + (resetDir ? _resetDir(text, direction, isHtml) : ''); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Format [text] of a known (if specified) or estimated [direction] for use | 119 * Format [text] of a known (if specified) or estimated [direction] for use |
| 120 * in *plain-text* output of the context directionality, so an | 120 * in *plain-text* output of the context directionality, so an |
| 121 * opposite-directionality text is neither garbled nor garbles what follows | 121 * opposite-directionality text is neither garbled nor garbles what follows |
| 122 * it. Unlike wrapWithSpan, this makes use of unicode BiDi formatting | 122 * it. Unlike wrapWithSpan, this makes use of unicode BiDi formatting |
| 123 * characters instead of spans for wrapping. The returned string would be | 123 * characters instead of spans for wrapping. The returned string would be |
| 124 * RLE+text+PDF for RTL text, or LRE+text+PDF for LTR text. | 124 * RLE+text+PDF for RTL text, or LRE+text+PDF for LTR text. |
| 125 * | 125 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 */ | 136 */ |
| 137 String wrapWithUnicode(String text, {bool isHtml: false, bool resetDir: true, | 137 String wrapWithUnicode(String text, {bool isHtml: false, bool resetDir: true, |
| 138 TextDirection direction}) { | 138 TextDirection direction}) { |
| 139 if (direction == null) direction = estimateDirection(text, isHtml: isHtml); | 139 if (direction == null) direction = estimateDirection(text, isHtml: isHtml); |
| 140 var result = text; | 140 var result = text; |
| 141 if (contextDirection.isDirectionChange(direction)) { | 141 if (contextDirection.isDirectionChange(direction)) { |
| 142 var marker = direction == TextDirection.RTL ? Bidi.RLE : Bidi.LRE; | 142 var marker = direction == TextDirection.RTL ? Bidi.RLE : Bidi.LRE; |
| 143 result = "${marker}$text${Bidi.PDF}"; | 143 result = "${marker}$text${Bidi.PDF}"; |
| 144 | 144 |
| 145 } | 145 } |
| 146 return result + (resetDir? _resetDir(text, direction, isHtml) : ''); | 146 return result + (resetDir ? _resetDir(text, direction, isHtml) : ''); |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * Estimates the directionality of [text] using the best known | 150 * Estimates the directionality of [text] using the best known |
| 151 * general-purpose method (using relative word counts). A | 151 * general-purpose method (using relative word counts). A |
| 152 * TextDirection.UNKNOWN return value indicates completely neutral input. | 152 * TextDirection.UNKNOWN return value indicates completely neutral input. |
| 153 * [isHtml] is true if [text] HTML or HTML-escaped. | 153 * [isHtml] is true if [text] HTML or HTML-escaped. |
| 154 */ | 154 */ |
| 155 TextDirection estimateDirection(String text, {bool isHtml: false}) { | 155 TextDirection estimateDirection(String text, {bool isHtml: false}) { |
| 156 return Bidi.estimateDirectionOfText(text, isHtml: isHtml); //TODO~!!! | 156 return Bidi.estimateDirectionOfText(text, isHtml: isHtml); //TODO~!!! |
| (...skipping 14 matching lines...) Expand all Loading... |
| 171 Bidi.endsWithRtl(text, isHtml))) || | 171 Bidi.endsWithRtl(text, isHtml))) || |
| 172 (contextDirection == TextDirection.RTL && | 172 (contextDirection == TextDirection.RTL && |
| 173 (direction == TextDirection.LTR || | 173 (direction == TextDirection.LTR || |
| 174 Bidi.endsWithLtr(text, isHtml)))) { | 174 Bidi.endsWithLtr(text, isHtml)))) { |
| 175 return contextDirection == TextDirection.LTR ? Bidi.LRM : Bidi.RLM; | 175 return contextDirection == TextDirection.LTR ? Bidi.LRM : Bidi.RLM; |
| 176 } else { | 176 } else { |
| 177 return ''; | 177 return ''; |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 } | 180 } |
| OLD | NEW |