Loading and Extracting Data | C++
Contents
[
Hide
Show
]Load CFF Font from Disc
Aspose.Font for C++ API allows to load CFF fonts from disc files on your computer. The following steps can be used to load a CFF font file:
- Create a new object of FontDefinition class
- Choose FontType as CFF and FontFileDefinition as cff
- Declare a CffFont object and open the font file from FontDefinition object defined in the earlier step
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::String fileName = dataDir + u"OpenSans-Regular.cff";
3//Font file name with full path
4
5System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::CFF, System::MakeObject<FontFileDefinition>(u"cff", System::MakeObject<FileSystemStreamSource>(fileName)));
6System::SharedPtr<CffFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Cff::CffFont>(Aspose::Font::Font::Open(fd));
Load CFF Font from Byte Array
A CFF font file can be loaded from stream using the following code sample.
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::ArrayPtr<uint8_t> fontMemoryData = System::IO::File::ReadAllBytes(dataDir + u"OpenSans-Regular.cff");
3System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::CFF, System::MakeObject<FontFileDefinition>(u"cff", System::MakeObject<ByteContentStreamSource>(fontMemoryData)));
4System::SharedPtr<CffFont> cffFont = System::DynamicCast_noexcept<Aspose::Font::Cff::CffFont>(Aspose::Font::Font::Open(fd));