feat: improve github card

This commit is contained in:
2024-09-15 13:47:04 +08:00
parent cd7cc341ab
commit 78582d5d9d
2 files changed
+25 -4

No files matched your search

@@ -71,4 +71,25 @@ fun Graphics2D.drawCenteredText(text: String, x: Int, y: Int) {
val drawX = x - textWidth / 2
val drawY = y + textHeight / 2
this.drawString(text, drawX, drawY)
}
fun Graphics2D.drawString(text: String, x: Int, y: Int, maxWidth: Int) {
val fm = this.fontMetrics
val lineHeight = fm.height
var curY = y
val words = text.split(" ")
val line = StringBuilder()
for (word in words) {
if (fm.stringWidth("$line$word ") <= maxWidth) {
line.append(word).append(" ")
} else {
this.drawString(line.toString(), x, curY)
curY += lineHeight
line.setLength(0)
line.append(word).append(" ")
}
}
if (line.isNotEmpty()) {
this.drawString(line.toString(), x, curY)
}
}