Loading and Extracting Data | Java

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.

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

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.