Warning: session_start(): open(/var/lib/php/sessions/sess_l8i0qvdnb3fnketu6erqa6se8l, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
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";
settable S alignment = "left";
Font scaledFont;
FontMetrics fm;
LS lines;
*() {}
*(Font *font) {}
selfType setFont(S fontSnippetID) {
ret setFont(fontForName(fontSnippetID));
}
Font scaledFont() { ret scaledFont = font.deriveFont(fontSize); }
BufferedImage get(S text) {
text(text);
ret this!;
}
BufferedImage get() {
fm = fontMetrics(scaledFont());
lines = lines(text);
var lineWidths = map(lines, line -> fm.stringWidth(line));
int width = intMax(lineWidths);
if (width <= 0) null;
int lineHeight = fm.getHeight();
int height = lineHeight*l(lines);
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);
for i over lines: {
int x = 0;
if (eq(alignment, "center"))
x = (width-lineWidths.get(i))/2;
g.drawString(lines.get(i), x, lineHeight*i+y);
}
g.dispose();
ret img;
}
}