mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 06:01:17 +02:00
- added support for libfribidi for languages requiring complex text rendering like Arabic and Hebrew
This commit is contained in:
@@ -34,6 +34,11 @@ using namespace Shared::Graphics::Gl;
|
||||
#include "util.h"
|
||||
#include "platform_common.h"
|
||||
#include "platform_util.h"
|
||||
|
||||
#ifdef HAVE_FRIBIDI
|
||||
#include <fribidi.h>
|
||||
#endif
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -303,6 +308,39 @@ void Font::setSize(int size) {
|
||||
}
|
||||
}
|
||||
|
||||
void Font::bidi_cvt(string &str_) {
|
||||
#ifdef HAVE_FRIBIDI
|
||||
char *c_str = const_cast<char *>(str_.c_str()); // fribidi forgot const...
|
||||
FriBidiStrIndex len = str_.length();
|
||||
FriBidiChar *bidi_logical = new FriBidiChar[len + 2];
|
||||
FriBidiChar *bidi_visual = new FriBidiChar[len + 2];
|
||||
char *utf8str = new char[4*len + 1]; //assume worst case here (all 4 Byte characters)
|
||||
FriBidiCharType base_dir = FRIBIDI_TYPE_ON;
|
||||
FriBidiStrIndex n;
|
||||
|
||||
|
||||
#ifdef OLD_FRIBIDI
|
||||
n = fribidi_utf8_to_unicode (c_str, len, bidi_logical);
|
||||
#else
|
||||
n = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, c_str, len, bidi_logical);
|
||||
#endif
|
||||
fribidi_log2vis(bidi_logical, n, &base_dir, bidi_visual, NULL, NULL, NULL);
|
||||
#ifdef OLD_FRIBIDI
|
||||
fribidi_unicode_to_utf8 (bidi_visual, n, utf8str);
|
||||
#else
|
||||
fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, bidi_visual, n, utf8str);
|
||||
#endif
|
||||
//is_rtl_ = base_dir == FRIBIDI_TYPE_RTL;
|
||||
//fontIsRightToLeft = base_dir == FRIBIDI_TYPE_RTL;
|
||||
fontIsRightToLeft = false;
|
||||
|
||||
str_ = std::string(utf8str);
|
||||
delete[] bidi_logical;
|
||||
delete[] bidi_visual;
|
||||
delete[] utf8str;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Font2D
|
||||
// ===============================================
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "string_utils.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
@@ -58,6 +59,7 @@ void TextRenderer2DGl::render(const string &text, float x, float y, bool centere
|
||||
}
|
||||
|
||||
string renderText = text;
|
||||
Font::bidi_cvt(renderText);
|
||||
int line = 0;
|
||||
int size = font->getSize();
|
||||
const unsigned char *utext = NULL;
|
||||
@@ -388,6 +390,8 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
|
||||
|
||||
if(text.empty() == false) {
|
||||
string renderText = text;
|
||||
Font::bidi_cvt(renderText);
|
||||
|
||||
if(Font::fontIsMultibyte == true) {
|
||||
if(font->getTextHandler() != NULL) {
|
||||
if(Font::fontIsRightToLeft == true) {
|
||||
|
Reference in New Issue
Block a user