mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-06-09 15:34:05 +09:00
Thai with diacritics works good enough; fixed wrong shadow of Korean
This commit is contained in:
@@ -83,7 +83,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
private fun isUniPunct(c: Char) = c.toInt() in 0x2000..0x206F
|
private fun isUniPunct(c: Char) = c.toInt() in 0x2000..0x206F
|
||||||
private fun isGreek(c: Char) = c.toInt() in 0x370..0x3CE
|
private fun isGreek(c: Char) = c.toInt() in 0x370..0x3CE
|
||||||
private fun isThai(c: Char) = c.toInt() in 0xE00..0xE7F
|
private fun isThai(c: Char) = c.toInt() in 0xE00..0xE7F
|
||||||
private fun isThaiDiacritics(c: Char) = c.toInt() in 0xE34..0xE3A
|
private fun isDiacritics(c: Char) = c.toInt() in 0xE34..0xE3A
|
||||||
|| c.toInt() in 0xE47..0xE4E
|
|| c.toInt() in 0xE47..0xE4E
|
||||||
|| c.toInt() == 0xE31
|
|| c.toInt() == 0xE31
|
||||||
private fun isCustomSym(c: Char) = c.toInt() in 0xE000..0xE0FF
|
private fun isCustomSym(c: Char) = c.toInt() in 0xE000..0xE0FF
|
||||||
@@ -173,7 +173,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
0xE00..0xE7F,
|
0xE00..0xE7F,
|
||||||
0xE000..0xE0FF
|
0xE000..0xE0FF
|
||||||
)
|
)
|
||||||
private val glyphWidths: HashMap<Int, Int> = HashMap()
|
private val glyphWidths: HashMap<Int, Int> = HashMap() // if the value is negative, it's diacritics
|
||||||
private val sheets: Array<TextureRegionPack>
|
private val sheets: Array<TextureRegionPack>
|
||||||
|
|
||||||
|
|
||||||
@@ -307,18 +307,21 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
|
|
||||||
private var textBuffer: CharSequence = ""
|
private var textBuffer: CharSequence = ""
|
||||||
private var textBWidth = intArrayOf() // absolute posX of glyphs from print-origin
|
private var textBWidth = intArrayOf() // absolute posX of glyphs from print-origin
|
||||||
|
private var textBGSize = intArrayOf() // width of each glyph
|
||||||
|
|
||||||
override fun draw(batch: Batch, str: CharSequence, x: Float, y: Float): GlyphLayout? {
|
override fun draw(batch: Batch, str: CharSequence, x: Float, y: Float): GlyphLayout? {
|
||||||
if (textBuffer != str) {
|
if (textBuffer != str) {
|
||||||
textBuffer = str
|
textBuffer = str
|
||||||
val widths = getWidthOfCharSeq(str)
|
val widths = getWidthOfCharSeq(str)
|
||||||
|
|
||||||
|
textBGSize = widths
|
||||||
|
|
||||||
textBWidth = Array(str.length, { charIndex ->
|
textBWidth = Array(str.length, { charIndex ->
|
||||||
if (charIndex == 0)
|
if (charIndex == 0)
|
||||||
0
|
0
|
||||||
else {
|
else {
|
||||||
var acc = 0
|
var acc = 0
|
||||||
(0..charIndex - 1).forEach { acc += widths[it] }
|
(0..charIndex - 1).forEach { acc += maxOf(0, widths[it]) } // don't accumulate diacrtics (which has negative value)
|
||||||
/*return*/acc
|
/*return*/acc
|
||||||
}
|
}
|
||||||
}).toIntArray()
|
}).toIntArray()
|
||||||
@@ -339,56 +342,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
|
|
||||||
//println("[TerrarumSansBitmap] sprite: $sheetID:${sheetXY[0]}x${sheetXY[1]}")
|
//println("[TerrarumSansBitmap] sprite: $sheetID:${sheetXY[0]}x${sheetXY[1]}")
|
||||||
|
|
||||||
if (sheetID != SHEET_HANGUL) {
|
if (sheetID == SHEET_HANGUL) {
|
||||||
|
|
||||||
if (!noShadow) {
|
|
||||||
batch.color = shadowCol
|
|
||||||
batch.draw(
|
|
||||||
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
|
||||||
x + textBWidth[index] + 1,
|
|
||||||
y +
|
|
||||||
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
|
||||||
offsetUnihan
|
|
||||||
else if (sheetID == SHEET_CUSTOM_SYM)
|
|
||||||
offsetCustomSym
|
|
||||||
else 0
|
|
||||||
)
|
|
||||||
batch.draw(
|
|
||||||
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
|
||||||
x + textBWidth[index],
|
|
||||||
y - 1 +
|
|
||||||
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
|
||||||
offsetUnihan
|
|
||||||
else if (sheetID == SHEET_CUSTOM_SYM)
|
|
||||||
offsetCustomSym
|
|
||||||
else 0
|
|
||||||
)
|
|
||||||
batch.draw(
|
|
||||||
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
|
||||||
x + textBWidth[index] + 1,
|
|
||||||
y - 1 +
|
|
||||||
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
|
||||||
offsetUnihan
|
|
||||||
else if (sheetID == SHEET_CUSTOM_SYM)
|
|
||||||
offsetCustomSym
|
|
||||||
else 0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
batch.color = mainCol
|
|
||||||
batch.draw(
|
|
||||||
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
|
||||||
x + textBWidth[index],
|
|
||||||
y +
|
|
||||||
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
|
||||||
offsetUnihan
|
|
||||||
else if (sheetID == SHEET_CUSTOM_SYM)
|
|
||||||
offsetCustomSym
|
|
||||||
else 0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else { // JOHAB (assemble) HANGUL
|
|
||||||
val hangulSheet = sheets[SHEET_HANGUL]
|
val hangulSheet = sheets[SHEET_HANGUL]
|
||||||
val hIndex = c.toInt() - 0xAC00
|
val hIndex = c.toInt() - 0xAC00
|
||||||
|
|
||||||
@@ -404,17 +358,80 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
if (!noShadow) {
|
if (!noShadow) {
|
||||||
batch.color = shadowCol
|
batch.color = shadowCol
|
||||||
|
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow), x + textBWidth[index] + 1, y)
|
batch.draw(hangulSheet.get(indexCho, choRow ), x + textBWidth[index] + 1, y)
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index], y - 1)
|
batch.draw(hangulSheet.get(indexCho, choRow ), x + textBWidth[index] , y - 1)
|
||||||
|
batch.draw(hangulSheet.get(indexCho, choRow ), x + textBWidth[index] + 1, y - 1)
|
||||||
|
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index] + 1, y)
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index] , y - 1)
|
||||||
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index] + 1, y - 1)
|
||||||
|
|
||||||
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index] + 1, y)
|
||||||
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index] , y - 1)
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index] + 1, y - 1)
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index] + 1, y - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
batch.color = mainCol
|
batch.color = mainCol
|
||||||
batch.draw(hangulSheet.get(indexCho, choRow), x + textBWidth[index], y)
|
batch.draw(hangulSheet.get(indexCho, choRow) , x + textBWidth[index], y)
|
||||||
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index], y)
|
batch.draw(hangulSheet.get(indexJung, jungRow), x + textBWidth[index], y)
|
||||||
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index], y)
|
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index], y)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
val offset = if (!isDiacritics(c)) 0 else {
|
||||||
|
if (index > 0) // LIMITATION: does not support double (or more) diacritics properly
|
||||||
|
(textBGSize[index] - textBGSize[index - 1]) / 2
|
||||||
|
else
|
||||||
|
textBGSize[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!noShadow) {
|
||||||
|
batch.color = shadowCol
|
||||||
|
batch.draw(
|
||||||
|
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
||||||
|
x + textBWidth[index] + 1 + offset,
|
||||||
|
y +
|
||||||
|
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
||||||
|
offsetUnihan
|
||||||
|
else if (sheetID == SHEET_CUSTOM_SYM)
|
||||||
|
offsetCustomSym
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
batch.draw(
|
||||||
|
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
||||||
|
x + textBWidth[index] + offset,
|
||||||
|
y - 1 +
|
||||||
|
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
||||||
|
offsetUnihan
|
||||||
|
else if (sheetID == SHEET_CUSTOM_SYM)
|
||||||
|
offsetCustomSym
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
batch.draw(
|
||||||
|
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
||||||
|
x + textBWidth[index] + 1 + offset,
|
||||||
|
y - 1 +
|
||||||
|
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
||||||
|
offsetUnihan
|
||||||
|
else if (sheetID == SHEET_CUSTOM_SYM)
|
||||||
|
offsetCustomSym
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
batch.color = mainCol
|
||||||
|
batch.draw(
|
||||||
|
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
|
||||||
|
x + textBWidth[index] + offset,
|
||||||
|
y +
|
||||||
|
if (sheetID == SHEET_UNIHAN) // evil exceptions
|
||||||
|
offsetUnihan
|
||||||
|
else if (sheetID == SHEET_CUSTOM_SYM)
|
||||||
|
offsetCustomSym
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.color = mainCol
|
this.color = mainCol
|
||||||
@@ -436,14 +453,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
val ctype = getSheetType(s[i])
|
val ctype = getSheetType(s[i])
|
||||||
|
|
||||||
if (variableWidthSheets.contains(ctype)) {
|
if (variableWidthSheets.contains(ctype)) {
|
||||||
len[i] = try {
|
if (!glyphWidths.containsKey(chr.toInt())) {
|
||||||
glyphWidths[chr.toInt()]!!
|
|
||||||
}
|
|
||||||
catch (e: kotlin.KotlinNullPointerException) {
|
|
||||||
println("[TerrarumSansBitmap] no width data for glyph number ${Integer.toHexString(chr.toInt()).toUpperCase()}")
|
println("[TerrarumSansBitmap] no width data for glyph number ${Integer.toHexString(chr.toInt()).toUpperCase()}")
|
||||||
//System.exit(1)
|
len[i] = W_LATIN_WIDE
|
||||||
W_LATIN_WIDE // failsafe
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len[i] = glyphWidths[chr.toInt()]!!
|
||||||
}
|
}
|
||||||
else if (ctype == SHEET_CJK_PUNCT)
|
else if (ctype == SHEET_CJK_PUNCT)
|
||||||
len[i] = W_ASIAN_PUNCT
|
len[i] = W_ASIAN_PUNCT
|
||||||
@@ -453,8 +468,6 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
len[i] = W_KANA
|
len[i] = W_KANA
|
||||||
else if (unihanWidthSheets.contains(ctype))
|
else if (unihanWidthSheets.contains(ctype))
|
||||||
len[i] = W_UNIHAN
|
len[i] = W_UNIHAN
|
||||||
else if (isThaiDiacritics(s[i]))
|
|
||||||
len[i] = 0 // set width of the glyph as -W_LATIN_WIDE
|
|
||||||
else if (ctype == SHEET_CUSTOM_SYM)
|
else if (ctype == SHEET_CUSTOM_SYM)
|
||||||
len[i] = SIZE_CUSTOM_SYM
|
len[i] = SIZE_CUSTOM_SYM
|
||||||
else
|
else
|
||||||
@@ -578,6 +591,10 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isDiacritics = pixmap.getPixel(codeStartX, codeStartY + H - 1).and(0xFF) != 0
|
||||||
|
if (isDiacritics)
|
||||||
|
glyphWidth = -glyphWidth
|
||||||
|
|
||||||
glyphWidths[code] = glyphWidth
|
glyphWidths[code] = glyphWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user