Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]

- Fixed mirrored text drawing its letters unflipped

## [3.1.2]

- Item icons on 1.21.8 and newer are drawn by vanilla's own GUI item renderer, so animated and enchanted items, oversized models such as tridents, and resource pack item models look the same as in vanilla menus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlin.math.roundToInt
import kotlin.math.sin
import kotlin.math.sqrt
import kotlin.math.tan
import kotlin.math.withSign

public abstract class PolyTessellator : PolyRenderer {
// explicit API mode demands visibility on members of these protected classes, yet the
Expand Down Expand Up @@ -1219,8 +1220,8 @@ public abstract class PolyTessellator : PolyRenderer {
bucket = snapped
}
}
val kx = k * ax / big
val ky = k * ay / big
val kx = (k * ax / big).withSign(state.sx)
val ky = (k * ay / big).withSign(state.sy)
runFace = face
runBucket = bucket
runOutline = outline
Expand Down Expand Up @@ -1572,6 +1573,9 @@ public abstract class PolyTessellator : PolyRenderer {
private var shearBase = 0f

private fun glyphQuad(x0: Float, y0: Float, x1: Float, y1: Float, u0: Float, v0: Float, u1: Float, v1: Float, c: Int) {
// a quad mirrored on one axis winds backwards, which culling pipelines drop
if (x1 < x0) return glyphQuad(x1, y0, x0, y1, u1, v0, u0, v1, c)
if (y1 < y0) return glyphQuad(x0, y1, x1, y0, u0, v1, u1, v0, c)
if (shearX == 0f) return quadPx(x0, y0, x1, y1, u0, v0, u1, v1, c)
val s0 = shearX * (shearBase - y0)
val s1 = shearX * (shearBase - y1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,35 @@ class PolyTessellatorTest {
}
}

@Test
fun mirroredTextFlipsGlyphsInPlace() {
val face = object : PolyGlyphPage.Face {
override fun glyph(codepoint: Int) = 1
override fun advance(glyph: Int) = 1f
// like stb, a non-positive pixel size rasterizes nothing
override fun raster(glyph: Int, pixelSize: Float) = if (pixelSize > 0f) PolyGlyphPage.Raster(0, -4, 2, 4, ByteArray(8) { -1 }) else null
}
val old = PolyGlyphPage.rasterizer
PolyGlyphPage.rasterizer = object : PolyGlyphPage.Rasterizer { override fun face(name: String) = face }
try {
for (sy in listOf(1f, -1f)) {
fun bounds(draw: Recorder.() -> Unit): List<Float> {
val b = Recorder().run { scale(-1f, sy); draw(); done() }.single()
assertWinding(b)
val xs = (0 until 4).map { b.verts[it * 4] }
val ys = (0 until 4).map { b.verts[it * 4 + 1] }
assertTrue(b.verts[xs.indexOf(xs.max()) * 4 + 2] < b.verts[xs.indexOf(xs.min()) * 4 + 2], "texture not mirrored at scale -1, $sy")
return listOf(xs.min(), ys.min(), xs.max(), ys.max())
}
val top = if (sy > 0f) 16f else -20f
assertEquals(listOf(-12f, top, -10f, top + 4f), bounds { text("a", 10f, 20f, -1, PolyFont("mirror", 4f)) })
assertEquals(listOf(-13f, top - 1f, -9f, top + 5f), bounds { textOutline("a", 10f, 20f, -1, PolyFont("mirror", 4f), 1f) })
}
} finally {
PolyGlyphPage.rasterizer = old
}
}

@Test
fun mcOutlineCoversEachPixelOnce() {
val face = object : PolyGlyphPage.Face {
Expand Down