检索 Visio 连接器和字体信息

检索连接器信息

Aspose.Diagram for .NET 提供检索信息的机制 - ID 和名称 - 关于页数掌握.它还可以让您获得有关连接器(连接形状的元素)的信息。

连接对象表示连接 Visio 绘图页上两个形状的连接器。 Connects 属性,由类支持 Aspose.Diagram.Connect 对象的集合。此属性可用于检索有关连接器的 ID 和名称信息。

编程范例

以下代码段检索 diagram 中连接器的信息。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Diagrams();
// Call the diagram constructor to load diagram from a VSD file
Diagram vdxDiagram = new Diagram(dataDir + "RetrieveConnectorInfo.vsd");
foreach (Aspose.Diagram.Connect connector in vdxDiagram.Pages[0].Connects)
{
// Display information about the Connectors
Console.WriteLine("\nFrom Shape ID : " + connector.FromSheet);
Console.WriteLine("To Shape ID : " + connector.ToSheet);
}

检索字体信息

Aspose.Diagram 具有从中检索有关构成 diagram 的元素的信息的机制页数, 模版, 连接器还有字体。本文介绍如何找出 diagram 中使用了哪些字体。

字体对象表示应用于文档中的文本或可在系统上使用的字体。字体对象将名称(例如“Arial”)映射到字体 ID(例如 3),字体 ID Microsoft Visio 存储在形状的字符部分的字体单元格中,该形状包含使用该字体设置格式的文本。当在不同系统上打开文档或安装或删除字体时,字体 ID 可能会发生变化。

检索字体编程示例

下面这段代码从 Visio diagram 中检索字体信息。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Diagrams();
// Call the diagram constructor to load diagram from a VSD file
Diagram vdxDiagram = new Diagram(dataDir + "RetrieveFontInfo.vsd");
foreach (Aspose.Diagram.Font font in vdxDiagram.Fonts)
{
// Display information about the fonts
Console.WriteLine(font.Name);
}

获取默认字体目录

Aspose.Diagram for .NET API 还允许使用 Diagram 类的 GetDefaultFontDir() 方法获取默认字体目录路径。以下代码从 Visio diagram 中检索默认字体目录。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Diagrams();
// Call the diagram constructor to load diagram from a VSD file
Diagram vdxDiagram = new Diagram(dataDir + "RetrieveFontInfo.vsd");
// Display font default directory
Console.WriteLine(vdxDiagram.GetDefaultFontDir());

获取未使用的字体

Aspose.Diagram for .NET API 还允许使用 Diagram 类的 GetUnusedStyles() 方法获取未使用的字体。下面的一段代码从 Visio diagram 中检索未使用的字体。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Diagrams();
// Call the diagram constructor to load diagram from a VSD file
Diagram vdxDiagram = new Diagram(dataDir + "Sample_UnusedFonts.vsdx");
// Get Unused Fonts
StyleSheetCollection unused = vdxDiagram.GetUnusedStyles();
// Display unused fonts count
Console.WriteLine(unused.Count);