In the previous article, you have seen how to load CFF, TrueType and Type1 fonts programmatically using Java. Today, we will discuss another interesting feature of our Java font manipulation API – rendering text using fonts. By the end of this article, you will be able to render text using TrueType and Type1 fonts from within your Java applications. So let’s start.
Aspose.Font for Java provides you with the features of loading and saving the fonts as well as getting the metrics of the popular font types including CFF, TrueType, OpenType, and Type1. In addition, the API lets you render the text using the provided TrueType or Type1 fonts. You can either install the API using Maven configurations or download the API’s JAR.
In order to render the text, Aspose.Font for Java requires you to implement the drawText() method which will draw the provided text. The following is the complete definition of the drawText() method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following is a utility method that is used to calculate the glyph width for bitmap coordinate system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Call the drawText() method by providing the details in the form of its parameters.
Render Text with TrueType Font using Java
The following code sample shows how to use the drawText() method to render text using a TrueType font. The rendering results will be generated as a JPEG image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following code sample shows how to render text to a JPEG image with a Type1 font using Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In this article, you have seen how to render the text as JPEG images using the TrueType or Type1 font from within the Java applications. In order to learn more about the Java font manipulation API, you can visit the documentation and evaluate the API’s features using source code samples.