ロード、抽出、TTF |から保存しますC ++
Contents
[
Hide
Show
]ディスクからTrueTypeフォントをロードします
TrueTypeフォントは、ファイルにディスクに保存できます。 C ++ APIのAspose.Fontは、このようなファイルをロードして、これらからフォント情報を読み取ることができます。次の手順を使用して、C ++アプリケーションでTrueTypeフォントファイルを読み取ることができます。
- FontDefinitionクラスの新しいオブジェクトを作成します
- fonttypeをTTFとして使用し、FontFileDefinitionをTTFとして使用します
- ttffontオブジェクトを宣言し、以前のステップで定義されたfontDefinitionオブジェクトからフォントファイルを開きます
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::String fileName = dataDir + u"Montserrat-Regular.ttf";
3//Font file name with full path
4
5System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
6System::SharedPtr<TtfFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
TTFフォントを保存します
C ++のAspose.Fontは、フォントファイルを編集し、ディスクへの変更を保存する機能を提供します。次のC ++コードサンプルは、更新されたTTFフォントファイルをディスクに保存する方法を示しています。
- FontDefinitionクラスの新しいオブジェクトを定義します
- fontTypeをTTFとして指定し、FontFileDefinitionをTTFとして指定します
- TTFFONTオブジェクトを作成し、以前のステップで定義されたfontDefinitionオブジェクトからフォントファイルを開きます
- 必要な更新を作成し、ttffontの保存方法を使用して更新されたフォントファイルをディスクに保存します
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2//byte array to load Font from
3System::String dataDir = RunExamples::GetDataDir_Data();
4
5System::ArrayPtr<uint8_t> fontMemoryData = System::IO::File::ReadAllBytes(dataDir + u"Montserrat-Regular.ttf");
6System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<ByteContentStreamSource>(fontMemoryData)));
7System::SharedPtr<TtfFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
8
9//Work with data from just loaded TtfFont object
10
11//Save CffFont to disk
12//Output Font file name with full path
13System::String outputFile = RunExamples::GetDataDir_Data() + u"Montserrat-Regular_out.ttf";
14
15ttfFont->Save(outputFile);
その他の例については、 aspose.examples.sln solution、 net-examples aspose.font documentationgithubリポジトリの net-examplesフォルダーにご覧ください。
また、無料のオンライン フォント操作アプリケーションを確認して、Webソリューションで機能を実装する方法を確認することもできます。