diff --git a/common/unicode-bidi.cpp b/common/unicode-bidi.cpp index faa6328db7b..340a0720762 100644 --- a/common/unicode-bidi.cpp +++ b/common/unicode-bidi.cpp @@ -26,17 +26,25 @@ #ifdef USE_FRIBIDI #include -#else -/* This constant is used below in common code - * fake it here to lighten code - */ -#define FRIBIDI_PAR_ON 0 #endif namespace Common { -UnicodeBiDiText::UnicodeBiDiText(const Common::U32String &str) : - logical(str), _pbase_dir(FRIBIDI_PAR_ON), +uint32 GetFriBiDiParType(BiDiParagraph dir) { +#ifdef USE_FRIBIDI + if (dir == BIDI_PAR_ON) { + return FRIBIDI_PAR_ON; + } else if (dir == BIDI_PAR_RTL) { + return FRIBIDI_PAR_RTL; + } else if (dir == BIDI_PAR_LTR) { + return FRIBIDI_PAR_LTR; + } +#endif + return 0; +} + +UnicodeBiDiText::UnicodeBiDiText(const Common::U32String &str, BiDiParagraph dir) : + logical(str), _pbase_dir(GetFriBiDiParType(dir)), _log_to_vis_index(NULL), _vis_to_log_index(NULL) { initWithU32String(str); } @@ -118,24 +126,24 @@ Common::String bidiByLineHelper(Common::String line, va_list args) { return UnicodeBiDiText(line, page, pbase_dir).visual.encode(page); } -String convertBiDiStringByLines(const String &input, const Common::CodePage page) { - uint32 pbase_dir = FRIBIDI_PAR_ON; +String convertBiDiStringByLines(const String &input, const Common::CodePage page, BiDiParagraph dir) { + uint32 pbase_dir = GetFriBiDiParType(dir); return input.forEachLine(bidiByLineHelper, page, &pbase_dir); } -String convertBiDiString(const String &input, const Common::Language lang) { +String convertBiDiString(const String &input, const Common::Language lang, BiDiParagraph dir) { if (lang != Common::HE_ISR) //TODO: modify when we'll support other RTL languages, such as Arabic and Farsi return input; - return Common::convertBiDiString(input, kWindows1255); + return Common::convertBiDiString(input, kWindows1255, dir); } -String convertBiDiString(const String &input, const Common::CodePage page) { - return convertBiDiU32String(input.decode(page)).visual.encode(page); +String convertBiDiString(const String &input, const Common::CodePage page, BiDiParagraph dir) { + return convertBiDiU32String(input.decode(page), dir).visual.encode(page); } -UnicodeBiDiText convertBiDiU32String(const U32String &input) { - return UnicodeBiDiText(input); +UnicodeBiDiText convertBiDiU32String(const U32String &input, BiDiParagraph dir) { + return UnicodeBiDiText(input, dir); } } // End of namespace Common diff --git a/common/unicode-bidi.h b/common/unicode-bidi.h index 3e06d76ed24..a9eedb8746a 100644 --- a/common/unicode-bidi.h +++ b/common/unicode-bidi.h @@ -29,6 +29,15 @@ namespace Common { +/** + * List of paragraph directions + */ +enum BiDiParagraph { + BIDI_PAR_ON = 0, + BIDI_PAR_RTL = 1, + BIDI_PAR_LTR = 2 +}; + class UnicodeBiDiText { private: uint32 *_log_to_vis_index; // from fribidi conversion @@ -40,7 +49,7 @@ public: Common::U32String visual; // from fribidi conversion, ordered visually uint32 _pbase_dir; - UnicodeBiDiText(const Common::U32String &str); + UnicodeBiDiText(const Common::U32String &str, BiDiParagraph dir = BIDI_PAR_ON); /* This constructor shouldn't be used outside of unicode-bidi.cpp file */ UnicodeBiDiText(const Common::String &str, const Common::CodePage page, uint32 *pbase_dir); ~UnicodeBiDiText(); @@ -56,12 +65,12 @@ public: }; /* just call the constructor for convenience */ -UnicodeBiDiText convertBiDiU32String(const U32String &input); -String convertBiDiString(const String &input, const Common::Language lang); -String convertBiDiString(const String &input, const Common::CodePage page); +UnicodeBiDiText convertBiDiU32String(const U32String &input, BiDiParagraph dir = BIDI_PAR_ON); +String convertBiDiString(const String &input, const Common::Language lang, BiDiParagraph dir = BIDI_PAR_ON); +String convertBiDiString(const String &input, const Common::CodePage page, BiDiParagraph dir = BIDI_PAR_ON); // calls convertBiDiString for each line in isolation -String convertBiDiStringByLines(const String &input, const Common::CodePage page); +String convertBiDiStringByLines(const String &input, const Common::CodePage page, BiDiParagraph dir = BIDI_PAR_ON); } // End of namespace Common