我使用C# WPF和Stimulsoft
当需要显示时,我想发送我的字体文件嵌入到我的报告中的路径
我在(我的WPF项目)中嵌入了字体,我使用它的方式如下:
XAML中的 :
<Label x:Name="preloader" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="Loading . . ." Margin="319,178,48,34" FontFamily="/WpfApp5;component/FNT/#B Titr" FontSize="48" Background="White"/>
字体是从我的项目中的字体文件夹中嵌入的:
因为我的报告是用刺激性软件生成的,所以我不能嵌入字体,但是我可以发送字体enter link description here的路径。
通过这个,我可以向它发送我的字体路径:
为此,我尝试了两种方式
C#代码:
1-:
StiFontCollection.AddFontFile(@"pack://application:,,,/FNT/#B Titr");
本例将显示此错误:
System.NotSupportedException:“给定路径的格式不支持。”
2-:
var fntpath = Assembly.GetEntryAssembly().GetManifestResourceStream("WpfApp5.FNT.BTITRBD.TTF");
StiFontCollection.AddFontFile(fntpath.ToString());
在这个fntpath.ToString()中为null!
怎么做?
请帮帮忙
发布于 2021-09-13 10:03:55
AddFontFile
方法期望磁盘上的物理文件的路径。您不能传入pack:
URI,因为它不理解这种格式。您不能只在一个.ToString()
上调用Stream
,因为这不会产生任何有意义的信息。
您需要将字体文件解压缩到临时文件,并将该文件的路径传递给AddFontFile
方法。
string tempPath = Path.GetTempPath();
string fileName = "WpfApp5.FNT.BTITRBD.TTF";
string fontPath = Path.Combine(tempPath, fileName);
if (!File.Exists(fontPath))
{
using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(fileName))
using (var output = File.Create(fontPath))
{
stream.CopyTo(output);
}
}
StiFontCollection.AddFontFile(fontPath);
https://stackoverflow.com/questions/69140558
复制相似问题