Just to inform you all that i did some research and found out the problem and
a solution:

The primary problem in this case is the fact that commas, spaces, and
numbers are all language-neutral.  By default, these chars are interpreted
as language-neutral character as being the same language as the text
directly preceding the character.  

So, in this case, because all of the characters in the string ", 2001" are
language-neutral, they are interpreted as being the same language as the
text preceding, which is Arabic.  Thus, they are displayed as Arabic
characters (numbers run left-to-right even in the middle of a right-to-left
paragraph in Arabic).

THE SOLUTION:
Split the mix language string into substring containing text with LTR and
RTL run directions and then add the Unicode Left-to-Right mark character
'\u200E' to each RTL substring.


David



dayvidpow wrote:
> 
> I modified the code to call
> columnText.setRunDirection(PdfWriter_DIRECTION_LTR) 
> and now the mix english and arabic text is displaying somewhat correctly. 
> However 
> in some cases the mix english and arabic text is still not being displayed
> properly.
> Especially when there are special chars and numbers involved (e.g.  '(' ,
> ')').
> 
> For example for the following mix english and arabic text string:
> 'Source: Journal Title, Vol. 0, No. 21, The Lyrical Phenomenon/
> <some_arabic_text>, (2001) , pp. 128-160'
> 
> For some strange reason the mix text is outputted to the PDF as:
> 'Source: Journal Title, Vol. 0, No. 21, The Lyrical Phenomenon/ 2001)
> <some_arabic_text>), pp. 128-160'
> 
> That is the (2001) is not getting displayed correctly as it appeared in
> the original text string. Do anyone knows how to prevent this from
> happening ?
> 
> See my code snippet below:
>       Paragraph para = new Paragraph();
>       para.add(new Phrase("Source: ", unicodeFont));
>       para.add(new Phrase(mixEnglishArabicSourceStr, unicodeItalicFont));
>       para.setAlignment(Element.ALIGN_LEFT);
>       columnText.setRunDirection(PdfWriter.RUN_DIRECTION_LTR) ;
>       columnText.addText(para);
>       columnText.go() 
> 
> David
> 
> 
> 
> Paulo Soares wrote:
>> 
>> You must call columnText.setRunDirection(PdfWriter.RUN_DIRECTION_RTL) or
>> columnText.setRunDirection(PdfWriter.RUN_DIRECTION_LTR).
>> 
>> Paulo
>> 
>>> -----Original Message-----
>>> From: [EMAIL PROTECTED] 
>>> [mailto:[EMAIL PROTECTED] On 
>>> Behalf Of dayvidpow
>>> Sent: Wednesday, December 05, 2007 3:08 PM
>>> To: [email protected]
>>> Subject: Re: [iText-questions] Phrase containing 
>>> Chunks/Phrase with multiple Run Directions
>>> 
>>> 
>>> As suggested, I added all the English and Arabic text to a 
>>> Paragraph and then
>>> set
>>> the alignment to Element.ALIGN_LEFT (see code sample below).  
>>> However, the 
>>> mix English and Arabic text output on the same line is still 
>>> not correct.
>>> The Arabic 
>>> text is not getting rendered correctly. 
>>> 
>>> I believe the problem is that English has a run direction of 
>>> Left-to-Right
>>> and Arabic text 
>>> has a run direction of Right-to-Left, but there is no way of 
>>> specifying this
>>> for each 
>>> piece of Arabic or English text added to the Paragraph.
>>> 
>>> Am I missing something here ?
>>> 
>>>             Paragraph para = new Paragraph();
>>>             para.add(new Phrase("Author(s): ", unicodeFont));
>>>             para.add(new Phrase(english_author_name_str1+"/ ",
>>> unicodeItalicFont));
>>>             para.add(new Phrase(arabic_author_name_str1+", ",
>>> unicodeItalicFont)); 
>>>             ....
>>>             para.add(new Phrase(english_author_name_strN+"/ ",
>>> unicodeItalicFont));
>>>             para.add(new Phrase(arabic_author_name_strN+", ",
>>> unicodeItalicFont));
>>>             para.setAlignment(Element.ALIGN_LEFT);
>>>             columnText.addText(para);
>>>             columnText.go()
>>> 
>>> 
>>> David
>>> 
>>> 
>>> 
>>> Paulo Soares wrote:
>>> > 
>>> > You can mix English and Arabic text in the same line and 
>>> both will work
>>> > correctly. You may use the alignment LTR. Both texts must 
>>> be in the same
>>> > Paragraph.
>>> > 
>>> > Paulo 
>>> > 
>>> >> -----Original Message-----
>>> >> From: [EMAIL PROTECTED] 
>>> >> [mailto:[EMAIL PROTECTED] On 
>>> >> Behalf Of dayvidpow
>>> >> Sent: Wednesday, December 05, 2007 1:25 AM
>>> >> To: [email protected]
>>> >> Subject: Re: [iText-questions] Phrase containing 
>>> >> Chunks/Phrase with multiple Run Directions
>>> >> 
>>> >> 
>>> >> The proposed 2 column solution will not work for my 
>>> special situation.
>>> >> Basically, I am reading some journal metadata from xml files 
>>> >> and using this 
>>> >> data to generate and insert a coverpage into existing PDFs.
>>> >> 
>>> >> The journal metadata is of varying length and in various languages.
>>> >> Some of the metadata contains text in 2 different languages with
>>> >> 2 different RUN DIRECTION eg. English and Arabic or English 
>>> >> and Hebrew.
>>> >> So for example: a journal article may have multiple authors -
>>> >> some with English names and some with Arabic names. So the 
>>> >> output should be:
>>> >> 
>>> >> Title: <english_article_title> / <arabic_article_title>
>>> >> Author(s): <englishname>, <english_name>, <arabic_name>,
>>> >> <arabic_name>...<arabic_name>
>>> >> 
>>> >> Now in these special cases i am trying to output the English 
>>> >> portion of the
>>> >> text
>>> >> and the Arabic portion of the text together on the same 
>>> line with auto
>>> >> wrapping 
>>> >> and in the proper order. The data varies in length therefore 
>>> >> i cannot use
>>> >> absolute 
>>> >> positioning (showTextAligned, PdfPTable, etc).  
>>> >> 
>>> >> I don;t know , but maybe this cannot be accomplished using iText ?
>>> >> 
>>> >> David
>>> >> 
>>> >> 
>>> >> Paulo Soares wrote:
>>> >> > 
>>> >> > I think that what you require are different alignments in 
>>> >> the same line.
>>> >> > It's possible to achieve that with a PdfPTable with two 
>>> >> columns without
>>> >> > borders, one left aligned and the other right aligned, both 
>>> >> with no wrap
>>> >> > set. 
>>> >> > 
>>> >> > Paulo
>>> >> > 
>>> >> >> -----Original Message-----
>>> >> >> From: [EMAIL PROTECTED] 
>>> >> >> [mailto:[EMAIL PROTECTED] On 
>>> >> >> Behalf Of dayvidpow
>>> >> >> Sent: Monday, December 03, 2007 6:31 PM
>>> >> >> To: [email protected]
>>> >> >> Subject: [iText-questions] Phrase containing Chunks/Phrase 
>>> >> >> with multiple Run Directions
>>> >> >> 
>>> >> >> 
>>> >> >> Currently, in iText I can create a new Phrase object with a 
>>> >> >> main font and
>>> >> >> then within the Phrase I can have additional Chunks or 
>>> Phrases with
>>> >> >> different fonts.  Therefore, likewise would it be possible 
>>> >> to create a
>>> >> >> Phrase with a main run direction and then add additional 
>>> >> >> Chunks or Phrases
>>> >> >> to it with different run directions ? 
>>> >> >> 
>>> >> >> I know that iText does not currently support thism, but I am 
>>> >> >> just looking at
>>> >> >> how i can possibly extend the Phrase class to meet a special 
>>> >> >> need, Which is
>>> >> >> to output some text in left-to-right and right-to-left 
>>> >> >> language on the same
>>> >> >> line using ColumnText.go() method, instead of 
>>> >> >> ColumnText.showTextAligned
>>> >> >> (which requires absolute positioning).
>>> >> >> 
>>> >> >> Can the Phrase class be extended in this way ?
>> 
>> 
>> Aviso Legal:
>> 
>> Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
>> informação confidencial ou legalmente protegida. A incorrecta transmissão
>> desta mensagem não significa a perca de confidencialidade. Se esta
>> mensagem for recebida por engano, por favor envie-a de volta para o
>> remetente e apague-a do seu sistema de imediato. É proibido a qualquer
>> pessoa que não o destinatário de usar, revelar ou distribuir qualquer
>> parte desta mensagem. 
>> 
>> 
>> 
>> Disclaimer:
>> 
>> This message is destined exclusively to the intended receiver. It may
>> contain confidential or legally protected information. The incorrect
>> transmission of this message does not mean the loss of its
>> confidentiality. If this message is received by mistake, please send it
>> back to the sender and delete it from your system immediately. It is
>> forbidden to any person who is not the intended receiver to use,
>> distribute or copy any part of this message.
>> 
>> 
>> 
>> 
>> -------------------------------------------------------------------------
>> SF.Net email is sponsored by: The Future of Linux Business White Paper
>> from Novell.  From the desktop to the data center, Linux is going
>> mainstream.  Let it simplify your IT future.
>> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Phrase-containing-Chunks-Phrase-with-multiple-Run-Directions-tp14135631p14274583.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to