@@ -6,6 +6,7 @@ import com.lambda.util.math.Vec2d
66import java.awt.Color
77import java.awt.Graphics2D
88import java.awt.image.BufferedImage
9+ import java.io.File
910import java.net.URL
1011import java.nio.file.Files
1112import java.util.zip.ZipFile
@@ -23,12 +24,16 @@ class EmojiGlyphs(zipUrl: String) {
2324 file.writeBytes(url.readBytes())
2425
2526 ZipFile (file).use { zip ->
27+ // someone please refactor this
28+ val first = ImageIO .read(zip.getInputStream(zip.entries().nextElement()))
29+
2630 val size = zip.entries().asSequence().count()
27- val dimensions = Vec2d (72.0 , 72.0 )
31+ val dimensions = Vec2d (first.width.toDouble(), first.height.toDouble() )
2832 val texelSize = 1.0 / size
29- val width = 72 * ceil(sqrt(size.toDouble())).toInt()
33+ val width = first.width * ceil(sqrt(size.toDouble())).toInt()
34+ val height = first.height * ceil(sqrt(size.toDouble())).toInt()
3035
31- val image = BufferedImage (width, width , BufferedImage .TYPE_INT_ARGB )
36+ val image = BufferedImage (width, height , BufferedImage .TYPE_INT_ARGB )
3237 val graphics = image.graphics as Graphics2D
3338 graphics.background = Color (0 , 0 , 0 , 0 )
3439
@@ -37,20 +42,20 @@ class EmojiGlyphs(zipUrl: String) {
3742
3843 zip.entries().asSequence().forEach { entry ->
3944 val name = entry.name.substringAfterLast(" /" ).substringBeforeLast(" ." )
40- val charImage = ImageIO .read(zip.getInputStream(entry))
45+ val emoji = ImageIO .read(zip.getInputStream(entry))
4146
42- if (x + 72 >= width) {
43- y + = 72
47+ if (x + emoji.width >= width) {
48+ y + = emoji.height
4449 x = 0
4550 }
4651
47- graphics.drawImage(charImage , x, y, null )
52+ graphics.drawImage(emoji , x, y, null )
4853
4954 val uv1 = Vec2d (x.toDouble(), y.toDouble()) * texelSize
5055 val uv2 = Vec2d (x, y).plus(dimensions) * texelSize
5156 emojiMap[name] = CharInfo (dimensions, uv1, uv2)
5257
53- x + = 72
58+ x + = emoji.width
5459 }
5560
5661 fontTexture = MipmapTexture (image)
0 commit comments