Paulo Soares | 4 Dec 11:24 2007
Picon

Re: Phrase containing Chunks/Phrase with multiple Run Directions

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: itext-questions-bounces <at> lists.sourceforge.net 
> [mailto:itext-questions-bounces <at> lists.sourceforge.net] On 
> Behalf Of dayvidpow
> Sent: Monday, December 03, 2007 6:31 PM
> To: itext-questions <at> lists.sourceforge.net
> 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 
(Continue reading)

dayvidpow | 5 Dec 02:25 2007
Picon

Re: 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.
(Continue reading)

Paulo Soares | 5 Dec 12:01 2007
Picon

Re: Phrase containing Chunks/Phrase with multiple Run Directions

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: itext-questions-bounces <at> lists.sourceforge.net 
> [mailto:itext-questions-bounces <at> lists.sourceforge.net] On 
> Behalf Of dayvidpow
> Sent: Wednesday, December 05, 2007 1:25 AM
> To: itext-questions <at> lists.sourceforge.net
> 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>
(Continue reading)

dayvidpow | 5 Dec 16:08 2007
Picon

Re: 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()
(Continue reading)

Paulo Soares | 5 Dec 17:37 2007
Picon

Re: Phrase containing Chunks/Phrase with multiple Run Directions

You must call columnText.setRunDirection(PdfWriter.RUN_DIRECTION_RTL) or
columnText.setRunDirection(PdfWriter.RUN_DIRECTION_LTR).

Paulo

> -----Original Message-----
> From: itext-questions-bounces <at> lists.sourceforge.net 
> [mailto:itext-questions-bounces <at> lists.sourceforge.net] On 
> Behalf Of dayvidpow
> Sent: Wednesday, December 05, 2007 3:08 PM
> To: itext-questions <at> lists.sourceforge.net
> 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
(Continue reading)

dayvidpow | 7 Dec 18:16 2007
Picon

Re: Phrase containing Chunks/Phrase with multiple Run Directions


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() 

(Continue reading)

dayvidpow | 11 Dec 15:14 2007
Picon

Re: Phrase containing Chunks/Phrase with multiple Run Directions


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.
(Continue reading)


Gmane