@@ -7,23 +7,25 @@ import org.jetbrains.skia.*
7
7
import org.jetbrains.skia.paragraph.*
8
8
import xyz.cssxsh.skia.FontUtils
9
9
import java.io.Closeable
10
+ import java.io.File
10
11
import java.io.FileNotFoundException
11
12
import java.io.InputStream
12
13
import java.util.zip.ZipFile
13
14
import kotlin.math.*
14
15
15
16
/* *
16
17
* [The Original Ayaka](https://github.com/TheOriginalAyaka/sekai-stickers)
17
- */
18
+ */
18
19
public class ProjectSekaiStickers private constructor(private val source : ZipFile ) : Closeable {
19
20
public constructor (path: String ) : this (source = ZipFile (path))
21
+ public constructor (file: File ) : this (source = ZipFile (file))
20
22
21
23
private fun ZipFile.getInputStream (name : String ): InputStream {
22
24
val entry = getEntry(name) ? : throw FileNotFoundException (name)
23
25
return getInputStream(entry)
24
26
}
25
27
26
- private val characters: List <Character > by lazy {
28
+ internal val characters: List <Character > by lazy {
27
29
source.getInputStream(" sekai-stickers-main/src/characters.json" ).use { input ->
28
30
@OptIn(ExperimentalSerializationApi ::class )
29
31
Json .decodeFromStream<List <Character >>(input)
@@ -48,7 +50,7 @@ public class ProjectSekaiStickers private constructor(private val source: ZipFil
48
50
return Image .makeFromEncoded(bytes)
49
51
}
50
52
51
- public fun create (name : String , block : Content .() -> Unit ): Image {
53
+ public fun create (name : String , block : Content .() -> Unit ): Surface {
52
54
val character = characters.find { it.name == name } ? : throw NoSuchElementException (name)
53
55
54
56
val surface = Surface .makeRasterN32Premul(296 , 256 )
@@ -85,36 +87,40 @@ public class ProjectSekaiStickers private constructor(private val source: ZipFil
85
87
}
86
88
87
89
ParagraphBuilder (style, fonts)
88
- .pushStyle(TextStyle ()
89
- .setFontSize(content.size)
90
- .setForeground(Paint ().apply {
91
- strokeCap = PaintStrokeCap .ROUND
92
- strokeJoin = PaintStrokeJoin .ROUND
93
- strokeWidth = 10F
94
- color = Color .WHITE
95
- mode = PaintMode .STROKE
96
- })
97
- .setFontFamilies(arrayOf(" FOT-Yuruka Std UB" , " YurukaStd" , " SSFangTangTi" )))
90
+ .pushStyle(
91
+ TextStyle ()
92
+ .setFontSize(content.size)
93
+ .setForeground(Paint ().apply {
94
+ strokeCap = PaintStrokeCap .ROUND
95
+ strokeJoin = PaintStrokeJoin .ROUND
96
+ strokeWidth = 10F
97
+ color = Color .WHITE
98
+ mode = PaintMode .STROKE
99
+ })
100
+ .setFontFamilies(arrayOf(" FOT-Yuruka Std UB" , " YurukaStd" , " SSFangTangTi" ))
101
+ )
98
102
.addText(content.text)
99
103
.build()
100
104
.layout(surface.width.toFloat())
101
105
.paint(canvas, - 6F , 6F )
102
106
103
107
104
108
ParagraphBuilder (style, fonts)
105
- .pushStyle(TextStyle ()
106
- .setFontSize(content.size)
107
- .setForeground(Paint ().apply {
108
- color = character.color.replace(" #" , " FF" ).toLong(16 ).toInt()
109
- mode = PaintMode .FILL
110
- })
111
- .setFontFamilies(arrayOf(" FOT-Yuruka Std UB" , " YurukaStd" , " SSFangTangTi" )))
109
+ .pushStyle(
110
+ TextStyle ()
111
+ .setFontSize(content.size)
112
+ .setForeground(Paint ().apply {
113
+ color = character.color.replace(" #" , " FF" ).toLong(16 ).toInt()
114
+ mode = PaintMode .FILL
115
+ })
116
+ .setFontFamilies(arrayOf(" FOT-Yuruka Std UB" , " YurukaStd" , " SSFangTangTi" ))
117
+ )
112
118
.addText(content.text)
113
119
.build()
114
120
.layout(surface.width.toFloat())
115
121
.paint(canvas, - 6F , 6F )
116
122
117
- return surface.makeImageSnapshot()
123
+ return surface
118
124
}
119
125
120
126
override fun close (): Unit = source.close()
0 commit comments