workaround ascented font

Fixes #75
This commit is contained in:
Moritz Zwerger 2023-11-18 22:06:40 +01:00
parent 041ddc8388
commit fe5457b406
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 18 additions and 9 deletions

View File

@ -74,8 +74,8 @@ class RasterizedCodePointRendererTest {
fun `12px height`() {
val consumer = object : DummyGUIVertexConsumer() {
override fun addChar(start: Vec2, end: Vec2, index: Int) {
assertEquals(start, Vec2(10.0f, 12.0f)) // -2 for ascent height difference, +1 for normal spacing, +1 for ascent fixing?
assertEquals(end, Vec2(15.0f, 24.0f))
assertEquals(start, Vec2(10.0f, 9.2f)) // whatever
assertEquals(end, Vec2(15.0f, 21.2f))
}
}
val char = DummyCodePointRenderer(ascent = 10.0f, height = 12.0f)

View File

@ -15,13 +15,14 @@ package de.bixilon.minosoft.gui.rendering.font.types.dummy
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.minosoft.gui.rendering.font.renderer.code.AscentedCodePointRenderer
import de.bixilon.minosoft.gui.rendering.font.renderer.code.AscentedCodePointRenderer.Companion.DEFAULT_ASCENT
import de.bixilon.minosoft.gui.rendering.system.dummy.texture.DummyTexture
class DummyCodePointRenderer(
override val uvStart: Vec2 = Vec2(0.1f, 0.2f),
override val uvEnd: Vec2 = Vec2(0.6f, 0.7f),
override val width: Float = 5.0f,
override val ascent: Float = 7.0f,
override val ascent: Float = DEFAULT_ASCENT,
override val height: Float = 8.0f,
) : AscentedCodePointRenderer {
override val texture = DummyTexture()

View File

@ -21,13 +21,17 @@ import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderPropert
* See the great explanation of @Suragch at https://stackoverflow.com/questions/27631736/meaning-of-top-ascent-baseline-descent-bottom-and-leading-in-androids-font
*/
interface AscentedCodePointRenderer : RasterizedCodePointRenderer {
val ascent: Float get() = 8.0f
val ascent: Float get() = DEFAULT_ASCENT
val height: Float
override fun calculateStart(properties: TextRenderProperties, base: Vec2, scale: Float): Vec2 {
val position = Vec2(base)
val offset = properties.charSpacing.top - (height - ascent - 1.0f)
var diff = ascent - DEFAULT_ASCENT
if (diff > 2.0f) {
diff += 0.8f // TODO: dirty hack
}
val offset = properties.charSpacing.top - diff
position.y += offset * scale
return position
@ -40,4 +44,8 @@ interface AscentedCodePointRenderer : RasterizedCodePointRenderer {
return position
}
companion object {
const val DEFAULT_ASCENT = 7.0f
}
}

View File

@ -22,8 +22,8 @@ import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
import de.bixilon.minosoft.gui.rendering.font.renderer.code.AscentedCodePointRenderer.Companion.DEFAULT_ASCENT
import de.bixilon.minosoft.gui.rendering.font.renderer.code.CodePointRenderer
import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FontProperties
import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FontProperties.CHAR_BASE_HEIGHT
import de.bixilon.minosoft.gui.rendering.font.types.PostInitFontType
import de.bixilon.minosoft.gui.rendering.font.types.empty.EmptyCodeRenderer
@ -66,7 +66,7 @@ class BitmapFontType(
override fun build(context: RenderContext, manager: FontManager, data: JsonObject): BitmapFontType? {
val file = data["file"]?.toString()?.let { it.toResourceLocation().texture() } ?: throw IllegalArgumentException("Missing file!")
val height = data["height"]?.toInt() ?: 8
val ascent = data["ascent"]?.toInt() ?: 7
val ascent = data["ascent"]?.toInt() ?: DEFAULT_ASCENT.toInt()
val chars = data["chars"]?.listCast<String>() ?: throw IllegalArgumentException("Missing chars!")
return load(file, height, ascent, chars, context)
}

View File

@ -61,8 +61,8 @@ interface GUIVertexConsumer {
val start = start.array
val end = end.array
val uvStart = (texture?.transformUV(uvStart) ?: uvStart).array
val uvEnd = (texture?.transformUV(uvEnd) ?: uvEnd).array
val uvStart = uvStart.array
val uvEnd = uvEnd.array
order.iterate { position, uv ->
val x = when (position) {