SystemFontSource
内容
[
隐藏
]
SystemFontSource class
表示安装到系统中的所有 TrueType 字体。
public class SystemFontSource : FontSourceBase
构造函数
姓名 | 描述 |
---|---|
SystemFontSource() | 克托尔. |
SystemFontSource(int) | 克托尔. |
特性
姓名 | 描述 |
---|---|
Priority { get; } | 返回字体源优先级。 |
override Type { get; } | 返回字体源的类型。 |
WarningCallback { get; set; } | 当检测到可能导致格式保真度丢失的问题时,在处理字体源期间调用。 |
方法
姓名 | 描述 |
---|---|
GetAvailableFonts() | 返回通过此源可用的字体列表。 |
static GetSystemFontFolders() | 如果文件夹不可访问,则返回系统字体文件夹或空数组。 |
例子
显示如何访问文档的系统字体源和设置字体替换。
Document doc = new Document();
doc.FontSettings = new FontSettings();
// 默认情况下,空白文档始终包含系统字体源。
Assert.AreEqual(1, doc.FontSettings.GetFontsSources().Length);
SystemFontSource systemFontSource = (SystemFontSource) doc.FontSettings.GetFontsSources()[0];
Assert.AreEqual(FontSourceType.SystemFonts, systemFontSource.Type);
Assert.AreEqual(0, systemFontSource.Priority);
PlatformID pid = Environment.OSVersion.Platform;
bool isWindows = (pid == PlatformID.Win32NT) || (pid == PlatformID.Win32S) ||
(pid == PlatformID.Win32Windows) || (pid == PlatformID.WinCE);
if (isWindows)
{
const string fontsPath = @"C:\WINDOWS\Fonts";
Assert.AreEqual(fontsPath.ToLower(),
SystemFontSource.GetSystemFontFolders().FirstOrDefault()?.ToLower());
}
foreach (string systemFontFolder in SystemFontSource.GetSystemFontFolders())
{
Console.WriteLine(systemFontFolder);
}
// 设置一种存在于 Windows 字体目录中的字体来替代不存在的字体。
doc.FontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;
doc.FontSettings.SubstitutionSettings.TableSubstitution.AddSubstitutes("Kreon-Regular", new[] {"Calibri"});
Assert.AreEqual(1,
doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").Count());
Assert.Contains("Calibri",
doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").ToArray());
// 或者,我们可以添加一个文件夹字体源,其中相应的文件夹包含字体。
FolderFontSource folderFontSource = new FolderFontSource(FontsDir, false);
doc.FontSettings.SetFontsSources(new FontSourceBase[] {systemFontSource, folderFontSource});
Assert.AreEqual(2, doc.FontSettings.GetFontsSources().Length);
// 重置字体源仍然给我们留下系统字体源以及我们的替代品。
doc.FontSettings.ResetFontSources();
Assert.AreEqual(1, doc.FontSettings.GetFontsSources().Length);
Assert.AreEqual(FontSourceType.SystemFonts, doc.FontSettings.GetFontsSources()[0].Type);
Assert.AreEqual(1,
doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").Count());
也可以看看
- class FontSourceBase
- 命名空间 Aspose.Words.Fonts
- 部件 Aspose.Words