Type-1 (PostScript) フォントの読み込み | .NET

Aspose.Font for .NETでのType‑1フォントの読み込み

なぜType‑1フォントなのか?

必要なもの

項目最低バージョン
.NET Framework4.6 (or .NET Core 2.x / .NET 5+)
Aspose.Font for .NET23.12 or later
LicenseA valid .lic file (optional for trial – otherwise a 30‑day evaluation works).

プロジェクトにNuGetパッケージを追加します:

1dotnet add package Aspose.Font

コアAPIの概念

クラス / 列挙型目的
FontDefinition開きたいフォントの種類(FontType.Type1)を記述します。
FontFileDefinitionフォントが存在する場所(ファイルシステム (FileSystemStreamSource)、メモリ (ByteContentStreamSource)、またはカスタムストリームソース)を記述します。
FontTypeAsposeに期待するフォーマット(CFFTTFType1、…)を示す列挙型です。
Aspose.Font.Font.Open(fd)定義を読み取り、IFont実装(Type1Font)を返す静的メソッドです。
Type1FontType‑1フォント向けにグリフ、メトリクス、エンコーディング、レンダリング機能を提供する具体クラスです。

ディスクからType‑1フォントをロードする

 1using System;
 2using System.IO;
 3using Aspose.Font;
 4using Aspose.Font.Sources;
 5
 6// Path to the .pfb or .pfa file
 7string fileName = @"C:\Fonts\courier.pfb";   // change to your file
 8
 9// Ensure the file exists
10if (!File.Exists(fileName))
11    throw new FileNotFoundException($"Font file not found: {fileName}");
12
13// Build a FontDefinition that tells Aspose we are dealing with a Type‑1 font.
14FontDefinition fd = new FontDefinition(
15    FontType.Type1,                                 // format hint
16    new FontFileDefinition(
17        "pfb",                                      // extension hint (pfb or pfa)
18        new FileSystemStreamSource(fileName)));    // reads directly from the file system
19
20// Load it
21Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
22
23// Verify that the font really loaded
24if (font == null)
25    throw new InvalidOperationException("Unable to load the Type‑1 font.");

メモリからType‑1をロードする

1byte[] fontBytes = File.ReadAllBytes(fileName);
2FontDefinition fd = new FontDefinition(
3    FontType.Type1,
4    new FontFileDefinition("pfb", new ByteContentStreamSource(fontBytes)));
5Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;

ヒント: "pfb" 文字列は単なるヒントです。ASCIIエンコードのType‑1ファイルには "pfa" を使用してください。

結論

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.