ロード、抽出、TTF |Java
Contents
[
Hide
Show
]ディスクからTrueTypeフォントをロードします
Java APIのAspose.Fontでは、デジタルストレージに保存されているファイルからTrueTypeフォントタイプを読み取ることができます。ディスクに保存されているTrueTypeフォントファイルは、次の手順を使用してロードできます。
- FontDefinitionクラスの新しいオブジェクトを定義します
 - fontTypeをTTFとして指定し、FontFileDefinitionをTTFとして指定します
 - TTFFONTオブジェクトを作成し、以前のステップで定義されたfontDefinitionオブジェクトからフォントファイルを開きます
 
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ファイルをディスクに保存できます。
- FontDefinitionクラスの新しいオブジェクトを定義します
 - fontTypeをTTFとして指定し、FontFileDefinitionをTTFとして指定します
 - TTFFONTオブジェクトを作成し、以前のステップで定義されたfontDefinitionオブジェクトからフォントファイルを開きます
 - 必要な更新を作成し、ttffontの保存方法を使用して更新されたフォントファイルをディスクに保存します
 
 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.examples.sln solution、 net-examples Aspose.Font documentationgithubリポジトリの net-examplesフォルダーにアクセスしてください。
また、無料のオンライン フォント操作アプリケーションを確認して、Webソリューションで機能を実装する方法を確認してください。