Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF Glyph运行不正确渲染度符号_C#_.net_Wpf_Directx - Fatal编程技术网

C# WPF Glyph运行不正确渲染度符号

C# WPF Glyph运行不正确渲染度符号,c#,.net,wpf,directx,C#,.net,Wpf,Directx,我正在做一些自定义控件,我有一些文本是通过Glyph运行绘制的 我的问题是,我的字形(无论字体系列如何)无法正确渲染°C,看起来如下所示: 因此,我的glyph运行代码(简化)是: var typeface = new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch); ... GlyphRun glyphRun = CreateGlyphRun(typeface, "°C", 10,

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

我的问题是,我的字形(无论字体系列如何)无法正确渲染°C,看起来如下所示:

因此,我的glyph运行代码(简化)是:

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);
在哪里

内部静态GlyphRun CreateGlyphRun(字体、字符串文本、双尺寸、点原点)
{
如果(text.Length==0)
返回null;
字形字体字形字体;
字体。tryGetGlyphType(外字形字体)
var glyph index=new-ushort[text.Length];
var advanceWidths=新的双精度[text.Length];
for(int n=0;n
我认为这是某种本地化问题。任何帮助都将不胜感激

改用?使用时,学位标志将显示:

<Glyphs FontUri="C:\WINDOWS\Fonts\SegoeUI.TTF" FontRenderingEmSize="80" 
    StyleSimulations="BoldSimulation" UnicodeString="It's 30°C" 
    Fill="Black" HorizontalAlignment="Center" VerticalAlignment="Center" />

尝试更换

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


这类问题通常是因为特定字体系列没有特定字符。。。你能确认你用过的字体有这个字符吗?如果没有,你应该能够为那个角色使用不同的字体系列,就像我使用SegoeUI一样。如果将文本块与Segoe UI一起使用,则会显示符号。只有当我在字形运行中使用字体时,符号才会正确显示。我使用字形运行是因为我通过DrawingContext(而不是XAML)进行渲染,它只接受字形运行。+1很好!最初的代码很可能是为了消除映射查找,并使用了“subtract 29”公式,但这种方法在当前字体系列中失败了。
var glyphIndex = (ushort)(text[n] - 29);
var glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];