fix: partial fix for issue #12

This commit is contained in:
minjaesong
2020-09-29 14:07:35 +09:00
parent bbee554fec
commit 45b431f953
3 changed files with 30 additions and 16 deletions

View File

@@ -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)

View File

@@ -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<Pixmap>
@@ -70,10 +71,10 @@ class PixmapRegionPack(
pixmap.pixels.rewind()
pixmapAtlas.pixels.rewind()
if (!xySwapped) {
regions = Array<Pixmap>(horizontalCount * verticalCount, {
regions = Array<Pixmap>(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<Pixmap>(horizontalCount * verticalCount, {
regions = Array<Pixmap>(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
})
}
}
}

View File

@@ -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