加载,提取数据并从TTF中保存| C++
Contents
[
Hide
Show
]从光盘加载TrueType字体
TrueType字体可以存储在文件中。 Aspose.Font 适用于C++ API可以加载此类文件并从中读取字体信息。以下步骤可用于读取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字体
Aspose.Font 适用于C++提供了编辑字体文件并将更改保存到光盘的功能。以下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.Font.Examples.sln 解决方案,该解决方案位于 Aspose.Font 文档 Github 仓库的 net-examples 文件夹中。
您还可以查看我们免费的在线 字体操作应用程序,了解如何在 Web 解决方案中实现该功能。