typesetter: extra draw call by line number

This commit is contained in:
minjaesong
2024-04-04 02:45:24 +09:00
parent 32c859fdf8
commit 30327776ba
4 changed files with 38 additions and 7 deletions

View File

@@ -41,9 +41,13 @@ class FontTestGDX : Game() {
lateinit var layout: MovableType lateinit var layout: MovableType
private lateinit var testtex: TextureRegion
override fun create() { override fun create() {
font = TerrarumSansBitmap("./assets", debug = true, flipY = false, errorOnUnknownChar = false, shadowAlpha = 0.5f) // must test for two flipY cases 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 inTextFile = Gdx.files.internal("./$demotextName")
val reader = inTextFile.reader("UTF-8") val reader = inTextFile.reader("UTF-8")
inputText = reader.readLines().joinToString("\n") inputText = reader.readLines().joinToString("\n")
@@ -108,7 +112,14 @@ class FontTestGDX : Game() {
// inputText.forEachIndexed { index, s -> // inputText.forEachIndexed { index, s ->
// font.draw(batch, s, 10f, TEXH - 30f - index * lineHeight) // 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() batch.end()
@@ -160,6 +171,7 @@ class FontTestGDX : Game() {
override fun dispose() { override fun dispose() {
font.dispose() font.dispose()
faketex.dispose() faketex.dispose()
testtex.texture.dispose()
} }
fun scrollAdd(x: Int = 1) { fun scrollAdd(x: Int = 1) {
@@ -321,7 +333,7 @@ class FlippingSpriteBatch(size: Int = 1000) : SpriteBatch(size) {
lateinit var appConfig: Lwjgl3ApplicationConfiguration lateinit var appConfig: Lwjgl3ApplicationConfiguration
const val TEXW = 800 const val TEXW = 800
const val TEXH = 24 * 130 const val TEXH = 24 * 170
const val WIDTH = TEXW const val WIDTH = TEXW
const val HEIGHT = 768 const val HEIGHT = 768

View File

@@ -243,17 +243,31 @@ class MovableType(
} } } }
fun draw(batch: Batch, x: Int, y: Int, lineStart: Int = 0, linesToDraw: Int = -1, lineHeight: Int = 24) = fun draw(batch: Batch, x: Int, y: Int, lineStart: Int = 0, linesToDraw: Int = -1, lineHeight: Int = TerrarumSansBitmap.LINE_HEIGHT, drawJobs: Map<Int, (Float, Float, Int) -> Unit> = HashMap()) =
draw(batch, x.toFloat(), y.toFloat(), lineStart, linesToDraw, lineHeight) 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<Int, (Float, Float, Int) -> Unit> = HashMap()) =
draw(batch, x.toFloat(), y.toFloat(), 0, 2147483647, TerrarumSansBitmap.LINE_HEIGHT, drawJobs)
fun draw(batch: Batch, x: Float, y: Float, drawJobs: Map<Int, (Float, Float, Int) -> 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<Int, (Float, Float, Int) -> Unit> = HashMap()) {
if (isNull) return if (isNull) return
typesettedSlugs.subList(lineStart, minOf(typesettedSlugs.size, lineStart + linesToDraw)).forEachIndexed { lineNum, lineBlocks -> typesettedSlugs.subList(lineStart, minOf(typesettedSlugs.size, lineStart + linesToDraw)).forEachIndexed { lineNum, lineBlocks ->
// println("Line [${lineNum+1}] anchors: "+ lineBlocks.map { it.posX }.joinToString()) // println("Line [${lineNum+1}] anchors: "+ lineBlocks.map { it.posX }.joinToString())
val absoluteLineNum = lineStart + lineNum
drawJobs[absoluteLineNum]?.invoke(x, y + lineNum * lineHeight, absoluteLineNum)
lineBlocks.forEach { 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) // font.draw(batch, "I", x, y + lineNum * lineHeight + 14)

View File

@@ -305,7 +305,7 @@ class TerrarumSansBitmap(
glyphProps[0] = GlyphProps(0) 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 getXHeight() = 8f * scale
override fun getCapHeight() = 12f * scale override fun getCapHeight() = 12f * scale
override fun getAscent() = 3f * scale override fun getAscent() = 3f * scale
@@ -2040,6 +2040,8 @@ class TerrarumSansBitmap(
companion object { companion object {
const val LINE_HEIGHT = 24
fun CodepointSequence.getHash(): Long { fun CodepointSequence.getHash(): Long {
val hashBasis = -3750763034362895579L val hashBasis = -3750763034362895579L
val hashPrime = 1099511628211L val hashPrime = 1099511628211L

BIN
testtex.tga LFS Normal file

Binary file not shown.