TableSubstitutionRule

TableSubstitutionRule class

表格字体替换规则.

要了解更多信息,请访问使用字体文档文章。

public class TableSubstitutionRule : FontSubstitutionRule

特性

姓名描述
virtual Enabled { get; set; }指定规则是否启用。

方法

姓名描述
AddSubstitutes(string, params string[])为给定的原始字体名称添加替代字体名称。
GetSubstitutes(string)返回包含指定原始字体名称的替代字体名称的数组。
Load(Stream)从 XML 流加载表替换设置。
Load(string)从 XML 文件加载表替换设置。
LoadAndroidSettings()加载 Android 平台的预定义表替换设置。
LoadLinuxSettings()加载 Linux 平台的预定义表替换设置。
LoadWindowsSettings()加载适用于 Windows 平台的预定义表替换设置。
Save(Stream)将当前表替换设置保存到流。
Save(string)将当前表替换设置保存到文件。
SetSubstitutes(string, params string[])覆盖给定原始字体名称的替代字体名称。

评论

此规则定义在原始字体不可用时要使用的替代字体名称列表。 将检查字体名称的替代项和AltName(如果有).

例子

展示如何访问 Windows 和 Linux 的字体替换表。

Document doc = new Document();
FontSettings fontSettings = new FontSettings();
doc.FontSettings = fontSettings;

// 创建一个新的表替换规则并加载默认的 Microsoft Windows 字体替换表。
TableSubstitutionRule tableSubstitutionRule = fontSettings.SubstitutionSettings.TableSubstitution;
tableSubstitutionRule.LoadWindowsSettings();

// 在 Windows 中,“Times New Roman CE”字体的默认替代字体是“Times New Roman”。
Assert.AreEqual(new[] {"Times New Roman"},
    tableSubstitutionRule.GetSubstitutes("Times New Roman CE").ToArray());

// 我们可以将表保存为 XML 文档的形式。
tableSubstitutionRule.Save(ArtifactsDir + "FontSettings.TableSubstitutionRule.Windows.xml");

// Linux 有自己的替换表。
// “Times New Roman CE” 有多个替代字体。
// 如果第一个替代品“FreeSerif”也不可用,
// 此规则将循环遍历数组中的其他规则,直到找到可用的规则。
tableSubstitutionRule.LoadLinuxSettings();
Assert.AreEqual(new[] {"FreeSerif", "Liberation Serif", "DejaVu Serif"},
    tableSubstitutionRule.GetSubstitutes("Times New Roman CE").ToArray());

// 使用流将 Linux 替换表保存为 XML 文档的形式。
using (FileStream fileStream = new FileStream(ArtifactsDir + "FontSettings.TableSubstitutionRule.Linux.xml",
    FileMode.Create))
{
    tableSubstitutionRule.Save(fileStream);
}

也可以看看