From 45b431f953d26a7aa9a08b0e8759facb3d884b46 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 29 Sep 2020 14:07:35 +0900 Subject: [PATCH] fix: partial fix for issue #12 --- .../terrarumsansbitmap/gdx/GameFontBase.kt | 14 ++++++++- .../gdx/PixmapRegionPack.kt | 31 ++++++++++--------- testtext.txt | 1 + 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt index 44ac312..0f7c0fd 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt @@ -357,6 +357,11 @@ class GameFontBase( } sheets = sheetsPack.toTypedArray() + + // make sure null char is actually null (draws nothing and has zero width) + sheets[SHEET_ASCII_VARW].regions[0].setColor(0) + sheets[SHEET_ASCII_VARW].regions[0].fill() + glyphProps[0] = GlyphProps(0, 0) } override fun getLineHeight(): Float = H.toFloat() @@ -396,6 +401,13 @@ class GameFontBase( if (debug) println("[TerrarumSansBitmap] max age: $textCacheCap") + // Q&D fix for issue #12 + // When the line ends with a diacritics, the whole letter won't render + // If the line starts with a letter-with-diacritic, it will error out + // Some diacritics (e.g. COMBINING TILDE) do not obey lowercase letters + val charSeqNotBlank = charSeq.isNotBlank() // determine emptiness BEFORE you hack a null chars in + val charSeq = "\u0000" + charSeq + 0.toChar() + fun Int.flipY() = this * if (flipY) 1 else -1 // always draw at integer position; this is bitmap font after all @@ -408,7 +420,7 @@ class GameFontBase( val charSeqHash = charSeq.toCodePoints().getHash() - if (charSeq.isNotBlank()) { + if (charSeqNotBlank) { val cacheObj = getCache(charSeqHash) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt b/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt index 2914468..c83fdb3 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt @@ -25,14 +25,15 @@ package net.torvald.terrarumsansbitmap.gdx import com.badlogic.gdx.files.FileHandle -import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Pixmap /** + * Breaks one pixmap atlas into many child pixmaps + * * Created by minjaesong on 2018-09-17. */ class PixmapRegionPack( - pixmap: Pixmap, + pixmapAtlas: Pixmap, val tileW: Int, val tileH: Int, val hGap: Int = 0, @@ -47,8 +48,8 @@ class PixmapRegionPack( constructor(fileHandle: FileHandle, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0, xySwapped: Boolean = false) : this(Pixmap(fileHandle), tileW, tileH, hGap, vGap, hFrame, vFrame, xySwapped) - val horizontalCount = (pixmap.width - 2 * hFrame + hGap) / (tileW + hGap) - val verticalCount = (pixmap.height - 2 * vFrame + vGap) / (tileH + vGap) + val horizontalCount = (pixmapAtlas.width - 2 * hFrame + hGap) / (tileW + hGap) + val verticalCount = (pixmapAtlas.height - 2 * vFrame + vGap) / (tileH + vGap) val regions: Array @@ -70,10 +71,10 @@ class PixmapRegionPack( - pixmap.pixels.rewind() + pixmapAtlas.pixels.rewind() if (!xySwapped) { - regions = Array(horizontalCount * verticalCount, { + regions = Array(horizontalCount * verticalCount) { val rx = (it % horizontalCount * (tileW + hGap)) + hFrame // pixel, not index val ry = (it / horizontalCount * (tileH + vGap)) + vFrame // pixel, not index @@ -84,15 +85,15 @@ class PixmapRegionPack( // for every "scanline" for (y in 0 until tileH) { - val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4) + val offsetY = (ry + y) * (pixmapAtlas.width * 4) + (vFrame * pixmapAtlas.width * 4) val offsetX = rx * 4 + hFrame * 4 //println("offset: ${offsetX + offsetY}") val bytesBuffer = ByteArray(4 * tileW) - pixmap.pixels.position(offsetY + offsetX) - pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size) + pixmapAtlas.pixels.position(offsetY + offsetX) + pixmapAtlas.pixels.get(bytesBuffer, 0, bytesBuffer.size) // test print bytesbuffer /*bytesBuffer.forEachIndexed { index, it -> @@ -112,10 +113,10 @@ class PixmapRegionPack( // todo globalFlipY ? /*return*/region - }) + } } else { - regions = Array(horizontalCount * verticalCount, { + regions = Array(horizontalCount * verticalCount) { val rx = (it / verticalCount * (tileW + hGap)) + hFrame val ry = (it % verticalCount * (tileH + vGap)) + vFrame @@ -126,15 +127,15 @@ class PixmapRegionPack( // for every "scanline" for (y in 0 until tileH) { - val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4) + val offsetY = (ry + y) * (pixmapAtlas.width * 4) + (vFrame * pixmapAtlas.width * 4) val offsetX = rx * 4 + hFrame * 4 //println("offset: ${offsetX + offsetY}") val bytesBuffer = ByteArray(4 * tileW) - pixmap.pixels.position(offsetY + offsetX) - pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size) + pixmapAtlas.pixels.position(offsetY + offsetX) + pixmapAtlas.pixels.get(bytesBuffer, 0, bytesBuffer.size) // test print bytesbuffer /*bytesBuffer.forEachIndexed { index, it -> @@ -154,7 +155,7 @@ class PixmapRegionPack( // todo globalFlipY ? /*return*/region - }) + } } } diff --git a/testtext.txt b/testtext.txt index 456a0c1..ff11631 100755 --- a/testtext.txt +++ b/testtext.txt @@ -8,5 +8,6 @@ Yd /œ̃/ /ɛ̃/ ẽ +/ẽ when the line ends with a diacritics, whole letter wont render if the line starts with a letter-with-diacritic, it will error out \ No newline at end of file