mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-12 03:56:20 +00:00
COMMON: Introduce BiDi paragraph direction types
This commit is contained in:
parent
9cd8bbafa9
commit
dce92c8e41
@ -26,17 +26,25 @@
|
|||||||
|
|
||||||
#ifdef USE_FRIBIDI
|
#ifdef USE_FRIBIDI
|
||||||
#include <fribidi/fribidi.h>
|
#include <fribidi/fribidi.h>
|
||||||
#else
|
|
||||||
/* This constant is used below in common code
|
|
||||||
* fake it here to lighten code
|
|
||||||
*/
|
|
||||||
#define FRIBIDI_PAR_ON 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
UnicodeBiDiText::UnicodeBiDiText(const Common::U32String &str) :
|
uint32 GetFriBiDiParType(BiDiParagraph dir) {
|
||||||
logical(str), _pbase_dir(FRIBIDI_PAR_ON),
|
#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) {
|
_log_to_vis_index(NULL), _vis_to_log_index(NULL) {
|
||||||
initWithU32String(str);
|
initWithU32String(str);
|
||||||
}
|
}
|
||||||
@ -118,24 +126,24 @@ Common::String bidiByLineHelper(Common::String line, va_list args) {
|
|||||||
return UnicodeBiDiText(line, page, pbase_dir).visual.encode(page);
|
return UnicodeBiDiText(line, page, pbase_dir).visual.encode(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
String convertBiDiStringByLines(const String &input, const Common::CodePage page) {
|
String convertBiDiStringByLines(const String &input, const Common::CodePage page, BiDiParagraph dir) {
|
||||||
uint32 pbase_dir = FRIBIDI_PAR_ON;
|
uint32 pbase_dir = GetFriBiDiParType(dir);
|
||||||
return input.forEachLine(bidiByLineHelper, page, &pbase_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
|
if (lang != Common::HE_ISR) //TODO: modify when we'll support other RTL languages, such as Arabic and Farsi
|
||||||
return input;
|
return input;
|
||||||
|
|
||||||
return Common::convertBiDiString(input, kWindows1255);
|
return Common::convertBiDiString(input, kWindows1255, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
String convertBiDiString(const String &input, const Common::CodePage page) {
|
String convertBiDiString(const String &input, const Common::CodePage page, BiDiParagraph dir) {
|
||||||
return convertBiDiU32String(input.decode(page)).visual.encode(page);
|
return convertBiDiU32String(input.decode(page), dir).visual.encode(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnicodeBiDiText convertBiDiU32String(const U32String &input) {
|
UnicodeBiDiText convertBiDiU32String(const U32String &input, BiDiParagraph dir) {
|
||||||
return UnicodeBiDiText(input);
|
return UnicodeBiDiText(input, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
@ -29,6 +29,15 @@
|
|||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of paragraph directions
|
||||||
|
*/
|
||||||
|
enum BiDiParagraph {
|
||||||
|
BIDI_PAR_ON = 0,
|
||||||
|
BIDI_PAR_RTL = 1,
|
||||||
|
BIDI_PAR_LTR = 2
|
||||||
|
};
|
||||||
|
|
||||||
class UnicodeBiDiText {
|
class UnicodeBiDiText {
|
||||||
private:
|
private:
|
||||||
uint32 *_log_to_vis_index; // from fribidi conversion
|
uint32 *_log_to_vis_index; // from fribidi conversion
|
||||||
@ -40,7 +49,7 @@ public:
|
|||||||
Common::U32String visual; // from fribidi conversion, ordered visually
|
Common::U32String visual; // from fribidi conversion, ordered visually
|
||||||
uint32 _pbase_dir;
|
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 */
|
/* 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(const Common::String &str, const Common::CodePage page, uint32 *pbase_dir);
|
||||||
~UnicodeBiDiText();
|
~UnicodeBiDiText();
|
||||||
@ -56,12 +65,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* just call the constructor for convenience */
|
/* just call the constructor for convenience */
|
||||||
UnicodeBiDiText convertBiDiU32String(const U32String &input);
|
UnicodeBiDiText convertBiDiU32String(const U32String &input, BiDiParagraph dir = BIDI_PAR_ON);
|
||||||
String convertBiDiString(const String &input, const Common::Language lang);
|
String convertBiDiString(const String &input, const Common::Language lang, BiDiParagraph dir = BIDI_PAR_ON);
|
||||||
String convertBiDiString(const String &input, const Common::CodePage page);
|
String convertBiDiString(const String &input, const Common::CodePage page, BiDiParagraph dir = BIDI_PAR_ON);
|
||||||
|
|
||||||
// calls convertBiDiString for each line in isolation
|
// 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
|
} // End of namespace Common
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user