【发布时间】:2015-01-16 01:13:03
【问题描述】:
我有一个压缩文件夹,其中包含我需要打开和使用的字体(除其他外)。我知道我可以将字体提取到临时文件夹并以这种方式使用它,但如果可能的话,我宁愿找到一种解决方案将其保存在内存中。
我正在使用 System.IO.Compression 将字体作为流获取,但从那时起我有点卡住了!
using (ZipArchive zipArchive = ZipFile.Open(filelocation, ZipArchiveMode.Update))
{
ZipArchiveEntry fontEntry = zipArchive.Entries.FirstOrDefault(ze => ze.Name.EndsWith("ttf"));
if (fontEntry != null)
{
Stream fontStream = fontEntry.Open();
// I need a TextBlock to somehow use this stream as the FontFamily
}
}
我查看了 System.IO.Packaging 来打包流,然后尝试使用包 URI 加载字体系列,但我无法让它工作。
【问题讨论】:
-
是否可以将字体的路径指定为
c:\folder\file.zip\fontname.ttf? -
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
PrivateFontCollection.AddMemoryFont可能对你有用,我以前从未尝试过,但它可能会完成这项工作 -
对不起约翰,我不会再放标签了。
-
Red Serpent,我在其他地方读到 PrivateFontCollection 不能与 WPF 一起使用?