partially balanced arabic text
Jarek M <[email protected]> Wed, 05 Sep 2012 11:15:55 +0200
| Newsgroups | gmane.comp.internationalization.fribidi |
|---|---|
| Message-ID | <[email protected]> |
Hi. I'm bumping into a following problem. I got a fribidi 0.19.2 running,
used to parse in webkit the contents of TextRun.h (pointer to array passed
as a buffer with arabic characters). When converting (mirroring and
positioning LTR) and later writing to the screen, I get all the characters
mirrored but majority of sentences are written RTL. Attached example and
the code. Any hints how to resolve this?
I tried several methods of setting up paragraph conversion, all producing
pretty much same result.
The code I used is below.
bool lRes = false;
FriBidiParType pBase;
FriBidiCharType *pCharTypes;
FriBidiChar *visualStr;
int i = 0, cnt = 0;
FriBidiStrIndex *posLtoVlist;
FriBidiStrIndex *posVtoLlist;
FriBidiLevel *embedLevelList;
FriBidiChar *fribidi_characters;
FriBidiStrIndex iLen = 0;
// if (m_rtl)
// pBase = FRIBIDI_PAR_RTL;
// else
// pBase = FRIBIDI_PAR_LTR;
iLen = (m_len + 1) << 2;
fribidi_characters = (FriBidiChar *)malloc(iLen *
sizeof(FriBidiChar));
pCharTypes = (FriBidiCharType*) malloc(iLen *
sizeof(FriBidiCharType));
visualStr = (FriBidiChar *)malloc(iLen * sizeof(FriBidiChar));
posLtoVlist = (FriBidiStrIndex*)malloc(iLen *
sizeof(FriBidiStrIndex));
posVtoLlist = (FriBidiStrIndex*)malloc(iLen *
sizeof(FriBidiStrIndex));
embedLevelList = (FriBidiLevel*)malloc(iLen *
sizeof(FriBidiLevel));
UErrorCode pErrorCode = U_ZERO_ERROR;
u_strToUTF32((UChar32 *)fribidi_characters, iLen, &iLen,
m_characters, m_len, &pErrorCode);
fribidi_get_bidi_types(fribidi_characters,iLen, pCharTypes);
pBase = fribidi_get_par_direction(pCharTypes, iLen);
if(m_shaped_characters) // I am not sure who calls it and where,
not sure who is responsible for memory management
{
delete [] m_shaped_characters;
}
lRes = fribidi_log2vis( /* input */fribidi_characters, iLen,
&pBase,
/* output */ visualStr, posVtoLlist, posLtoVlist,
embedLevelList );
iLen = fribidi_remove_bidi_marks(visualStr, iLen, posVtoLlist,
posLtoVlist, embedLevelList);
m_shaped_characters = (UChar *)malloc(sizeof(UChar) * (iLen+1));
u_strFromUTF32(m_shaped_characters, sizeof(UChar) * (iLen+1), NULL,
(UChar32 *)visualStr, iLen, &pErrorCode);
m_shaped_characters[iLen] = '\0';
m_len = iLen;
if(pErrorCode)
{
FILE *file_present =
fopen("/mnt/ota/system/core/fribidi.txt","a+");
fprintf(file_present, "BCTextRunWK.cpp:
TextRun::doShapeCharacters() failure 2. iLen is:
%i\n",pErrorCode);
fclose(file_present);
// LOG AN ERROR AND GET THE HELL OUT OF HERE!!!
free(posLtoVlist);
free(posVtoLlist);
free(embedLevelList);
free(fribidi_characters);
free(pCharTypes);
free(visualStr);
delete [] m_shaped_characters;
m_len = 0;
return;
}
free(posLtoVlist);
free(posVtoLlist);
free(embedLevelList);
free(fribidi_characters);
free(pCharTypes);
free(visualStr);
I draw m_shaped_characters using skia, and the results sometimes are drawn correctly, and sometimes LTR with all fonts mirrored.
Am I using the code correctly? Are there some other methods You would
recommend to use to draw arabic in an older version of webkit? (it is embedded)
Rgards,
Jarek