Carregamento de tipos de letra Type-1 (PostScript) | .NET

Carregando fontes Type‑1 com Aspose.Font para .NET

Por que fontes Type‑1?

O que você precisa

ItemVersão mínima
.NET Framework4.6 (ou .NET Core 2.x / .NET 5+)
Aspose.Font para .NET23.12 ou posterior
LicençaUm ficheiro .lic válido (opcional para avaliação – caso contrário, funciona a avaliação de 30 dias).

Adicione o pacote NuGet ao seu projeto:

1dotnet add package Aspose.Font

Conceitos principais da API

Classe / EnumFinalidade
FontDefinitionDescreve qual tipo de fonte você quer abrir (FontType.Type1).
FontFileDefinitionDescreve onde a fonte está – sistema de ficheiros (FileSystemStreamSource), memória (ByteContentStreamSource) ou qualquer origem de fluxo personalizada.
FontTypeEnum que indica ao Aspose que formato esperar (CFF, TTF, Type1, …).
Aspose.Font.Font.Open(fd)Método estático que lê a definição e devolve uma implementação IFont (Type1Font).
Type1FontClasse concreta que expõe glifos, métricas, codificação e capacidades de renderização para fontes Type‑1.

Carregando uma fonte Type‑1 a partir do disco

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

Carregando Type‑1 a partir da memória

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;

Dica: A string "pfb" é apenas uma sugestão. Use "pfa" para arquivos Type‑1 codificados em ASCII.

Conclusão

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.