Render TrueType Fonts Programmatically using C++

Render truetype font c++

Characters are symbols that explain the meanings of different words. You can render different text characters with TrueType fonts using C++ with Aspose.Font for C++ API. It supports different text rendering features including TrueType, Type1, OTF, EOT, and other fonts. Let us explore how to use the text rendering features with a few simple API calls. We will be covering the topic under the following headings:

C++ TrueType Font Rendering API – Installation

Considering the popularity and demand of C++ platform, we have introduced very useful features in Aspose.Font for C++ API. In order to render TrueType fonts in your applications, you need to configure the API by downloading it from New Releases, or you can install it via NuGet using the following command:

Install-Package Aspose.Font.Cpp

Implement Interface for Drawing Glyph to Render TrueType Fonts using C++

First of all, you need to implement IGlyphOutlinePainter under Aspose.Font.Rendering namespace. Follow the steps below for the implementation of methods and classes:

  1. Create a class named GlyphOutlinePainter
  2. Use System.Drawing.Drawing2D.GraphicsPath to draw graphics

Below is the C++ code snippet for the implementation of interface in order to draw glyphs:

Secondly, please create a method with name DrawText with the following steps:

  1. Loop through symbols in the text string
  2. Get GID as glyph identified for each symbol
  3. Create GlyphOutlinePainter and pass over to GlyphOutlineRenderer object
  4. Specify Glyph coordinates with Matrix object

Moreover, after following all these steps, create utility method for calculation of font dimensions to image as elaborated in the following C++ code snippet:

Render Text with TrueType Font using C++

We have implemented the required functionality for the rendering of text with TrueType fonts. Now let us call the methods using Aspose.Font for C++ API as the code snippet below:

Conclusion

In this article, you have learned how to render text using TrueType fonts with C++. Interested to learn more about features offered by Aspose.Font for C++ API? You can learn further details by exploring API references or Product Documentation. However, if you face any ambiguity or need assistance, please feel free to reach us via Free Support Forums. We look forward to engaging with you!

See Also

Detect Latin Symbols in TrueType and Type1 Fonts using C++