我想使用Glyph来渲染从右向左的语言文本(例如阿拉伯语或混合英语和阿拉伯语)。WPF:Glyph从右到左的文本渲染
我使用这个代码:
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:
的问题是阿拉伯字母分别呈现。
可能不得不分成两个因为一个是LRT和o它是RTL – codebender
为什么你需要首先使用字形?也许你工作的杠杆太低,而不是利用一些更高级别的工具来呈现文本? WPF控件是否首先呈现文本OK? –
@George,因为性能需要使用字形(上面的代码是一个小示例),我发现[这个伟大的Github项目测试所有WPF文本渲染方法](https://github.com/dgrunwald/WPF-Text-Rendering-Benchmark),我意识到雕文是我需要的。 –