summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 17:16:26 +0000
committerfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 17:16:26 +0000
commit45003a76537ada4d727e0b33f28961a72938c9e7 (patch)
tree93d62dd7633fe2165d65c0548c8bcde2006b35db /chrome/common
parent153d44b69e23ac6e1ca2efa64ef5544f08cb8c71 (diff)
downloadchromium_src-45003a76537ada4d727e0b33f28961a72938c9e7.zip
chromium_src-45003a76537ada4d727e0b33f28961a72938c9e7.tar.gz
chromium_src-45003a76537ada4d727e0b33f28961a72938c9e7.tar.bz2
Fix RTL issues in the About box (bug 3756).
I used the BiDiLineIterator, which I moved out of the AutocompletePopup and into the l10n_util file. I also added a wrapper function around ubidi_getLogicalRun. Review URL: http://codereview.chromium.org/8727 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4294 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/l10n_util.cc47
-rw-r--r--chrome/common/l10n_util.h35
2 files changed, 76 insertions, 6 deletions
diff --git a/chrome/common/l10n_util.cc b/chrome/common/l10n_util.cc
index 5c6e74b..199d937 100644
--- a/chrome/common/l10n_util.cc
+++ b/chrome/common/l10n_util.cc
@@ -125,7 +125,7 @@ bool IsDuplicateName(const std::string& locale_name) {
// Skip all 'es_RR'. Currently, we use 'es' for es-ES (Spanish in Spain).
// 'es-419' (Spanish in Latin America) is not available in ICU so that it
// has to be added manually in GetAvailableLocales().
- if (LowerCaseEqualsASCII(locale_name.substr(0,3), "es_"))
+ if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_"))
return true;
for (int i = 0; i < arraysize(kDuplicateNames); ++i) {
if (_stricmp(kDuplicateNames[i], locale_name.c_str()) == 0)
@@ -185,7 +185,7 @@ bool CheckAndResolveLocale(const std::wstring& locale,
}
// Google updater uses no, iw and en for our nb, he, and en-US.
- // We need to map them to our codes.
+ // We need to map them to our codes.
struct {
const char* source;
const wchar_t* dest;} alias_map[] = {
@@ -572,5 +572,48 @@ const std::vector<std::wstring>& GetAvailableLocales() {
return locales;
}
+BiDiLineIterator::~BiDiLineIterator() {
+ if (bidi_) {
+ ubidi_close(bidi_);
+ bidi_ = NULL;
+ }
}
+UBool BiDiLineIterator::Open(const std::wstring& text,
+ bool right_to_left,
+ bool url) {
+ DCHECK(bidi_ == NULL);
+ UErrorCode error = U_ZERO_ERROR;
+ bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error);
+ if (U_FAILURE(error))
+ return false;
+ if (right_to_left && url)
+ ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY);
+ ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()),
+ right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
+ NULL, &error);
+ return U_SUCCESS(error);
+}
+
+int BiDiLineIterator::CountRuns() {
+ DCHECK(bidi_ != NULL);
+ UErrorCode error = U_ZERO_ERROR;
+ const int runs = ubidi_countRuns(bidi_, &error);
+ return U_SUCCESS(error) ? runs : 0;
+}
+
+UBiDiDirection BiDiLineIterator::GetVisualRun(int index,
+ int* start,
+ int* length) {
+ DCHECK(bidi_ != NULL);
+ return ubidi_getVisualRun(bidi_, index, start, length);
+}
+
+void BiDiLineIterator::GetLogicalRun(int start,
+ int* end,
+ UBiDiLevel* level) {
+ DCHECK(bidi_ != NULL);
+ ubidi_getLogicalRun(bidi_, start, end, level);
+}
+
+}
diff --git a/chrome/common/l10n_util.h b/chrome/common/l10n_util.h
index 4514f60..68d1f32 100644
--- a/chrome/common/l10n_util.h
+++ b/chrome/common/l10n_util.h
@@ -5,14 +5,15 @@
// This file contains utility functions for dealing with localized
// content.
-#ifndef CHROME_COMMON_L10N_UTIL_H__
-#define CHROME_COMMON_L10N_UTIL_H__
+#ifndef CHROME_COMMON_L10N_UTIL_H_
+#define CHROME_COMMON_L10N_UTIL_H_
#include <windows.h>
#include <string>
#include <vector>
#include "base/basictypes.h"
+#include "third_party/icu38/public/common/unicode/ubidi.h"
class PrefService;
@@ -167,7 +168,33 @@ void SortStrings(const std::wstring& locale,
// en-US, es, fr, fi, pt-PT, pt-BR, etc.
const std::vector<std::wstring>& GetAvailableLocales();
-}
+// A simple wrapper class for the bidirectional iterator of ICU.
+// This class uses the bidirectional iterator of ICU to split a line of
+// bidirectional texts into visual runs in its display order.
+class BiDiLineIterator {
+ public:
+ BiDiLineIterator() : bidi_(NULL) { }
+ ~BiDiLineIterator();
+
+ // Initializes the bidirectional iterator with the specified text. Returns
+ // whether initialization succeeded.
+ UBool Open(const std::wstring& text, bool right_to_left, bool url);
+
+ // Returns the number of visual runs in the text, or zero on error.
+ int CountRuns();
+
+ // Gets the logical offset, length, and direction of the specified visual run.
+ UBiDiDirection GetVisualRun(int index, int* start, int* length);
+
+ // Given a start position, figure out where the run ends (and the BiDiLevel).
+ void GetLogicalRun(int start, int* end, UBiDiLevel* level);
-#endif // CHROME_COMMON_L10N_UTIL_H__
+ private:
+ UBiDi* bidi_;
+
+ DISALLOW_COPY_AND_ASSIGN(BiDiLineIterator);
+};
+
+}
+#endif // CHROME_COMMON_L10N_UTIL_H_