Skip to content

Commit 329686d

Browse files
committed
BasicFontRenderer: Fix scaling
Fixes y position of text being incorrect when scaled. Also renames `originalPointSize` to `scaledPointSize` since the former is a misnomer.
1 parent ffc0b68 commit 329686d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ class BasicFontRenderer(
136136
shadow: Boolean,
137137
shadowColor: Color?
138138
) {
139-
val scaledPointSize = scale * regularFontInfo.atlas.size
140-
141139
if (shadow) {
142140
drawStringNow(
143141
vertexConsumer,
@@ -148,7 +146,7 @@ class BasicFontRenderer(
148146
),
149147
x + 1,
150148
y + 1,
151-
scaledPointSize,
149+
scale,
152150
)
153151
}
154152
drawStringNow(
@@ -158,7 +156,7 @@ class BasicFontRenderer(
158156
color,
159157
x,
160158
y,
161-
scaledPointSize,
159+
scale,
162160
)
163161
}
164162

@@ -181,8 +179,10 @@ class BasicFontRenderer(
181179
color: Color,
182180
x: Float,
183181
y: Float,
184-
originalPointSize: Float
182+
scale: Float,
185183
) {
184+
val scaledPointSize = scale * regularFontInfo.atlas.size
185+
186186
var currentX = x
187187
var i = 0
188188
while (i < string.length) {
@@ -204,22 +204,22 @@ class BasicFontRenderer(
204204
val planeBounds = glyph.planeBounds
205205

206206
if (planeBounds != null) {
207-
val width = (planeBounds.r - planeBounds.l) * originalPointSize
208-
val height = (planeBounds.t - planeBounds.b) * originalPointSize
207+
val width = (planeBounds.r - planeBounds.l) * scaledPointSize
208+
val height = (planeBounds.t - planeBounds.b) * scaledPointSize
209209

210210
drawGlyph(
211211
vertexConsumer,
212212
matrixStack,
213213
glyph,
214214
color,
215215
currentX,
216-
y + regularFontInfo.atlas.baseCharHeight - planeBounds.t * originalPointSize,
216+
y + regularFontInfo.atlas.baseCharHeight * scale - planeBounds.t * scaledPointSize,
217217
width,
218218
height
219219
)
220220
}
221221

222-
currentX += computeAdvance(regularFontInfo, glyph) * originalPointSize
222+
currentX += computeAdvance(regularFontInfo, glyph) * scaledPointSize
223223
i++
224224
}
225225

0 commit comments

Comments
 (0)