I want to use Glyph to render right-to-left languages text (e.g. Arabic or mix English and Arabic).
I'm using this code:
Typeface typeface = new Typeface(new FontFamily("Arial"),
FontStyles.Italic,
FontWeights.Normal,
FontStretches.Normal);
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
throw new InvalidOperationException("No glyphtypeface found");
string text = "Hello , سلام";
double size = 40;
ushort[] glyphIndexes = new ushort[text.Length];
double[] advanceWidths = new double[text.Length];
double totalWidth = 0;
for (int n = 0; n < text.Length; n++)
{
ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];
glyphIndexes[n] = glyphIndex;
double width = glyphTypeface.AdvanceWidths[glyphIndex] * size;
advanceWidths[n] = width;
totalWidth += width;
}
Point origin = new Point(50, 50);
GlyphRun glyphRun = new GlyphRun(glyphTypeface, 0, false, size,
glyphIndexes, origin, advanceWidths, null, null, null, null,
null, null);
dc.DrawGlyphRun(Brushes.Black, glyphRun);
But the problem is that Arabic characters are shown separately, like this:
Hello , س ل ا م
please guide me
------------------------------------------------------
UPDATE:
This is result of Obfuscate's solution:
The problem is that the Arabic letters are rendered separately.