Load, Extract Data and Save from TTF | C++

Load TrueType Font from Disc

TrueType fonts can be stored to disc in files. Aspose.Font for C++ API can load such files and read font information from these. The following steps can be used to read TrueType font file in C++ applications.

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
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));

Save TTF Font

Aspose.Font for C++ provides the capability to edit font files and save back the changes to disc. The following C++ code sample shows how to save an updated TTF font file to disc.

 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();
  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));
  9//Work with data from just loaded TtfFont object
 11//Save CffFont to disk
 12//Output Font file name with full path
 13System::String outputFile = RunExamples::GetDataDir_Data() + u"Montserrat-Regular_out.ttf";

For more examples go to Aspose.Font.Examples.sln solution, in the net-examples folder of the Aspose.Font Documentation Github repository.

You can also check our free online Font Manipulation Applications to see how the functionality can be implemented in a web solution.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.