sclass RenderText { settable Color foregroundColor = Color.black; settable Color backgroundColor = Color.white; settable bool withLeading = true; settable Font font = sansSerifFont(20); settable float fontSize = 20; settable S text = "DEMO"; Font scaledFont; FontMetrics fm; *() {} *(Font *font) {} selfType setFont(S fontSnippetID) { ret setFont(loadFont_cached(fontSnippetID)); } Font scaledFont() { ret scaledFont = font.deriveFont(fontSize); } BufferedImage get(S text) { text(text); ret this!; } BufferedImage get() { fm = fontMetrics(scaledFont()); int width = fm.stringWidth(text); if (width <= 0) null; int height = fm.getHeight(); int y = withLeading ? fm.getLeading() + fm.getMaxAscent() : fm.getAscent(); BufferedImage img = bufferedImageWithoutAlpha(width, height, backgroundColor); Graphics g = imageGraphics(img); g.setColor(foregroundColor); g.setFont(scaledFont); g.drawString(text, 0, y); g.dispose(); ret img; } }