Завантажити, витягти дані та зберегти з TTF | C++

Завантажте шрифт TrueType з диска

Шрифти TrueType можна зберігати на диску у файлах. API Aspose.Font для C++ може завантажувати такі файли та читати з них інформацію про шрифт. Наступні кроки можна використати для читання файлу шрифту TrueType у програмах C++.

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 на диск.

 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 solution у папці net-examples репозиторію Github Aspose.Font Documentation.

Ви також можете перевірити наші безкоштовні онлайн- Програми для обробки шрифтів, щоб побачити, як цю функцію можна реалізувати у веб-рішенні.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.