mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
COMMON: add bidi support for U32String
This commit is contained in:
parent
77c96b83a2
commit
c30b22c628
@ -466,25 +466,29 @@ String TranslationManager::convertBiDiString(const String &input) {
|
||||
return TranslationManager::convertBiDiString(input, HE_ISR);
|
||||
}
|
||||
|
||||
#ifdef USE_FRIBIDI
|
||||
String TranslationManager::convertBiDiString(const String &input, const Common::Language lang) {
|
||||
if (lang != HE_ISR) //TODO: modify when we'll support other RTL languages, such as Arabic and Farsi
|
||||
return input;
|
||||
|
||||
return convertBiDiString(input, kWindows1255);
|
||||
}
|
||||
|
||||
String TranslationManager::convertBiDiString(const String &input, const Common::CodePage page) {
|
||||
return convertBiDiU32String(input.decode(page)).encode(page);
|
||||
}
|
||||
|
||||
U32String TranslationManager::convertBiDiU32String(const U32String &input) {
|
||||
|
||||
#ifdef USE_FRIBIDI
|
||||
int buff_length = (input.size() + 2) * 2; // it's more than enough, but it's better to be on the safe side
|
||||
FriBidiChar *input_unicode = (FriBidiChar *)malloc(buff_length * sizeof(FriBidiChar));
|
||||
FriBidiChar *visual_str = (FriBidiChar *)malloc(buff_length * sizeof(FriBidiChar));
|
||||
char *output = (char *)malloc(buff_length);
|
||||
|
||||
FriBidiCharType pbase_dir = FRIBIDI_TYPE_ON;
|
||||
FriBidiCharSet char_set = FRIBIDI_CHAR_SET_ISO8859_8;
|
||||
|
||||
FriBidiStrIndex length = fribidi_charset_to_unicode(char_set, input.c_str(), input.size(), input_unicode);
|
||||
|
||||
if (!fribidi_log2vis(
|
||||
/* input */
|
||||
input_unicode,
|
||||
length,
|
||||
(const FriBidiChar *)input.c_str(),
|
||||
input.size(),
|
||||
&pbase_dir,
|
||||
/* output */
|
||||
visual_str,
|
||||
@ -492,28 +496,21 @@ String TranslationManager::convertBiDiString(const String &input, const Common::
|
||||
NULL, // position_V_to_L_list,
|
||||
NULL // embedding_level_list
|
||||
)) {
|
||||
warning("convertBiDiString: calling fribidi_log2vis failed");
|
||||
free(input_unicode);
|
||||
warning("convertBiDiU32String: calling fribidi_log2vis failed");
|
||||
free(visual_str);
|
||||
free(output);
|
||||
return input;
|
||||
}
|
||||
|
||||
fribidi_unicode_to_charset(char_set, visual_str, length, output);
|
||||
|
||||
String result = String(output);
|
||||
free(input_unicode);
|
||||
U32String result = U32String(visual_str, input.size());
|
||||
free(visual_str);
|
||||
free(output);
|
||||
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
String TranslationManager::convertBiDiString(const String &input, const Common::Language lang) {
|
||||
warning("convertBiDiU32String: Fribidi not available, using input string as fallback");
|
||||
return input;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace Common
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "common/array.h"
|
||||
#include "common/fs.h"
|
||||
#include "common/str.h"
|
||||
#include "common/ustr.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/str-array.h"
|
||||
#include "common/language.h"
|
||||
@ -180,7 +181,9 @@ public:
|
||||
* For LTR (Left To Right) languages, returns the original input
|
||||
* For RTL (Right To Left) languages, returns visual representation of a logical single-line input
|
||||
*/
|
||||
U32String convertBiDiU32String(const U32String &input);
|
||||
String convertBiDiString(const String &input);
|
||||
String convertBiDiString(const String &input, const Common::CodePage page);
|
||||
String convertBiDiString(const String &input, const Common::Language lang);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user