Render TrueType text with a custom glyph outline painter using Aspose.Font for Java and Java 2D. The examples load Montserrat Bold and Lato Regular, position glyphs using their advances and pair kerning, and save black text on white and red text on yellow as PNG images.
Combine the rendering call, drawText, fontWidthToImageWidth and GlyphOutlinePainter fragments in one Java class. The painter implements IGlyphOutlinePainter and sends outline commands to GeneralPath; Graphics2D fills the paths on a 960 × 720 image.
Supply getDataDir() and getOutputDir() for your application. The sample paths use the sibling TTF directory containing montserrat-bold.ttf and LatoWeb-Regular.ttf; create the output directory before rendering. Lato Regular replaces the Lora Bold font used in the documentation.
The 300 DPI value controls coordinate scaling; it does not embed resolution metadata in the PNG. Required imports are shown in the Java source and include com.aspose.font, Java 2D, java.nio.file and javax.imageio.ImageIO.
- Documentation – Aspose.Font for Java
- Product page – Aspose.Font for Java
- Free Support Forum – Aspose.Font
- Blog – Aspose.Font Product Family
- API Reference – Aspose.Font for Java
- Releases – Aspose.Font for Java
- JDK 8 or later and Maven for this example project
- Aspose.Font for Java library
- Java 2D and a PNG writer available through ImageIO; rendering supports headless operation