FontInfoCollection

FontInfoCollection class

表示文档中使用的字体集合。

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

public class FontInfoCollection : IEnumerable<FontInfo>

特性

姓名描述
Count { get; }获取集合中包含的元素数量。
EmbedSystemFonts { get; set; }指定是否将系统字体嵌入到文档中。 该属性的默认值为错误的
EmbedTrueTypeFonts { get; set; }指定保存文档时是否在文档中嵌入 TrueType 字体。 此属性的默认值为错误的.
Item { get; }获取具有指定名称的字体。 (2 indexers)
SaveSubsetFonts { get; set; }指定是否将嵌入的 TrueType 字体的子集与文档一起保存。 此属性的默认值为错误的

方法

姓名描述
Contains(string)确定集合中是否包含具有给定名称的字体。
GetEnumerator()返回一个枚举器对象,可用于迭代集合中的所有项目。

评论

物品有FontInfo对象。

您不直接创建此类的实例。 使用FontInfos属性来访问文档中定义的字体 集合。

例子

演示如何打印文档中存在的字体的详细信息。

Document doc = new Document(MyDir + "Embedded font.docx");

FontInfoCollection allFonts = doc.FontInfos;
// 打印文档中所有已使用和未使用的字体。
for (int i = 0; i < allFonts.Count; i++)
{
    Console.WriteLine($"Font index #{i}");
    Console.WriteLine($"\tName: {allFonts[i].Name}");
    Console.WriteLine($"\tIs {(allFonts[i].IsTrueType ? "" : "not ")}a trueType font");
}

演示如何保存嵌入 TrueType 字体的文档。

Document doc = new Document(MyDir + "Document.docx");

FontInfoCollection fontInfos = doc.FontInfos;
fontInfos.EmbedTrueTypeFonts = embedAllFonts;
fontInfos.EmbedSystemFonts = embedAllFonts;
fontInfos.SaveSubsetFonts = embedAllFonts;

doc.Save(ArtifactsDir + "Font.FontInfoCollection.docx");

if (embedAllFonts)
    Assert.That(25000, Is.LessThan(new FileInfo(ArtifactsDir + "Font.FontInfoCollection.docx").Length));
else
    Assert.That(15000, Is.AtLeast(new FileInfo(ArtifactsDir + "Font.FontInfoCollection.docx").Length));

也可以看看