WPF:字形从右到左的文本呈现

时间:2017-11-25 21:09:59

标签: c# wpf text glyph

我想使用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  ,  س ل ا م

请指导我

-------------------------------------------- ----------

更新

这是Obfuscate解决方案的结果: image1

问题是阿拉伯字母是单独呈现的。

但这就是我想要的: image2

0 个答案:

没有答案