feat: support parse github repo(project)
This commit is contained in:
15 files changed
+269
-55
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/12
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.util
|
||||
|
||||
import java.awt.Graphics2D
|
||||
import java.awt.geom.RoundRectangle2D
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import javax.imageio.ImageIO
|
||||
|
||||
fun Graphics2D.drawCustomImage(
|
||||
image: BufferedImage,
|
||||
x: Int,
|
||||
y: Int,
|
||||
maxWidth: Double,
|
||||
maxHeight: Double,
|
||||
clip: Boolean
|
||||
) {
|
||||
val originalWidth = image.getWidth(null)
|
||||
val originalHeight = image.getHeight(null)
|
||||
val widthScale = maxWidth / originalWidth
|
||||
val heightScale = maxHeight / originalHeight
|
||||
val scale = minOf(widthScale, heightScale)
|
||||
val targetWidth = (originalWidth * scale).toInt()
|
||||
val targetHeight = (originalHeight * scale).toInt()
|
||||
if (clip) {
|
||||
this.clip = RoundRectangle2D.Float(
|
||||
x.toFloat(),
|
||||
y.toFloat(),
|
||||
targetWidth.toFloat(),
|
||||
targetHeight.toFloat(),
|
||||
30.toFloat(),
|
||||
30.toFloat()
|
||||
)
|
||||
}
|
||||
this.drawImage(image, x, y, targetWidth, targetHeight, null)
|
||||
}
|
||||
|
||||
fun BufferedImage.scaleImage(size: Pair<Int, Int>): BufferedImage {
|
||||
val scaledImage = BufferedImage(size.first, size.second, this.type)
|
||||
val graphics2d = scaledImage.createGraphics()
|
||||
graphics2d.drawImage(this, 0, 0, size.first, size.second, null)
|
||||
graphics2d.dispose()
|
||||
return scaledImage
|
||||
}
|
||||
|
||||
fun ByteArray.toBufferedImage(): BufferedImage {
|
||||
ByteArrayInputStream(this).use { inputStream ->
|
||||
return ImageIO.read(inputStream)
|
||||
}
|
||||
}
|
||||
|
||||
fun BufferedImage.toByteArray(): ByteArray {
|
||||
ByteArrayOutputStream().use { outputStream ->
|
||||
ImageIO.write(this, "png", outputStream)
|
||||
return outputStream.toByteArray()
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,5 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
val wsType get() = this.read<Config>().wsType
|
||||
val listeningGroups get() = this.read<Config>().listeningGroups
|
||||
val qweatherKey get() = this.read<Config>().qweatherKey
|
||||
val githubKey get() = this.read<Config>().githubKey
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/12
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.util.str
|
||||
|
||||
import java.awt.Graphics2D
|
||||
|
||||
fun setTruncat(origin: String, g2d: Graphics2D, maxWidth: Int = 500): String {
|
||||
val fontMetrics = g2d.fontMetrics
|
||||
val textWidth = fontMetrics.stringWidth(origin)
|
||||
return if (textWidth > maxWidth) {
|
||||
val ellipsisWidth = fontMetrics.stringWidth("...")
|
||||
val width = maxWidth - ellipsisWidth
|
||||
var endIndex = origin.length
|
||||
while (fontMetrics.stringWidth(origin.substring(0, endIndex)) > width && endIndex > 0) {
|
||||
endIndex--
|
||||
}
|
||||
origin.substring(0, endIndex) + "..."
|
||||
} else origin
|
||||
}
|
||||
Reference in New Issue
Block a user