| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "app/bidi_line_iterator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/string16.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 | |
| 11 BiDiLineIterator::~BiDiLineIterator() { | |
| 12 if (bidi_) { | |
| 13 ubidi_close(bidi_); | |
| 14 bidi_ = NULL; | |
| 15 } | |
| 16 } | |
| 17 | |
| 18 UBool BiDiLineIterator::Open(const string16& text, | |
| 19 bool right_to_left, | |
| 20 bool url) { | |
| 21 DCHECK(bidi_ == NULL); | |
| 22 UErrorCode error = U_ZERO_ERROR; | |
| 23 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); | |
| 24 if (U_FAILURE(error)) | |
| 25 return false; | |
| 26 if (right_to_left && url) | |
| 27 ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY); | |
| 28 ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()), | |
| 29 right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, | |
| 30 NULL, &error); | |
| 31 return U_SUCCESS(error); | |
| 32 } | |
| 33 | |
| 34 int BiDiLineIterator::CountRuns() { | |
| 35 DCHECK(bidi_ != NULL); | |
| 36 UErrorCode error = U_ZERO_ERROR; | |
| 37 const int runs = ubidi_countRuns(bidi_, &error); | |
| 38 return U_SUCCESS(error) ? runs : 0; | |
| 39 } | |
| 40 | |
| 41 UBiDiDirection BiDiLineIterator::GetVisualRun(int index, | |
| 42 int* start, | |
| 43 int* length) { | |
| 44 DCHECK(bidi_ != NULL); | |
| 45 return ubidi_getVisualRun(bidi_, index, start, length); | |
| 46 } | |
| 47 | |
| 48 void BiDiLineIterator::GetLogicalRun(int start, | |
| 49 int* end, | |
| 50 UBiDiLevel* level) { | |
| 51 DCHECK(bidi_ != NULL); | |
| 52 ubidi_getLogicalRun(bidi_, start, end, level); | |
| 53 } | |
| OLD | NEW |