I have a web site built with DevExpress controls including Reports. The main language used is Hebrew so the basic direction is RTL. However there is often a need to include English text, LTR, mixed in the Hebrew text. Their web controls support RTL and usually there isn't a problem with mixed texts.
The problem is with their reports that up until recently did not support RTL. Creating a report entirely in Hebrew was not to much of a problem. Trouble starts when we have Hebrew and English mixed, then the text becomes messed up.
I succeeded in fixing that with the following code:
private string FixBiDirectionalString(string textToFix)
{
try
{
char RLE = '\u202B';
char PDF = '\u202C';
char LRM = '\u200E';
char RLM = '\u200F';
StringBuilder sb = new StringBuilder(textToFix.Replace("\r", "").Replace("\n", string.Format("{0}", '\u000A')));
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("[A-Za-z0-9-+ ]+");
System.Text.RegularExpressions.MatchCollection mc = r.Matches(sb.ToString());
foreach (System.Text.RegularExpressions.Match m in mc)
{
double tmp;
if (m.Value == " ")
continue;
if (double.TryParse(RemoveAcceptedChars(m.Value), out tmp))
continue;
sb.Replace(m.Value, LRM + m.Value + RLM);
}
return RLE + sb.ToString() + PDF;
}
catch { return Text; }
}
private string RemoveAcceptedChars(string p)
{
return p.Replace("+", "").Replace("-", "").Replace("*", "").Replace("/", "");
}
This code is based on code I found in this article XtraReports RTL: bidirectional text drawing in one of the comments.
However I still had a problem with spaces between Hebrew and English words disapearing or being misplaced.
How can that be fixed? (I'm still using an older version of reports that doesn't support RTL).