mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
parent
041ddc8388
commit
fe5457b406
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user