右から左の言語のテキスト(アラビア語または英語とアラビア語の組み合わせなど)をレンダリングするにはGlyphを使用します。WPF:グリフの右から左へのテキストのレンダリング
私はこのコードを使用しています:
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);
をしかし、問題はこのように、アラビア文字は別々に示されているということです。
Hello , س ل ا م
くれ
を案内してください--- -------------------------------------------------- -
UPDATE:
問題は、アラビア語の文字が別々にレンダリングされていることです。
2に侵入する必要がある場合があります文字列はLRTであり、O therはRTL – codebender
なぜ最初にグリフを使用する必要がありますか?おそらく、テキストをレンダリングするために高水準の機能を利用するのではなく、レバーをあまりに低くしすぎているのでしょうか? WPFコントロールは最初にテキストをOKにしますか? –
@George、私はGlyphを使用する必要があります(上記のコードは小さなサンプルです)、私はこの素晴らしいGithubプロジェクトがすべてのWPFテキストレンダリング手法をテストすることを発見しました(https://github.com/dgrunwald/WPF-Text-Rendering-Benchmark)、私はGlyphが必要なものであることに気付きました。 –