Carregue uma fonte do arquivo CFF | Java
Contents
[
Hide
Show
]Observe mais de perto como carregar a fonte em `` centurygothic ‘particular, colocado no arquivo centurygothic.cff.
Se você não leu os fundamentos do Aspose.Font Carregando, vá para Como carregar fontes? Página.
Primeiro, vamos notificar as declarações que você precisará usar:
1 pacote com.aspose.font;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.nio.file.Files;
6 import java.nio.file.Paths;
7
8 import com.aspose.font.ByteContentStreamSource;
9 import com.aspose.font.FileSystemStreamSource;
10 import com.aspose.font.Font;
11 import com.aspose.font.FontDefinition;
12 import com.aspose.font.FontFileDefinition;
13 import com.aspose.font.FontType;
Carregando do arquivo usando o objeto java.io.file
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 FILEEXTENNENTE.
- Carregue a fonte.
1 // Construa o caminho para o arquivo.
2 String fontpath = paths.get (getDatadir (), "centurygothic.cff"). Tostring ();
3
4 // Initialize FontDefinition object passing CFF as FontType value and using FontFileDefinition
5 FontFileDefinition fileDef = new FontFileDefinition(new File(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 = paths.get (getDatadir (), "centurygothic.cff"). Tostring ();
3
4 // Load font binary data into byte array
5 byte[] fontBytes = Files.readAllBytes(Paths.get(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 java-examples da documentação aspose.font.