mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-06-13 01:04:05 +09:00
diacritics overlap artefacts fixed
not as I intended. fuck my life
This commit is contained in:
Binary file not shown.
BIN
demo.PNG
BIN
demo.PNG
Binary file not shown.
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
@@ -26,9 +26,11 @@ package net.torvald.terrarumsansbitmap.gdx
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.*
|
import com.badlogic.gdx.graphics.g2d.*
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import net.torvald.terrarumsansbitmap.GlyphProps
|
import net.torvald.terrarumsansbitmap.GlyphProps
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -417,7 +419,11 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
private val offsetUnihan = (H - H_UNIHAN) / 2
|
private val offsetUnihan = (H - H_UNIHAN) / 2
|
||||||
private val offsetCustomSym = (H - SIZE_CUSTOM_SYM) / 2
|
private val offsetCustomSym = (H - SIZE_CUSTOM_SYM) / 2
|
||||||
|
|
||||||
|
private var firstRun = true
|
||||||
private var textBuffer = CodepointSequence(256)
|
private var textBuffer = CodepointSequence(256)
|
||||||
|
private var oldCharSequence = ""
|
||||||
|
//private lateinit var textTexture: FrameBuffer
|
||||||
|
//private val textTexCamera = OrthographicCamera()
|
||||||
private var posXbuffer = intArrayOf() // absolute posX of glyphs from print-origin
|
private var posXbuffer = intArrayOf() // absolute posX of glyphs from print-origin
|
||||||
private var posYbuffer = intArrayOf() // absolute posY of glyphs from print-origin
|
private var posYbuffer = intArrayOf() // absolute posY of glyphs from print-origin
|
||||||
private var glyphWidthBuffer = intArrayOf() // width of each glyph
|
private var glyphWidthBuffer = intArrayOf() // width of each glyph
|
||||||
@@ -428,7 +434,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
|
|
||||||
|
|
||||||
override fun draw(batch: Batch, charSeq: CharSequence, x: Float, y: Float): GlyphLayout? {
|
override fun draw(batch: Batch, charSeq: CharSequence, x: Float, y: Float): GlyphLayout? {
|
||||||
val str = charSeq.toCodePoints()
|
val oldProjectionMatrix = batch.projectionMatrix
|
||||||
|
|
||||||
fun Int.flipY() = this * if (flipY) 1 else -1
|
fun Int.flipY() = this * if (flipY) 1 else -1
|
||||||
|
|
||||||
@@ -438,10 +444,16 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
val y = Math.round(y).toFloat()
|
val y = Math.round(y).toFloat()
|
||||||
|
|
||||||
|
|
||||||
if (textBuffer != str) {
|
if (charSeq.isNotBlank()) {
|
||||||
textBuffer = str
|
if (oldCharSequence != charSeq || firstRun) {
|
||||||
//println(textBuffer)
|
textBuffer = charSeq.toCodePoints()
|
||||||
|
val str = textBuffer
|
||||||
val widths = getWidthOfCharSeq(str)
|
val widths = getWidthOfCharSeq(str)
|
||||||
|
val texWidth = widths.sum()
|
||||||
|
|
||||||
|
//if (!firstRun) textTexture.dispose()
|
||||||
|
//textTexture = FrameBuffer(Pixmap.Format.RGBA8888, texWidth, H, true)
|
||||||
|
|
||||||
|
|
||||||
glyphWidthBuffer = widths
|
glyphWidthBuffer = widths
|
||||||
|
|
||||||
@@ -456,7 +468,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
if (charIndex > 0) {
|
if (charIndex > 0) {
|
||||||
// nonDiacriticCounter allows multiple diacritics
|
// nonDiacriticCounter allows multiple diacritics
|
||||||
|
|
||||||
val thisChar = textBuffer[charIndex]
|
val thisChar = str[charIndex]
|
||||||
if (glyphProps[thisChar] == null && errorOnUnknownChar) {
|
if (glyphProps[thisChar] == null && errorOnUnknownChar) {
|
||||||
val errorGlyphSB = StringBuilder()
|
val errorGlyphSB = StringBuilder()
|
||||||
Character.toChars(thisChar).forEach { errorGlyphSB.append(it) }
|
Character.toChars(thisChar).forEach { errorGlyphSB.append(it) }
|
||||||
@@ -465,7 +477,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
"(${thisChar.charInfo()})")
|
"(${thisChar.charInfo()})")
|
||||||
}
|
}
|
||||||
val thisProp = glyphProps[thisChar] ?: nullProp
|
val thisProp = glyphProps[thisChar] ?: nullProp
|
||||||
val lastNonDiacriticChar = textBuffer[nonDiacriticCounter]
|
val lastNonDiacriticChar = str[nonDiacriticCounter]
|
||||||
val itsProp = glyphProps[lastNonDiacriticChar] ?: nullProp
|
val itsProp = glyphProps[lastNonDiacriticChar] ?: nullProp
|
||||||
|
|
||||||
|
|
||||||
@@ -521,13 +533,25 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
|
|
||||||
//print("[TerrarumSansBitmap] widthTable for $textBuffer: ")
|
//print("[TerrarumSansBitmap] widthTable for $textBuffer: ")
|
||||||
//posXbuffer.forEach { print("$it ") }; println()
|
//posXbuffer.forEach { print("$it ") }; println()
|
||||||
|
|
||||||
|
firstRun = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//textTexCamera.setToOrtho(false, textTexture.width.toFloat(), textTexture.height.toFloat())
|
||||||
|
//textTexCamera.update()
|
||||||
|
//batch.projectionMatrix = textTexCamera.combined
|
||||||
|
|
||||||
|
|
||||||
originalColour = batch.color.cpy()
|
originalColour = batch.color.cpy()
|
||||||
var mainCol = originalColour
|
var mainCol = originalColour
|
||||||
var shadowCol = mainCol.cpy().mul(0.5f,0.5f,0.5f,1f)
|
var shadowCol = mainCol.cpy().mul(0.5f, 0.5f, 0.5f, 1f)
|
||||||
|
|
||||||
|
|
||||||
|
//textTexture.begin()
|
||||||
|
|
||||||
|
val runs = if (noShadow) 0..0 else 3 downTo 0
|
||||||
|
for (run in runs) { // 0: Main, 1..3: Shadows
|
||||||
resetHash()
|
resetHash()
|
||||||
var index = 0
|
var index = 0
|
||||||
while (index <= textBuffer.lastIndex) {
|
while (index <= textBuffer.lastIndex) {
|
||||||
@@ -536,12 +560,15 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
val (sheetX, sheetY) = getSheetwisePosition(c)
|
val (sheetX, sheetY) = getSheetwisePosition(c)
|
||||||
val hash = getHash(c)
|
val hash = getHash(c)
|
||||||
|
|
||||||
|
if (run == 0) {
|
||||||
//println("[TerrarumSansBitmap] sprite: $sheetID:${sheetX}x${sheetY}")
|
//println("[TerrarumSansBitmap] sprite: $sheetID:${sheetX}x${sheetY}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isColourCode(c)) {
|
if (isColourCode(c)) {
|
||||||
if (c == 0x100000) {
|
if (c == 0x100000) {
|
||||||
mainCol = originalColour
|
mainCol = originalColour
|
||||||
shadowCol = mainCol.cpy().mul(0.5f,0.5f,0.5f,1f)
|
shadowCol = mainCol.cpy().mul(0.5f, 0.5f, 0.5f, 1f)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mainCol = getColour(c)
|
mainCol = getColour(c)
|
||||||
@@ -564,27 +591,34 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
val jongRow = getHanFinalRow(hIndex)
|
val jongRow = getHanFinalRow(hIndex)
|
||||||
|
|
||||||
|
|
||||||
if (!noShadow) {
|
when (run) {
|
||||||
|
0 -> {
|
||||||
|
batch.color = mainCol
|
||||||
|
batch.draw(hangulSheet.get(indexCho, choRow), x + posXbuffer[index].toFloat(), y)
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index].toFloat(), y)
|
||||||
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index].toFloat(), y)
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
batch.color = shadowCol
|
batch.color = shadowCol
|
||||||
|
batch.draw(hangulSheet.get(indexCho, choRow), x + posXbuffer[index] + 1, y)
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow ), x + posXbuffer[index] + 1, y)
|
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow ), x + posXbuffer[index] , y + 1.flipY())
|
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow ), x + posXbuffer[index] + 1, y + 1.flipY())
|
|
||||||
|
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index] + 1, y)
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index] + 1, y)
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index] , y + 1.flipY())
|
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index] + 1, y + 1.flipY())
|
|
||||||
|
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index] + 1, y)
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index] + 1, y)
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index] , y + 1.flipY())
|
}
|
||||||
|
2 -> {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(hangulSheet.get(indexCho, choRow), x + posXbuffer[index], y + 1.flipY())
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index], y + 1.flipY())
|
||||||
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index], y + 1.flipY())
|
||||||
|
}
|
||||||
|
3 -> {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(hangulSheet.get(indexCho, choRow), x + posXbuffer[index] + 1, y + 1.flipY())
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index] + 1, y + 1.flipY())
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index] + 1, y + 1.flipY())
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index] + 1, y + 1.flipY())
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
batch.color = mainCol
|
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow) , x + posXbuffer[index], y)
|
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + posXbuffer[index], y)
|
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + posXbuffer[index], y)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
@@ -599,28 +633,48 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
|
|||||||
val posX = x + posXbuffer[index]
|
val posX = x + posXbuffer[index]
|
||||||
val texture = sheets[sheetID].get(sheetX, sheetY)
|
val texture = sheets[sheetID].get(sheetX, sheetY)
|
||||||
|
|
||||||
|
when (run) {
|
||||||
if (!noShadow) {
|
0 -> {
|
||||||
batch.color = shadowCol
|
|
||||||
batch.draw(texture, posX + 1, posY + 1.flipY())
|
|
||||||
batch.draw(texture, posX , posY + 1.flipY())
|
|
||||||
batch.draw(texture, posX + 1, posY)
|
|
||||||
}
|
|
||||||
|
|
||||||
batch.color = mainCol
|
batch.color = mainCol
|
||||||
batch.draw(texture, posX, posY)
|
batch.draw(texture, posX, posY)
|
||||||
}
|
}
|
||||||
|
1 -> {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(texture, posX + 1, posY)
|
||||||
|
}
|
||||||
|
2 -> {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(texture, posX, posY + 1.flipY())
|
||||||
|
}
|
||||||
|
3 -> {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(texture, posX + 1, posY + 1.flipY())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (noSuchGlyph: ArrayIndexOutOfBoundsException) {
|
catch (noSuchGlyph: ArrayIndexOutOfBoundsException) {
|
||||||
batch.color = mainCol
|
batch.color = mainCol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
index += 1
|
index++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*textTexture.end()
|
||||||
|
|
||||||
|
|
||||||
|
batch.color = originalColour
|
||||||
|
batch.projectionMatrix = oldProjectionMatrix
|
||||||
|
val textTex = textTexture.colorBufferTexture
|
||||||
|
|
||||||
|
batch.draw(textTex, x, y, textTex.width.toFloat(), textTex.height.toFloat())
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.color = originalColour
|
batch.color = originalColour
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user