diff --git a/FontTestGDX/src/FontTestGDX.kt b/FontTestGDX/src/FontTestGDX.kt index aa8fa08..64d5860 100755 --- a/FontTestGDX/src/FontTestGDX.kt +++ b/FontTestGDX/src/FontTestGDX.kt @@ -41,9 +41,13 @@ class FontTestGDX : Game() { lateinit var layout: MovableType + private lateinit var testtex: TextureRegion + override fun create() { font = TerrarumSansBitmap("./assets", debug = true, flipY = false, errorOnUnknownChar = false, shadowAlpha = 0.5f) // must test for two flipY cases + testtex = TextureRegion(Texture("./testtex.tga")) + val inTextFile = Gdx.files.internal("./$demotextName") val reader = inTextFile.reader("UTF-8") inputText = reader.readLines().joinToString("\n") @@ -108,7 +112,14 @@ class FontTestGDX : Game() { // inputText.forEachIndexed { index, s -> // font.draw(batch, s, 10f, TEXH - 30f - index * lineHeight) // } - layout.draw(batch, 24f, 12f) + + // draw position debuggers +// font.draw(batch, "soft\uFE0F\u00ADhyphen\uFE0F\u00ADated", 24f, 12f) +// batch.draw(testtex, 24f, 12f) + // end of draw position debuggers + + val layoutDrawCall = { x: Float, y: Float, _: Int -> batch.draw(testtex, x, y) } + layout.draw(batch, 24f, 12f, mapOf(0 to layoutDrawCall)) batch.end() @@ -160,6 +171,7 @@ class FontTestGDX : Game() { override fun dispose() { font.dispose() faketex.dispose() + testtex.texture.dispose() } fun scrollAdd(x: Int = 1) { @@ -321,7 +333,7 @@ class FlippingSpriteBatch(size: Int = 1000) : SpriteBatch(size) { lateinit var appConfig: Lwjgl3ApplicationConfiguration const val TEXW = 800 -const val TEXH = 24 * 130 +const val TEXH = 24 * 170 const val WIDTH = TEXW const val HEIGHT = 768 diff --git a/src/net/torvald/terrarumsansbitmap/MovableType.kt b/src/net/torvald/terrarumsansbitmap/MovableType.kt index a288f24..59d9760 100644 --- a/src/net/torvald/terrarumsansbitmap/MovableType.kt +++ b/src/net/torvald/terrarumsansbitmap/MovableType.kt @@ -243,17 +243,31 @@ class MovableType( } } - fun draw(batch: Batch, x: Int, y: Int, lineStart: Int = 0, linesToDraw: Int = -1, lineHeight: Int = 24) = - draw(batch, x.toFloat(), y.toFloat(), lineStart, linesToDraw, lineHeight) + fun draw(batch: Batch, x: Int, y: Int, lineStart: Int = 0, linesToDraw: Int = -1, lineHeight: Int = TerrarumSansBitmap.LINE_HEIGHT, drawJobs: Map Unit> = HashMap()) = + draw(batch, x.toFloat(), y.toFloat(), lineStart, linesToDraw, lineHeight, drawJobs) - fun draw(batch: Batch, x: Float, y: Float, lineStart: Int = 0, linesToDraw: Int = 2147483647, lineHeight: Int = 24) { + fun draw(batch: Batch, x: Int, y: Int, drawJobs: Map Unit> = HashMap()) = + draw(batch, x.toFloat(), y.toFloat(), 0, 2147483647, TerrarumSansBitmap.LINE_HEIGHT, drawJobs) + + fun draw(batch: Batch, x: Float, y: Float, drawJobs: Map Unit> = HashMap()) = + draw(batch, x, y, 0, 2147483647, TerrarumSansBitmap.LINE_HEIGHT, drawJobs) + + /** + * @param drawJobs Draw call for specific lines (absolute line). This takes the form of Map from linnumber to draw function, + * which has three arguments: (line's top-left position-x, line's top-left position-y, absolute line number) + */ + fun draw(batch: Batch, x: Float, y: Float, lineStart: Int = 0, linesToDraw: Int = 2147483647, lineHeight: Int = TerrarumSansBitmap.LINE_HEIGHT, drawJobs: Map Unit> = HashMap()) { if (isNull) return typesettedSlugs.subList(lineStart, minOf(typesettedSlugs.size, lineStart + linesToDraw)).forEachIndexed { lineNum, lineBlocks -> // println("Line [${lineNum+1}] anchors: "+ lineBlocks.map { it.posX }.joinToString()) + val absoluteLineNum = lineStart + lineNum + + drawJobs[absoluteLineNum]?.invoke(x, y + lineNum * lineHeight, absoluteLineNum) + lineBlocks.forEach { - batch.draw(it.block.glyphLayout!!.linotype, x + it.posX - 16, y + lineNum * lineHeight) + batch.draw(it.block.glyphLayout!!.linotype, x + it.posX - 16, y + lineNum * lineHeight - 8) } // font.draw(batch, "I", x, y + lineNum * lineHeight + 14) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt index fc60ec7..6c03951 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt @@ -305,7 +305,7 @@ class TerrarumSansBitmap( glyphProps[0] = GlyphProps(0) } - override fun getLineHeight(): Float = 24f * scale + override fun getLineHeight(): Float = LINE_HEIGHT.toFloat() * scale override fun getXHeight() = 8f * scale override fun getCapHeight() = 12f * scale override fun getAscent() = 3f * scale @@ -2040,6 +2040,8 @@ class TerrarumSansBitmap( companion object { + const val LINE_HEIGHT = 24 + fun CodepointSequence.getHash(): Long { val hashBasis = -3750763034362895579L val hashPrime = 1099511628211L diff --git a/testtex.tga b/testtex.tga new file mode 100644 index 0000000..d02062c --- /dev/null +++ b/testtex.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e5814c2d96a902d7a9f6c5171d24a2d135d39d7d03074c7fd75d152ef132a6c +size 274