加载和提取数据|爪哇
Contents
[
Hide
Show
]从光盘加载CFF字体
Java 版 Aspose.Font API使您可以在Java应用程序中打开CFF字体文件。可以使用以下步骤加载存储在光盘上的CFF字体文件。
- 定义FontDefinition类的新对象
- 将fonttype指定为cff,而fontfiledefinition为cff
- 创建一个cfffont对象,然后从fontdefinition对象打开字体文件,在早期步骤中定义
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
2String fileName = Utils.getDataDir() + "OpenSans-Regular.cff"; //Font file name with full path
3
4 FontDefinition fd = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new FileSystemStreamSource(fileName)));
5 CffFont ttfFont = (CffFont) Font.open(fd);
6
7 System.out.println("Font has been loaded");
从字节数组加载CFF字体
您还可以使用以下代码示例从流中加载CFF字体。
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
2byte [] fontMemoryData = Utils.getInputFileBytes("OpenSans-Regular.cff");
3
4 FontDefinition fd = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData)));
5 CffFont ttfFont = (CffFont) Font.open(fd);
6
7 System.out.println("Font has been loaded");