+ applied patch from itayperl (bidi-mirroring-SVN-r3110.patch)
This commit is contained in:
parent
6575e34973
commit
aba5f21936
2 changed files with 24 additions and 66 deletions
|
@ -61,6 +61,7 @@ extern "C"
|
|||
// icu
|
||||
#include <unicode/ubidi.h>
|
||||
#include <unicode/ushape.h>
|
||||
#include <unicode/schriter.h>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
|
|
@ -230,82 +230,39 @@ void font_face_set::get_string_info(string_info & info)
|
|||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
UnicodeString reordered;
|
||||
UnicodeString shaped;
|
||||
|
||||
UnicodeString const& ustr = info.get_string();
|
||||
const UChar * text = ustr.getBuffer();
|
||||
UBiDi * bidi = ubidi_openSized(ustr.length(),0,&err);
|
||||
int32_t length = ustr.length();
|
||||
|
||||
if (U_SUCCESS(err))
|
||||
{
|
||||
ubidi_setPara(bidi,text,ustr.length(), UBIDI_DEFAULT_LTR,0,&err);
|
||||
UBiDi *bidi = ubidi_openSized(length, 0, &err);
|
||||
ubidi_setPara(bidi, ustr.getBuffer(), length, UBIDI_DEFAULT_LTR, 0, &err);
|
||||
|
||||
if (U_SUCCESS(err))
|
||||
{
|
||||
int32_t count = ubidi_countRuns(bidi,&err);
|
||||
int32_t logicalStart;
|
||||
int32_t length;
|
||||
ubidi_writeReordered(bidi, reordered.getBuffer(length),
|
||||
length, UBIDI_DO_MIRRORING, &err);
|
||||
|
||||
for (int32_t i=0; i< count;++i)
|
||||
{
|
||||
if (UBIDI_LTR == ubidi_getVisualRun(bidi,i,&logicalStart,&length))
|
||||
{
|
||||
do {
|
||||
UChar ch = text[logicalStart++];
|
||||
dimension_t char_dim = character_dimensions(ch);
|
||||
info.add_info(ch, char_dim.width, char_dim.height);
|
||||
width += char_dim.width;
|
||||
height = char_dim.height > height ? char_dim.height : height;
|
||||
reordered.releaseBuffer(length);
|
||||
|
||||
} while (--length > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
logicalStart += length;
|
||||
u_shapeArabic(reordered.getBuffer(), length,
|
||||
shaped.getBuffer(length), length,
|
||||
U_SHAPE_LETTERS_SHAPE | U_SHAPE_LENGTH_FIXED_SPACES_NEAR |
|
||||
U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &err);
|
||||
|
||||
int32_t j=0,i=length;
|
||||
UnicodeString arabic;
|
||||
UChar * buf = arabic.getBuffer(length);
|
||||
do {
|
||||
UChar ch = text[--logicalStart];
|
||||
buf[j++] = ch;
|
||||
} while (--i > 0);
|
||||
shaped.releaseBuffer(length);
|
||||
|
||||
arabic.releaseBuffer(length);
|
||||
if ( *arabic.getBuffer() >= 0x0600 && *arabic.getBuffer() <= 0x06ff)
|
||||
{
|
||||
UnicodeString shaped;
|
||||
u_shapeArabic(arabic.getBuffer(),arabic.length(),shaped.getBuffer(arabic.length()),arabic.length(),
|
||||
U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR|
|
||||
U_SHAPE_TEXT_DIRECTION_VISUAL_LTR
|
||||
,&err);
|
||||
|
||||
shaped.releaseBuffer(arabic.length());
|
||||
|
||||
if (U_SUCCESS(err))
|
||||
{
|
||||
for (int j=0;j<shaped.length();++j)
|
||||
{
|
||||
dimension_t char_dim = character_dimensions(shaped[j]);
|
||||
info.add_info(shaped[j], char_dim.width, char_dim.height);
|
||||
width += char_dim.width;
|
||||
height = char_dim.height > height ? char_dim.height : height;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Non-Arabic RTL
|
||||
for (int j=0;j<arabic.length();++j)
|
||||
{
|
||||
dimension_t char_dim = character_dimensions(arabic[j]);
|
||||
info.add_info(arabic[j], char_dim.width, char_dim.height);
|
||||
width += char_dim.width;
|
||||
height = char_dim.height > height ? char_dim.height : height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (U_SUCCESS(err)) {
|
||||
StringCharacterIterator iter(shaped);
|
||||
for (iter.setToStart(); iter.hasNext();) {
|
||||
UChar ch = iter.nextPostInc();
|
||||
dimension_t char_dim = character_dimensions(ch);
|
||||
info.add_info(ch, char_dim.width, char_dim.height);
|
||||
width += char_dim.width;
|
||||
height = (char_dim.height > height) ? char_dim.height : height;
|
||||
}
|
||||
ubidi_close(bidi);
|
||||
}
|
||||
|
||||
ubidi_close(bidi);
|
||||
info.set_dimensions(width, height);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue