mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
gdx font: thai works good enough; RIP performance tho
This commit is contained in:
@@ -60,7 +60,11 @@ class TestTestTest : ApplicationAdapter() {
|
||||
"",
|
||||
"x86-64 е наименованието на наборът от 64-битови разширения към x86 процесорната архитектура. Като синоним",
|
||||
"на това наименование, се използват и съкращенията AMD64 (използвано от AMD), EM64T и IA-32e (използвани от",
|
||||
"Intel) и x64 (използвано от Microsoft)."
|
||||
"Intel) и x64 (използвано от Microsoft).",
|
||||
"",
|
||||
"เอกซ์86-64 (x86-64) เป็นชื่อของสถาปัตยกรรมคอมพิวเตอร์สำหรับไมโครโพรเซสเซอร์แบบ 64 บิต และชุดคำสั่งที่ใช้งานด้วยกัน x86-64",
|
||||
"เป็นส่วนขยายของสถาปัตยกรรมแบบ x86 ออกแบบโดยบริษัท AMD และใช้ชื่อทางการค้าว่า AMD64 ในภายหลังบริษัทอินเทลได้นำสถาปัตยกร",
|
||||
"รมนี้ไปใช้ใต้ชื่อการค้าว่า Intel 64 หรือ EM64T ซึ่งชื่อทั่วไปที่ใช้กันโดยไม่อิงกับชื่อการค้าคือ x86-64 หรือ x64"
|
||||
)
|
||||
|
||||
override fun render() {
|
||||
@@ -96,11 +100,11 @@ class TestTestTest : ApplicationAdapter() {
|
||||
|
||||
fun main(args: Array<String>) { // LWJGL 3 won't work? java.lang.VerifyError
|
||||
val config = LwjglApplicationConfiguration()
|
||||
config.useGL30 = true
|
||||
//config.useGL30 = true
|
||||
config.vSyncEnabled = false
|
||||
config.resizable = false
|
||||
config.width = 1072
|
||||
config.height = 742
|
||||
//config.foregroundFPS = 9999
|
||||
config.foregroundFPS = 9999
|
||||
LwjglApplication(TestTestTest(), config)
|
||||
}
|
||||
@@ -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 isGreek(c: Char) = c.toInt() in 0x370..0x3CE
|
||||
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() == 0xE31
|
||||
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,
|
||||
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>
|
||||
|
||||
|
||||
@@ -307,18 +307,21 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
||||
|
||||
private var textBuffer: CharSequence = ""
|
||||
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? {
|
||||
if (textBuffer != str) {
|
||||
textBuffer = str
|
||||
val widths = getWidthOfCharSeq(str)
|
||||
|
||||
textBGSize = widths
|
||||
|
||||
textBWidth = Array(str.length, { charIndex ->
|
||||
if (charIndex == 0)
|
||||
0
|
||||
else {
|
||||
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
|
||||
}
|
||||
}).toIntArray()
|
||||
@@ -339,56 +342,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
||||
|
||||
//println("[TerrarumSansBitmap] sprite: $sheetID:${sheetXY[0]}x${sheetXY[1]}")
|
||||
|
||||
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
|
||||
if (sheetID == SHEET_HANGUL) {
|
||||
val hangulSheet = sheets[SHEET_HANGUL]
|
||||
val hIndex = c.toInt() - 0xAC00
|
||||
|
||||
@@ -404,17 +358,80 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
||||
if (!noShadow) {
|
||||
batch.color = shadowCol
|
||||
|
||||
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] + 1, y)
|
||||
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.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(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
|
||||
@@ -436,14 +453,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
||||
val ctype = getSheetType(s[i])
|
||||
|
||||
if (variableWidthSheets.contains(ctype)) {
|
||||
len[i] = try {
|
||||
glyphWidths[chr.toInt()]!!
|
||||
}
|
||||
catch (e: kotlin.KotlinNullPointerException) {
|
||||
if (!glyphWidths.containsKey(chr.toInt())) {
|
||||
println("[TerrarumSansBitmap] no width data for glyph number ${Integer.toHexString(chr.toInt()).toUpperCase()}")
|
||||
//System.exit(1)
|
||||
W_LATIN_WIDE // failsafe
|
||||
len[i] = W_LATIN_WIDE
|
||||
}
|
||||
|
||||
len[i] = glyphWidths[chr.toInt()]!!
|
||||
}
|
||||
else if (ctype == SHEET_CJK_PUNCT)
|
||||
len[i] = W_ASIAN_PUNCT
|
||||
@@ -453,8 +468,6 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false) : BitmapFont(
|
||||
len[i] = W_KANA
|
||||
else if (unihanWidthSheets.contains(ctype))
|
||||
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)
|
||||
len[i] = SIZE_CUSTOM_SYM
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user