| 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 #library('bidi_formatter'); |
| 6 |
| 7 #import('bidi_utils.dart'); |
| 8 |
| 5 /** | 9 /** |
| 6 * Bidi stands for Bi-directional text. | 10 * Bidi stands for Bi-directional text. |
| 7 * According to [Wikipedia](http://en.wikipedia.org/wiki/Bi-directional_text): | 11 * According to http://en.wikipedia.org/wiki/Bi-directional_text: |
| 8 * Bi-directional text is text containing text in both text directionalities, | 12 * Bi-directional text is text containing text in both text directionalities, |
| 9 * both right-to-left (RTL) and left-to-right (LTR). It generally involves text | 13 * both right-to-left (RTL) and left-to-right (LTR). It generally involves text |
| 10 * containing different types of alphabets, but may also refer to boustrophedon, | 14 * containing different types of alphabets, but may also refer to boustrophedon, |
| 11 * which is changing text directionality in each row. | 15 * which is changing text directionality in each row. |
| 12 * | 16 * |
| 13 * Utility class for formatting display text in a potentially | 17 * Utility class for formatting display text in a potentially |
| 14 * opposite-directionality context without garbling layout issues. | 18 * opposite-directionality context without garbling layout issues. |
| 15 * Mostly a very "slimmed-down" and dart-ified port of the Closure Birectional | 19 * Mostly a very "slimmed-down" and dart-ified port of the Closure Birectional |
| 16 * formatting libary. If there is a utility in the Closure library (or ICU, or | 20 * formatting libary. If there is a utility in the Closure library (or ICU, or |
| 17 * elsewhere) that you would like this formatter to make available, please | 21 * elsewhere) that you would like this formatter to make available, please |
| (...skipping 28 matching lines...) Expand all Loading... |
| 46 * attacks and other nasty business. This of course is always true, but the | 50 * attacks and other nasty business. This of course is always true, but the |
| 47 * escaping cannot be done after the string has already been wrapped in | 51 * escaping cannot be done after the string has already been wrapped in |
| 48 * mark-up, so the BiDi formatter also serves as a last chance and includes | 52 * mark-up, so the BiDi formatter also serves as a last chance and includes |
| 49 * escaping services. | 53 * escaping services. |
| 50 * | 54 * |
| 51 * Thus, in a single call, the formatter will escape the input string as | 55 * Thus, in a single call, the formatter will escape the input string as |
| 52 * specified, determine its directionality, and wrap it as necessary. It is | 56 * specified, determine its directionality, and wrap it as necessary. It is |
| 53 * then up to the caller to insert the return value in the output. | 57 * then up to the caller to insert the return value in the output. |
| 54 */ | 58 */ |
| 55 | 59 |
| 60 #import('dart:web'); |
| 61 |
| 56 class BidiFormatter { | 62 class BidiFormatter { |
| 57 | 63 |
| 58 /** The direction of the surrounding text (the context). */ | 64 /** The direction of the surrounding text (the context). */ |
| 59 TextDirection contextDirection; | 65 TextDirection contextDirection; |
| 60 | 66 |
| 61 /** | 67 /** |
| 62 * Indicates if we should always wrap the formatted text in a <span<,. | 68 * Indicates if we should always wrap the formatted text in a <span<,. |
| 63 */ | 69 */ |
| 64 bool _alwaysSpan; | 70 bool _alwaysSpan; |
| 65 | 71 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (contextDirection == TextDirection.LTR) { | 179 if (contextDirection == TextDirection.LTR) { |
| 174 return BidiUtils.LRM; | 180 return BidiUtils.LRM; |
| 175 } else { | 181 } else { |
| 176 return BidiUtils.RLM; | 182 return BidiUtils.RLM; |
| 177 } | 183 } |
| 178 } else { | 184 } else { |
| 179 return ''; | 185 return ''; |
| 180 } | 186 } |
| 181 } | 187 } |
| 182 } | 188 } |
| OLD | NEW |