Carregue uma fonte do arquivo CFF | .NET
Contents
[
Hide
Show
]Nesta página, daremos uma olhada em exemplos de carregamento de fontes Centurygothic
, colocado no arquivo centurygothic.cff.
Se você não leu os fundamentos do Aspose.Font Carregando, vá para Como carregar fontes? Página.
Primeiro, você precisa notificar os próximos namespaces à frente do arquivo:
1 using System;
2 using Aspose.Font
3 using Aspose.Font.Sources;
4 using System.IO;
Carregando do arquivo usando o objeto FileInfo
Siga o algoritmo para cumprir o carregamento da fonte:
- Construa o caminho para o arquivo.
- Inicie
fontDefiniton Passagem do objeto
cff
como fontType valor. - Obtenha o valor calculado automaticamente fileExtension.
- Carregue a fonte.
1 // Construa o caminho para o arquivo.
2 string fontpath = path.combine (datadir, "centurygothic.cff");
3
4 // Initialize FontDefinition object passing CFF as FontType value and using FontFileDefinition
5 FontFileDefinition fileDef = new FontFileDefinition(new FileInfo(fontPath));
6
7 // Based on FileInfo object, fileExtension value is calculated automatically from FileInfo fields.
8 FontDefinition fontDef = new FontDefinition(FontType.CFF, fileDef);
9
10 // Load the font
11 Font font = Font.Open(fontDef);
Carregando de fonte com a variável de tipo [] de byte e com o uso do objeto ByteContentStreamSource
Para carregar a fonte dessa maneira, você precisa tomar as seguintes etapas:
- Construa o caminho para o arquivo.
- Inicialize
fontDefiniton Passagem do objeto
cff
como fontType valor,cff
como fileExtension valor e byteContentStreamSource objeto baseado na prisão fontbytes. - Carregue a fonte.
1 // Construa o caminho para o arquivo
2 string fontpath = path.combine (datadir, "centurygothic.cff");
3
4 // Load font binary data into byte array
5 byte[] fontBytes = File.ReadAllBytes(fontPath);
6
7 // Initialize FontDefinition object passing CFF as FontType value, "cff" as fileExtension value,
8 // and ByteContentStreamSource object based on fontBytes array
9 FontDefinition fontDef = new FontDefinition(FontType.CFF, "ttf", new ByteContentStreamSource(fontBytes));
10
11 // Load the font
12 Font font = Font.Open(fontDef);
Mais exemplos sobre como usar aspose.font estão em aspose.font.examples.sln Solution, nos net-examples da documentação aspose.font.