Save updated font files to disc

C++ API Solution to save previously loaded from stream fonts.

 

Aspose.Font API Solution offers you rich capabilities for working with fonts, including conversion, glyph manipulation, Latin symbol detection, and many more. The topic of this article will be the functionality to save fonts.

Saving fonts to disk allows for long-term storage and sharing of the font data. Then the font can be used for future projects or you can share it with others to ensure that a specific font is available for use on their computer.

Additionally, saving the font to a disk allows you to easily retrieve the font data, without loading the font from a remote source each time when needed. This can be useful for large or frequently used fonts that may take a long time to load.

By saving fonts to disk, you can also ensure that the font is available even if the original source of the font is no longer accessible. This helps to preserve the font data and makes it possible to use the font in future projects.

This page describes the option on how to save TrueType font to disk but all the rest code snippets on how to use the solution are placed in the Aspose Github Project .

To save font files we need:

  • Aspose.Font for C++ API which is a feature-rich, powerful and easy-to-use document manipulation and conversion API for C++ platform.

  • Open the NuGet package manager, and search for Aspose.Font and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Font

Steps to save the before-changed font using C++:

Aspose.Font for C++ offers the ability to modify font files and store the changed ones on disk. The code example below demonstrates how to save a modified TTF font file.

  1. Create a new FontFileDefinition object.
  2. Set FontType as TTF and FontFileDefinition as .ttf.
  3. Establish a TtfFont object and open the font file using the FontDefinition object defined previously.
  4. Save the TtfFont to a disk by calling the Save() Method and passing the output file name with the full path. The saved font file will have the updated changes.

C++ Code for saving TrueType font to the disk

    using Aspose::Font;
    using Aspose::Font::Sources;
    using Aspose::Font::Ttf;
    //byte array to load Font from
    System::String dataDir = RunExamples::GetDataDir_Data();
    
    System::ArrayPtr<uint8_t> fontMemoryData = System::IO::File::ReadAllBytes(dataDir + u"Montserrat-Regular.ttf");
    System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<ByteContentStreamSource>(fontMemoryData)));
    System::SharedPtr<TtfFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
    
    //Work with data from the just loaded TtfFont object
    
    //Save The TtfFont to disk
    //Output the Font file name with the full path
    System::String outputFile = RunExamples::GetDataDir_Data() + u"Montserrat-Regular_out.ttf";
    
    ttfFont->Save(outputFile);



FAQ

1. How do I save fonts to my hard drive?

When you downloaded a font and want to save it to your drive you need to paste its file to the Fonts folder, for example, C:>Windows>Fonts if the operating system is Windows.

2. Can I copy fonts from one computer to another?

If the device you want to transfer your font to has the same operating system you can just copy and paste the font file from/to the Font folder. If the operating system or app is different, you need to convert the font to the format that is supported by such a device or environment.

3. How to save changed fonts?

To save the font to the disc, first, declare the output font file name with the full path. Then use the Save() Method.