データの読み込みと抽出| Java
Contents
[
Hide
Show
]ディスクからCFFフォントをロードします
Java API用のAspose.Fontを使用すると、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");