Hi

Thanks for bringing that to attention. At the moment rtl is not supported.

I would not rely on a regex to determine the text direction after all perhaps some one intend to display it in the other run direction?
I would opt for using CSS to set the run direction. Just like in html
 {
direction:rtl;
}

the encoding should be settable in the same way, we can add an xmlworker specific css property for that. Forcing .CP1252 is not a good idea, that's right.


Thanks for the idea
ps: please don't hijack other threads, write a new message for a new topic, I almost mist this mail.

On 8/12/2011 22:34, Vahid Nasiri wrote:
Hello,
In iTextSharp.tool.xml.css.apply.ChunkCssApplier class, String encoding is hardcoded to BaseFont.CP1252.
It's easy to detect right to left languages data:
static readonly Regex MatchArabicHebrew = new Regex(@"[\u0600-\u06FF,\u0590-\u05FF]+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static bool IsRtl(string data)
{
if (string.IsNullOrEmpty(data)) return false;
return MatchArabicHebrew.IsMatch(data);
}
And then we can improve Apply method of ChunkCssApplier class for instance:
public Chunk Apply(Chunk c, Tag t)
{
String fontName = null;
String encoding = BaseFont.CP1252;
if (IsRtl(c.Content)) encoding = BaseFont.IDENTITY_H;
Also run_direction should be set for PdfPCell and other similar elements to RTL.
Ex. iTextSharp.tool.xml.html.table.TableData class
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) {
HtmlCell cell = new HtmlCell();
IList<IElement> l = new List<IElement>(1);
foreach (IElement e in currentContent) {
if(e is Chunk)
if (IsRtl(((Chunk)e).Content))
{
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
}




--
twitter <http://twitter.com/redlabbe>
redlab-log <http://www.redlab.be/blog/>
------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to