c# - WPF Glyph Run 错误地渲染度数符号

标签 c# .net wpf directx

我正在做一些自定义控件,我有一些文本是通过 Glyph Runs 绘制的

我的问题是 °C 没有被我的字形正确渲染(无论字体系列如何),看起来像这样:

Problem symbol

所以我的字形运行代码(简化)是:

var typeface = new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch);

...

GlyphRun glyphRun = CreateGlyphRun(typeface, "°C", 10, new Point(0,0));
dc.DrawGlyphRun(brush, glyphRun);

在哪里

internal static GlyphRun CreateGlyphRun(Typeface typeface, string text, double size, Point origin)
{
    if (text.Length == 0)
        return null;

    GlyphTypeface glyphTypeface;

    typeface.TryGetGlyphTypeface(out glyphTypeface)

    var glyphIndexes = new ushort[text.Length];
    var advanceWidths = new double[text.Length];

    for (int n = 0; n < text.Length; n++)
    {
        var glyphIndex = (ushort)(text[n] - 29);
        glyphIndexes[n] = glyphIndex;
        advanceWidths[n] = glyphTypeface.AdvanceWidths[glyphIndex] * size;
    }

    var glyphRun = new GlyphRun(glyphTypeface, 0, false, size, glyphIndexes, origin, advanceWidths, null, null,
                                null,
                                null, null, null);
    return glyphRun;
}

我假设它是某种本地化问题。任何帮助,将不胜感激。

最佳答案

尝试替换

var glyphIndex = (ushort)(text[n] - 29);

var glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];

关于c# - WPF Glyph Run 错误地渲染度数符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23296997/

相关文章:

c# - 如何将任何验证控件传递给方法?

.net - EF 4.1 Code First - 将枚举包装器映射为复杂类型

.net - Silverlight 的替代品

c# - 将数据从父级传递到对话框

wpf - 在哪里可以找到 Visual Studio 2010 的 Expression Blend 4?

c# - 找不到类型或命名空间名称 'boolean'

c# foreach 循环写得不好

c# - 无法加载 .NET 程序集

C# WPF 为所有控件设置标签=名称

c# - 确定 DevExpress GridControl 中单击的行