Skip to content

Commit cbe6de2

Browse files
committed
Take the dimension of the first emoji
1 parent b38439d commit cbe6de2

File tree

1 file changed

+13
-8
lines changed
  • common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph

1 file changed

+13
-8
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph/EmojiGlyphs.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.lambda.util.math.Vec2d
66
import java.awt.Color
77
import java.awt.Graphics2D
88
import java.awt.image.BufferedImage
9+
import java.io.File
910
import java.net.URL
1011
import java.nio.file.Files
1112
import 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

Comments
 (0)