In the previous post, you have seen how to use Aspose.Font for .NET API for loading and saving CFF, TrueType, and Type1 fonts programmatically. In this article, you will learn how to render text with TrueType and Type1 font using C#. The code samples will show you how to generate a JPG image based on the provided text.
- .NET Font Rendering API - Installation
- Implement Text Rendering Interface
- Render Text with TrueType Font using C#
- Render Text with Type1 Font using C#
.NET Font Rendering API - Installation
Aspose.Font for .NET provides a powerful font rendering mechanism in order to render the text using TrueType and Type1 fonts. You can download the API or get it installed using NuGet.
PM> Install-Package Aspose.Font
Implement Text Rendering Interface
In order to achieve the text rendering, Aspose.Font for .NET provides an IGlyphOutlinePainter interface to draw the glyphs. The following steps demonstrate how to implement the methods in IGlyphOutlinePainter.
- Implement the IGlyphOutlinePainter interface methods using GlyphOutlinePainter class which requires an object of type System.Drawing.Drawing2D.GraphicsPath for drawing graphics.
- Create a new method DrawText() to draw the text into System.Drawing.Bitmap object.
- Define a utility method to calculate the font’s width according to the image’s width.
Render Text with TrueType Font using C#
The following code sample shows how to use the above-mentioned implementation to render text with a TrueType font using C#.
Render Text with Type1 Font using C#
The following code sample shows how to render text with a Type1 font using C#.
In this article, you have learned how to implement the rendering of text with a TrueType or Type1 font using C#. The code samples have shown how to generate JPG images based on the provided text. You can explore more about Aspose.Font for .NET using the documentation.