Chargement des polices Type-1 (PostScript) | .NET

Caricamento di font Type‑1 con Aspose.Font per .NET

Perché i font Type‑1?

Cosa ti serve

ItemVersione minima
.NET Framework4.6 (o .NET Core 2.x / .NET 5+)
Aspose.Font per .NET23.12 o successiva
LicenzaUn file .lic valido (opzionale per la versione di prova – altrimenti una valutazione di 30 giorni è sufficiente).

Aggiungi il pacchetto NuGet al tuo progetto:

1dotnet add package Aspose.Font

Concetti fondamentali dell’API

Classe / EnumScopo
FontDefinitionDescrive cosa tipo di font si vuole aprire (FontType.Type1).
FontFileDefinitionDescrive dove si trova il font – file system (FileSystemStreamSource), memoria (ByteContentStreamSource) o qualsiasi sorgente di stream personalizzata.
FontTypeEnum che indica ad Aspose il formato atteso (CFF, TTF, Type1, …).
Aspose.Font.Font.Open(fd)Metodo statico che legge la definizione e restituisce un’implementazione di IFont (Type1Font).
Type1FontClasse concreta che espone glifi, metriche, codifica e capacità di rendering per i font Type‑1.

Caricamento di un font Type‑1 dal disco

 1using System;
 2using System.IO;
 3using Aspose.Font;
 4using Aspose.Font.Sources;
 5
 6// Percorso al file .pfb o .pfa
 7string fileName = @"C:\Fonts\courier.pfb";   // modifica con il tuo file
 8
 9// Verifica che il file esista
10if (!File.Exists(fileName))
11    throw new FileNotFoundException($"Font file not found: {fileName}");
12
13// Costruisci un FontDefinition che indica ad Aspose che stiamo usando un font Type‑1.
14FontDefinition fd = new FontDefinition(
15    FontType.Type1,                                 // suggerimento del formato
16    new FontFileDefinition(
17        "pfb",                                      // suggerimento dell'estensione (pfb o pfa)
18        new FileSystemStreamSource(fileName)));    // legge direttamente dal file system
19
20// Caricalo
21Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
22
23// Verifica che il font sia stato caricato correttamente
24if (font == null)
25    throw new InvalidOperationException("Unable to load the Type‑1 font.");

Caricamento di Type‑1 dalla memoria

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;

Suggerimento: La stringa "pfb" è solo un suggerimento. Usa "pfa" per i file Type‑1 codificati in ASCII.

Conclusione

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.