加载,提取数据并从TTF中保存|爪哇

从光盘加载TrueType字体

Java 版 Aspose.Font API可让您从数字存储中存储的文件中读取TrueType字体类型。可以使用以下步骤加载存储在光盘上的TRUETYPE字体文件。

1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
2String fileName = Utils.getDataDir() + "Montserrat-Regular.ttf"; //Font file name with full path
3
4      FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
5      TtfFont font = (TtfFont) Font.open(fd);        

保存TTF字体

加载TTF文件后,您可以使用字体文件,更新一些参数,并希望将文件保存到光盘。 Java 版 Aspose.Font可让您使用以下步骤将TTF文件保存为光盘。

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
 2byte[] fontMemoryData = Utils.getInputFileBytes("Montserrat-Regular.ttf"); //Font file name with full path
 3
 4      FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new ByteContentStreamSource(fontMemoryData)));
 5      TtfFont font = (TtfFont) Font.open(fd);
 6      
 7      //Work with data from just loaded TtfFont object
 8
 9      //Save TtfFont to disk
10      //Output Font file name with full path
11      String outputFile = Utils.getDataDir() + "Montserrat-Regular_out.ttf";
12
13      font.save(outputFile);

要了解更多示例,请转到 Aspose.Font.Examples.sln 解决方案,位于 Aspose.Font 文档 Github 存储库的 net-examples 文件夹中。

另外,请检查我们的免费在线 FONT操纵应用程序,以了解如何在Web解决方案中实现功能。

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.