Skip to content

Commit

Permalink
Merge pull request #4 from xiao-zheng233/master
Browse files Browse the repository at this point in the history
添加Osu图标生成
  • Loading branch information
LaoLittle authored Jun 3, 2022
2 parents de23d92 + 6e11594 commit 9c97bd8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Binary file added Font/Aller-Bold.ttf
Binary file not shown.
9 changes: 7 additions & 2 deletions src/main/kotlin/DrawMeme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object DrawMeme : KotlinPlugin(
val zeroReg = Regex("""#(\d{1,3})""")
val erodeReg = Regex("""^#erode ?(\d*) ?(\d*)""")
val emojiReg = Regex("""^($fullEmojiRegex) *($fullEmojiRegex)$""")
val osuReg = Regex("""^#osu (.*)""")

globalEventChannel().subscribeGroupMessages(
priority = EventPriority.NORMAL
Expand Down Expand Up @@ -254,7 +255,11 @@ object DrawMeme : KotlinPlugin(
val file = getEmojiMix(first, second) ?: getEmojiMix(second, first) ?: return@finding
file.toExternalResource("png").use { e -> subject.sendImage(e) }
}

finding(osuReg) {
val content = it.groupValues[1]
subject.sendImage(osu(if (content.isBlank()) "osu!" else content))
}
}
}
}

}
34 changes: 34 additions & 0 deletions src/main/kotlin/meme/Osu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.laolittle.plugin.draw.meme

import org.jetbrains.skia.*
import org.laolittle.plugin.Fonts
import org.laolittle.plugin.draw.makeFromResource
import org.laolittle.plugin.usedBy

private val paintText = Paint().apply {
color = Color.WHITE
}

private val osuImage = Image.makeFromResource("/Osu/logo.png")

private val font = Fonts["Aller-Bold", 112.5F] usedBy "OSU图标生成"

fun osu(text: String = "osu!"): Image {
val osuText: TextLine
val yPos: Float
val textWidth = font.measureTextWidth(text, paintText)
if (textWidth <= 250) {
osuText = TextLine.make(text, font)
yPos = 137.5F + osuText.height / 2
}else {
yPos = 210 - (textWidth - 255) / 20
osuText = TextLine.make(text, font.makeWithSize(250F / textWidth * 112.5F))
}

return Surface.makeRasterN32Premul(350, 350).apply {
canvas.apply {
drawImage(osuImage, 0F, 0F)
drawTextLine(osuText, 175F - osuText.width / 2, yPos, paintText)
}
}.makeImageSnapshot()
}
Binary file added src/main/resources/Osu/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9c97bd8

Please sign in to comment.