OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/bidi_line_iterator.h" | 5 #include "app/bidi_line_iterator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 | 10 |
11 BiDiLineIterator::~BiDiLineIterator() { | 11 BiDiLineIterator::~BiDiLineIterator() { |
12 if (bidi_) { | 12 if (bidi_) { |
13 ubidi_close(bidi_); | 13 ubidi_close(bidi_); |
14 bidi_ = NULL; | 14 bidi_ = NULL; |
15 } | 15 } |
16 } | 16 } |
17 | 17 |
18 UBool BiDiLineIterator::Open(const std::wstring& text, | 18 UBool BiDiLineIterator::Open(const string16& text, |
19 bool right_to_left, | 19 bool right_to_left, |
20 bool url) { | 20 bool url) { |
21 DCHECK(bidi_ == NULL); | 21 DCHECK(bidi_ == NULL); |
22 UErrorCode error = U_ZERO_ERROR; | 22 UErrorCode error = U_ZERO_ERROR; |
23 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); | 23 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); |
24 if (U_FAILURE(error)) | 24 if (U_FAILURE(error)) |
25 return false; | 25 return false; |
26 if (right_to_left && url) | 26 if (right_to_left && url) |
27 ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY); | 27 ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY); |
28 #if defined(WCHAR_T_IS_UTF32) | 28 ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()), |
29 const string16 text_utf16 = WideToUTF16(text); | |
30 #else | |
31 const std::wstring &text_utf16 = text; | |
32 #endif // U_SIZEOF_WCHAR_T != 4 | |
33 ubidi_setPara(bidi_, text_utf16.data(), static_cast<int>(text_utf16.length()), | |
34 right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, | 29 right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, |
35 NULL, &error); | 30 NULL, &error); |
36 return U_SUCCESS(error); | 31 return U_SUCCESS(error); |
37 } | 32 } |
38 | 33 |
39 int BiDiLineIterator::CountRuns() { | 34 int BiDiLineIterator::CountRuns() { |
40 DCHECK(bidi_ != NULL); | 35 DCHECK(bidi_ != NULL); |
41 UErrorCode error = U_ZERO_ERROR; | 36 UErrorCode error = U_ZERO_ERROR; |
42 const int runs = ubidi_countRuns(bidi_, &error); | 37 const int runs = ubidi_countRuns(bidi_, &error); |
43 return U_SUCCESS(error) ? runs : 0; | 38 return U_SUCCESS(error) ? runs : 0; |
44 } | 39 } |
45 | 40 |
46 UBiDiDirection BiDiLineIterator::GetVisualRun(int index, | 41 UBiDiDirection BiDiLineIterator::GetVisualRun(int index, |
47 int* start, | 42 int* start, |
48 int* length) { | 43 int* length) { |
49 DCHECK(bidi_ != NULL); | 44 DCHECK(bidi_ != NULL); |
50 return ubidi_getVisualRun(bidi_, index, start, length); | 45 return ubidi_getVisualRun(bidi_, index, start, length); |
51 } | 46 } |
52 | 47 |
53 void BiDiLineIterator::GetLogicalRun(int start, | 48 void BiDiLineIterator::GetLogicalRun(int start, |
54 int* end, | 49 int* end, |
55 UBiDiLevel* level) { | 50 UBiDiLevel* level) { |
56 DCHECK(bidi_ != NULL); | 51 DCHECK(bidi_ != NULL); |
57 ubidi_getLogicalRun(bidi_, start, end, level); | 52 ubidi_getLogicalRun(bidi_, start, end, level); |
58 } | 53 } |
OLD | NEW |