Armenian, Georgian (+other Kartvelian langs)

This commit is contained in:
minjaesong
2017-06-19 21:44:18 +09:00
parent 31c1adcee4
commit c5004c3ff6
4 changed files with 98 additions and 53 deletions

BIN
assets/hayeren_variable.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

BIN
assets/kartuli_variable.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@@ -87,9 +87,11 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
private fun isGreek(c: Char) = c.toInt() in codeRange[SHEET_GREEK_VARW] private fun isGreek(c: Char) = c.toInt() in codeRange[SHEET_GREEK_VARW]
private fun isThai(c: Char) = c.toInt() in codeRange[SHEET_THAI_VARW] private fun isThai(c: Char) = c.toInt() in codeRange[SHEET_THAI_VARW]
private fun isDiacritics(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 codeRange[SHEET_CUSTOM_SYM] private fun isCustomSym(c: Char) = c.toInt() in codeRange[SHEET_CUSTOM_SYM]
private fun isArmenian(c: Char) = c.toInt() in codeRange[SHEET_HAYEREN_VARW]
private fun isKartvelian(c: Char) = c.toInt() in codeRange[SHEET_KARTULI_VARW]
@@ -129,6 +131,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
private fun symbolIndexX(c: Char) = (c.toInt() - 0xE000) % 16 private fun symbolIndexX(c: Char) = (c.toInt() - 0xE000) % 16
private fun symbolIndexY(c: Char) = (c.toInt() - 0xE000) / 16 private fun symbolIndexY(c: Char) = (c.toInt() - 0xE000) / 16
private fun armenianIndexX(c: Char) = (c.toInt() - 0x530) % 16
private fun armenianIndexY(c: Char) = (c.toInt() - 0x530) / 16
private fun kartvelianIndexX(c: Char) = (c.toInt() - 0x10D0) % 16
private fun kartvelianIndexY(c: Char) = (c.toInt() - 0x10D0) / 16
private val unihanWidthSheets = arrayOf( private val unihanWidthSheets = arrayOf(
SHEET_UNIHAN, SHEET_UNIHAN,
SHEET_FW_UNI SHEET_FW_UNI
@@ -140,7 +148,9 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
SHEET_CYRILIC_VARW, SHEET_CYRILIC_VARW,
SHEET_UNI_PUNCT, SHEET_UNI_PUNCT,
SHEET_GREEK_VARW, SHEET_GREEK_VARW,
SHEET_THAI_VARW SHEET_THAI_VARW,
SHEET_HAYEREN_VARW,
SHEET_KARTULI_VARW
) )
private val fontParentDir = if (fontDir.endsWith('/') || fontDir.endsWith('\\')) fontDir else "$fontDir/" private val fontParentDir = if (fontDir.endsWith('/') || fontDir.endsWith('\\')) fontDir else "$fontDir/"
@@ -157,6 +167,8 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
"unipunct_variable.tga", "unipunct_variable.tga",
"greek_variable.tga", "greek_variable.tga",
"thai_variable.tga", "thai_variable.tga",
"hayeren_variable.tga",
"kartuli_variable.tga",
"puae000-e0ff.tga" "puae000-e0ff.tga"
) )
private val cyrilic_bg = "cyrilic_bulgarian_variable.tga" private val cyrilic_bg = "cyrilic_bulgarian_variable.tga"
@@ -174,6 +186,8 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
0x2000..0x206F, 0x2000..0x206F,
0x370..0x3CE, 0x370..0x3CE,
0xE00..0xE7F, 0xE00..0xE7F,
0x530..0x58F,
0x10D0..0x10FF,
0xE000..0xE0FF 0xE000..0xE0FF
) )
private val glyphWidths: HashMap<Int, Int> = HashMap() // if the value is negative, it's diacritics private val glyphWidths: HashMap<Int, Int> = HashMap() // if the value is negative, it's diacritics
@@ -383,59 +397,64 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index], y) batch.draw(hangulSheet.get(indexJong, jongRow), x + textBWidth[index], y)
} }
else { else {
val offset = if (!isDiacritics(c)) 0 else { try {
if (index > 0) // LIMITATION: does not support double (or more) diacritics properly val offset = if (!isDiacritics(c)) 0 else {
(textBGSize[index] - textBGSize[index - 1]) / 2 if (index > 0) // LIMITATION: does not support double (or more) diacritics properly
else (textBGSize[index] - textBGSize[index - 1]) / 2
textBGSize[index] else
} textBGSize[index]
}
if (!noShadow) { if (!noShadow) {
batch.color = shadowCol batch.color = shadowCol
batch.draw( batch.draw(
sheets[sheetID].get(sheetXY[0], sheetXY[1]), sheets[sheetID].get(sheetXY[0], sheetXY[1]),
x + textBWidth[index] + 1 + offset, x + textBWidth[index] + 1 + offset,
y + (if (sheetID == SHEET_UNIHAN) // evil exceptions y + (if (sheetID == SHEET_UNIHAN) // evil exceptions
offsetUnihan offsetUnihan
else if (sheetID == SHEET_CUSTOM_SYM) else if (sheetID == SHEET_CUSTOM_SYM)
offsetCustomSym offsetCustomSym
else else
0) * if (flipY) 1 else -1 0) * if (flipY) 1 else -1
) )
batch.draw(
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
x + textBWidth[index] + offset,
y + (if (sheetID == SHEET_UNIHAN) // evil exceptions
offsetUnihan + 1
else if (sheetID == SHEET_CUSTOM_SYM)
offsetCustomSym + 1
else
1) * if (flipY) 1 else -1
)
batch.draw(
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
x + textBWidth[index] + 1 + offset,
y + (if (sheetID == SHEET_UNIHAN) // evil exceptions
offsetUnihan + 1
else if (sheetID == SHEET_CUSTOM_SYM)
offsetCustomSym + 1
else
1) * if (flipY) 1 else -1
)
}
batch.color = mainCol
batch.draw( batch.draw(
sheets[sheetID].get(sheetXY[0], sheetXY[1]), sheets[sheetID].get(sheetXY[0], sheetXY[1]),
x + textBWidth[index] + offset, x + textBWidth[index] + offset,
y + (if (sheetID == SHEET_UNIHAN) // evil exceptions y +
offsetUnihan + 1 if (sheetID == SHEET_UNIHAN) // evil exceptions
else if (sheetID == SHEET_CUSTOM_SYM) offsetUnihan
offsetCustomSym + 1 else if (sheetID == SHEET_CUSTOM_SYM)
else offsetCustomSym
1) * if (flipY) 1 else -1 else 0
)
batch.draw(
sheets[sheetID].get(sheetXY[0], sheetXY[1]),
x + textBWidth[index] + 1 + offset,
y + (if (sheetID == SHEET_UNIHAN) // evil exceptions
offsetUnihan + 1
else if (sheetID == SHEET_CUSTOM_SYM)
offsetCustomSym + 1
else
1) * if (flipY) 1 else -1
) )
} }
catch (noSuchGlyph: ArrayIndexOutOfBoundsException) {
batch.color = mainCol
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
)
} }
} }
@@ -510,6 +529,10 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
return SHEET_THAI_VARW return SHEET_THAI_VARW
else if (isCustomSym(c)) else if (isCustomSym(c))
return SHEET_CUSTOM_SYM return SHEET_CUSTOM_SYM
else if (isArmenian(c))
return SHEET_HAYEREN_VARW
else if (isKartvelian(c))
return SHEET_KARTULI_VARW
else else
return SHEET_UNKNOWN return SHEET_UNKNOWN
// fixed width // fixed width
@@ -563,6 +586,14 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
sheetX = symbolIndexX(ch) sheetX = symbolIndexX(ch)
sheetY = symbolIndexY(ch) sheetY = symbolIndexY(ch)
} }
SHEET_HAYEREN_VARW -> {
sheetX = armenianIndexX(ch)
sheetY = armenianIndexY(ch)
}
SHEET_KARTULI_VARW -> {
sheetX = kartvelianIndexX(ch)
sheetY = kartvelianIndexY(ch)
}
else -> { else -> {
sheetX = ch.toInt() % 16 sheetX = ch.toInt() % 16
sheetY = ch.toInt() / 16 sheetY = ch.toInt() / 16
@@ -602,6 +633,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
} }
} }
private val glyphLayout = GlyphLayout()
fun getWidth(text: String): Int {
glyphLayout.setText(this, text)
return glyphLayout.width.toInt()
}
companion object { companion object {
@@ -634,7 +671,9 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
internal val SHEET_UNI_PUNCT = 9 internal val SHEET_UNI_PUNCT = 9
internal val SHEET_GREEK_VARW = 10 internal val SHEET_GREEK_VARW = 10
internal val SHEET_THAI_VARW = 11 internal val SHEET_THAI_VARW = 11
internal val SHEET_CUSTOM_SYM = 12 internal val SHEET_HAYEREN_VARW = 12
internal val SHEET_KARTULI_VARW = 13
internal val SHEET_CUSTOM_SYM = 14
internal val SHEET_UNKNOWN = 254 internal val SHEET_UNKNOWN = 254

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarumsansbitmap.gdx package net.torvald.terrarumsansbitmap.gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
@@ -16,6 +17,11 @@ class TextureRegionPack(
val vFrame: Int = 0 val vFrame: Int = 0
) { ) {
constructor(ref: String, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0) :
this(Texture(ref), tileW, tileH, hGap, vGap, hFrame, vFrame)
constructor(fileHandle: FileHandle, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0) :
this(Texture(fileHandle), tileW, tileH, hGap, vGap, hFrame, vFrame)
companion object { companion object {
/** Intented for Y-down coord system, typically fon Non-GDX codebase */ /** Intented for Y-down coord system, typically fon Non-GDX codebase */
var globalFlipY = false var globalFlipY = false
@@ -23,8 +29,8 @@ class TextureRegionPack(
val regions: Array<TextureRegion> val regions: Array<TextureRegion>
private val horizontalCount = (texture.width - 2 * hFrame + hGap) / (tileW + hGap) val horizontalCount = (texture.width - 2 * hFrame + hGap) / (tileW + hGap)
private val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap) val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap)
init { init {
//println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH") //println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH")