Laden von Type-1-Schriftarten (PostScript) | .NET

Laden von Type‑1-Schriften mit Aspose.Font für .NET

Warum Type‑1-Schriften?

Was Sie benötigen

ElementMindestversion
.NET Framework4.6 (oder .NET Core 2.x / .NET 5+)
Aspose.Font for .NET23.12 oder höher
LizenzEine gültige .lic‑Datei (optional für Testversion – andernfalls funktioniert eine 30‑tägige Evaluierung).

Add the NuGet package to your project:

1dotnet add package Aspose.Font

Kern-API-Konzepte

Klasse / AufzählungZweck
FontDefinitionBeschreibt welche Art von Schrift Sie öffnen möchten (FontType.Type1).
FontFileDefinitionBeschreibt wo die Schrift gespeichert ist – Dateisystem (FileSystemStreamSource), Speicher (ByteContentStreamSource) oder jede benutzerdefinierte Stream‑Quelle.
FontTypeAufzählung, die Aspose mitteilt, welches Format erwartet wird (CFF, TTF, Type1, …).
Aspose.Font.Font.Open(fd)Statische Methode, die die Definition liest und eine IFont‑Implementierung (Type1Font) zurückgibt.
Type1FontKonkrete Klasse, die Glyphen, Metriken, Kodierung und Rendering‑Fähigkeiten für Type‑1-Schriften bereitstellt.

Laden einer Type‑1‑Schrift von der Festplatte

 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.");

Laden von Type‑1 aus dem Speicher

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;

Tipp: Der String "pfb" ist nur ein Hinweis. Verwenden Sie "pfa" für ASCII‑kodierte Type‑1‑Dateien.

Fazit

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.