Loading and Extracting Data | Java
Contents
[
Hide
Show
]Load CFF Font from Disc
Aspose.Font for Java API lets you open CFF Font files in your java applications. CFF font files stored on disc can be loaded by using the following steps.
- Define a new object of FontDefinition class
- Specify FontType as CFF and FontFileDefinition as cff
- Create a CffFont object and open the font file from FontDefinition object defined in the earlier step
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");
Load CFF Font from Byte Array
You can also load CFF fonts from stream using the following code sample.
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");