加载嵌入式 OpenType (EOT) 字体文件 | .NET

使用 Aspose.Font for .NET 加载 EOT 字体

嵌入式 OpenType (EOT) 是一种紧凑的面向 Web 的字体格式,最初由 Microsoft 为 Internet Explorer 推出。尽管其受欢迎程度已因 WOFF/WOFF2 而下降,但许多遗留的 Web 应用仍依赖 EOT 文件。Aspose.Font 库提供了纯 .NET API,让您无需图形子系统即可读取、修改、转换和写入 EOT 字体。

所需条件

需求细节
.NET 运行时.NET 6.0 或更高(该库同样支持 .NET Framework 4.6.2 以上)
Aspose.Font for .NET通过 NuGet 安装:dotnet add package Aspose.Font
IDEVisual Studio 2022、VS Code 或任何支持 C# 的编辑器
许可证生产环境需有效的 Aspose.Font 许可证。库可在试用模式下使用,带有水印。

加载 EOT 字体

步骤

  1. 初始化文件源。将应用指向字体文件的实际位置。使用逐字字符串 (@) 可以正确处理 Windows 路径中的反斜杠。
  2. 使用 Font.Open 方法加载并打开字体,将二进制数据加载到对象中。此时库会验证文件是否损坏或受保护。
  3. 如果字体加载成功,您可以提取技术数据。
 1using Aspose.Font;
 2using Aspose.Font.Sources;
 3
 4// Path to the EOT file
 5string eotPath = @"C:\Fonts\MyWebFont.eot";
 6
 7// Create a FontDefinition from the file source
 8FontDefinition fontDef = new FontDefinition(
 9    FontType.EOT,                // Explicitly specify the format
10    new FileSystemFontSource(eotPath)
11);
12
13// Load the font into memory
14Font font = Font.Open(fontDef);
15
16// Verify that the font was loaded correctly
17Console.WriteLine($"Family: {font.FamilyName}");
18Console.WriteLine($"Style: {font.Style}");
19Console.WriteLine($"Units per EM: {font.UnitsPerEm}");

关键点

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.