Romanian and Thai language support, GameFont: scaling

Former-commit-id: 960bbc00b2d16111b5b63fc31a71a8093bae9dc1
Former-commit-id: 159beb538d151a6b332809ddfeb66ce1e02be52d
This commit is contained in:
Song Minjae
2016-07-17 21:05:47 +09:00
parent 644ae95e01
commit 222bf0811c
13 changed files with 115 additions and 51 deletions

View File

@@ -71,14 +71,28 @@ constructor() : Font {
private fun isWenQuanYi2(c: Char) = c.toInt() >= 0x69FD && c.toInt() <= 0x9FDC
private fun isGreek(c: Char) = c.toInt() >= 0x370 && c.toInt() <= 0x3CE
private fun isGreekEF(c: Char) = greekEFList.contains(c)
private fun isRomanian(c: Char) = c.toInt() >= 0x218 && c.toInt() <= 0x21A
private fun isRomanianEF(c: Char) = c.toInt() == 0x21B
private fun isThai(c: Char) = c.toInt() >= 0xE00 && c.toInt() <= 0xE7F
private fun isThaiDiacritics(c: Char) = (c.toInt() >= 0xE34 && c.toInt() <= 0xE3A)
|| (c.toInt() >= 0xE47 && c.toInt() <= 0xE4E)
|| (c.toInt() == 0xE31)
private fun isThaiEF(c: Char) = c.toInt() == 0xE40
private fun asciiEFindexX(c: Char) = asciiEFList.indexOf(c) % 16
private fun asciiEFindexY(c: Char) = asciiEFList.indexOf(c) / 16
private fun extAEFindexX(c: Char) = extAEFList.indexOf(c) % 16
private fun extAEFindexY(c: Char) = extAEFList.indexOf(c) / 16
private fun extAindexX(c: Char) = (c.toInt() - 0x100) % 16
private fun extAindexY(c: Char) = (c.toInt() - 0x100) / 16
private fun extAEFindexX(c: Char) =
if (isThaiEF(c)) 3 // thai เ
else extAEFList.indexOf(c) % 16
private fun extAEFindexY(c: Char) =
if (isThaiEF(c)) 0 // thai เ
else extAEFList.indexOf(c) / 16
private fun runicIndexX(c: Char) = runicList.indexOf(c) % 16
private fun runicIndexY(c: Char) = runicList.indexOf(c) / 16
@@ -115,12 +129,21 @@ constructor() : Font {
private fun greekEFIndexX(c: Char) = greekEFList.indexOf(c) % 16
private fun greekEFIndexY(c: Char) = greekEFList.indexOf(c) / 16
private fun romanianIndexX(c: Char) = c.toInt() - 0x218
private fun romanianIndexY(c: Char) = 0
private fun thaiIndexX(c: Char) = (c.toInt() - 0xE00) % 16
private fun thaiIndexY(c: Char) = (c.toInt() - 0xE00) / 16
private fun thaiEFIndexX(c: Char) = 3
private fun thaiEFIndexY(c: Char) = 0
private val narrowWidthSheets = arrayOf(
SHEET_ASCII_EF,
SHEET_EXTA_EF,
SHEET_CYRILIC_EF,
SHEET_GREEK_EF
SHEET_GREEK_EF,
SHEET_EXTB_ROMANIAN_EF
)
private val unihanWidthSheets = arrayOf(
SHEET_UNIHAN,
@@ -169,17 +192,19 @@ constructor() : Font {
len += W_CJK
else if (unihanWidthSheets.contains(ctype))
len += W_UNIHAN
else if (isThaiDiacritics(s[i]))
len = len // set width of the glyph as -W_LATIN_WIDE
else
len += W_LATIN_WIDE
if (i < endIndex - 1) len += interchar
}
return len
return len * scale
}
override fun getHeight(s: String) = H
override fun getHeight(s: String) = H * scale
override fun getLineHeight() = H
override fun getLineHeight() = H * scale
override fun drawString(x: Float, y: Float, s: String) = drawString(x, y, s, Color.white)
@@ -236,17 +261,17 @@ constructor() : Font {
hangulSheet.getSubImage(indexCho, choRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
thisCol
scale.toFloat(), thisCol
)
hangulSheet.getSubImage(indexJung, jungRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
thisCol
scale.toFloat(), thisCol
)
hangulSheet.getSubImage(indexJong, jongRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
thisCol
scale.toFloat(), thisCol
)
}
}
@@ -294,7 +319,7 @@ constructor() : Font {
wenQuanYi_1.getSubImage(wenQuanYiIndexX(ch), wenQuanYi1IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
thisCol
scale.toFloat(), thisCol
)
}
}
@@ -322,7 +347,7 @@ constructor() : Font {
wenQuanYi_2.getSubImage(wenQuanYiIndexX(ch), wenQuanYi2IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
thisCol
scale.toFloat(), thisCol
)
}
}
@@ -364,8 +389,8 @@ constructor() : Font {
sheetY = runicIndexY(ch)
}
SHEET_EXTA_EM -> {
sheetX = (ch.toInt() - 0x100) % 16
sheetY = (ch.toInt() - 0x100) / 16
sheetX = extAindexX(ch)
sheetY = extAindexY(ch)
}
SHEET_KANA -> {
sheetX = kanaIndexX(ch)
@@ -399,6 +424,18 @@ constructor() : Font {
sheetX = greekEFIndexX(ch)
sheetY = greekEFIndexY(ch)
}
SHEET_EXTB_ROMANIAN_EM -> {
sheetX = romanianIndexX(ch)
sheetY = romanianIndexY(ch)
}
SHEET_EXTB_ROMANIAN_EF -> {
sheetX = 0
sheetY = 0
}
SHEET_THAI_EM -> {
sheetX = thaiIndexX(ch)
sheetY = thaiIndexY(ch)
}
else -> {
sheetX = ch.toInt() % 16
sheetY = ch.toInt() / 16
@@ -415,7 +452,7 @@ constructor() : Font {
else 0,
sheetX, sheetY
)*/
sheetKey[prevInstance].getSubImage(sheetX, sheetY).draw(
sheetKey[prevInstance]!!.getSubImage(sheetX, sheetY).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat() // Interchar: pull punct right next to hangul to the left
+ if (i > 0 && isHangul(s[i - 1])) -3f
else 0f,
@@ -424,7 +461,7 @@ constructor() : Font {
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
else 0).toFloat(),
thisCol
scale.toFloat(), thisCol
)
}
catch (e: ArrayIndexOutOfBoundsException) {
@@ -454,6 +491,10 @@ constructor() : Font {
return SHEET_CYRILIC_EF
else if (isGreekEF(c))
return SHEET_GREEK_EF
else if (isRomanianEF(c))
return SHEET_EXTB_ROMANIAN_EF
else if (isThaiEF(c))
return SHEET_EXTA_EF // will use fourth glyph in EXTA_EF
else if (isRunic(c))
return SHEET_RUNIC
else if (isHangul(c))
@@ -476,6 +517,10 @@ constructor() : Font {
return SHEET_FW_UNI
else if (isGreek(c))
return SHEET_GREEK_EM
else if (isRomanian(c))
return SHEET_EXTB_ROMANIAN_EM
else if (isThai(c))
return SHEET_THAI_EM
else if (c.isColourCode())
return SHEET_COLOURCODE
else
@@ -506,19 +551,6 @@ constructor() : Font {
drawString(x + xoff, y, printedBody, color)
}
@Throws(SlickException::class)
open fun reloadUnihan() {
}
/**
* Set margin between characters
* @param margin
*/
fun setInterchar(margin: Int) {
interchar = margin
}
private fun setBlendModeMul() {
GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
@@ -550,6 +582,9 @@ constructor() : Font {
lateinit internal var wenQuanYi_2: SpriteSheet
lateinit internal var greekSheet: SpriteSheet
lateinit internal var greekSheetEF: SpriteSheet
lateinit internal var romanianSheet: SpriteSheet
lateinit internal var romanianSheetEF: SpriteSheet
lateinit internal var thaiSheet: SpriteSheet
internal val JUNG_COUNT = 21
internal val JONG_COUNT = 28
@@ -580,9 +615,13 @@ constructor() : Font {
internal val SHEET_WENQUANYI_2 = 14
internal val SHEET_GREEK_EM = 15
internal val SHEET_GREEK_EF = 16
internal val SHEET_EXTB_ROMANIAN_EM = 17
internal val SHEET_EXTB_ROMANIAN_EF = 18
internal val SHEET_THAI_EM = 19
internal val SHEET_THAI_EF = 20
internal val SHEET_COLOURCODE = 255
lateinit internal var sheetKey: Array<SpriteSheet>
lateinit internal var sheetKey: Array<SpriteSheet?>
internal val asciiEFList = arrayOf(' ', '!', '"', '\'', '(', ')', ',', '.', ':', ';', 'I', '[', ']', '`', 'f', 'i', 'j', 'l', 't', '{', '|', '}', 0xA1.toChar(), 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', '·')
internal val extAEFList = arrayOf(
0x12E.toChar(),
@@ -632,6 +671,11 @@ constructor() : Font {
internal val runicList = arrayOf('ᚠ', 'ᚢ', 'ᚦ', 'ᚬ', 'ᚱ', 'ᚴ', 'ᚼ', 'ᚾ', '', 'ᛅ', 'ᛋ', 'ᛏ', 'ᛒ', 'ᛘ', 'ᛚ', 'ᛦ', 'ᛂ', '', '᛫', '', 'ᛮ', 'ᛯ', 'ᛰ')
internal var interchar = 0
internal var scale = 1
set(value) {
if (value > 0) field = value
else throw IllegalArgumentException("Font scale cannot be zero or negative (input: $value)")
}
val colourKey = hashMapOf(
Pair(0x10.toChar(), Color(0xFFFFFF)), //*w hite

View File

@@ -50,6 +50,12 @@ constructor() : GameFontBase() {
"./res/graphics/fonts/greek_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.greekSheetEF = SpriteSheet(
"./res/graphics/fonts/greek_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.romanianSheet = SpriteSheet(
"./res/graphics/fonts/romana_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.romanianSheetEF = SpriteSheet(
"./res/graphics/fonts/romana_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.thaiSheet = SpriteSheet(
"./res/graphics/fonts/thai_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
val shk = arrayOf(
GameFontBase.asciiSheet,
@@ -60,7 +66,7 @@ constructor() : GameFontBase() {
GameFontBase.extASheetEF,
GameFontBase.kanaSheet,
GameFontBase.cjkPunct,
GameFontBase.asciiSheet, // Filler
null, // Filler
GameFontBase.cyrilic,
GameFontBase.cyrilicEF,
GameFontBase.fullwidthForms,
@@ -68,19 +74,12 @@ constructor() : GameFontBase() {
GameFontBase.wenQuanYi_1,
GameFontBase.wenQuanYi_2, // uniHan
GameFontBase.greekSheet,
GameFontBase.greekSheetEF
GameFontBase.greekSheetEF,
GameFontBase.romanianSheet,
GameFontBase.romanianSheetEF,
GameFontBase.thaiSheet,
null // Filler
)
GameFontBase.sheetKey = shk
}
@Throws(SlickException::class)
override fun reloadUnihan() {
/*uniHan = new SpriteSheet(
"./res/graphics/fonts/unifont_unihan"
+ ((!terrarum.gameLocale.contains("zh"))
? "_ja" : "")
+".png"
, W_UNIHAN, H_UNIHAN
);*/
}
}

View File

@@ -117,7 +117,7 @@ class StateMonitorCheck : BasicGameState() {
this, g
)
(1..10).forEach {
(1..12).forEach {
Typesetter.printCentered(
Lang["MENU_MONITOR_CALI_LABEL_$it"],
instructionY + it.minus(2).times(g.font.lineHeight),

View File

@@ -100,13 +100,13 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
return this
}
fun snapToPixel(): Hitbox {
/*fun snapToPixel(): Hitbox {
hitboxStart.x = Math.round(hitboxStart.x - HALF_PIXEL).toDouble()
hitboxStart.y = Math.round(hitboxStart.y - HALF_PIXEL).toDouble()
hitboxEnd.x = Math.round(hitboxEnd.x - HALF_PIXEL).toDouble()
hitboxEnd.y = Math.round(hitboxEnd.y - HALF_PIXEL).toDouble()
return this
}
}*/
/**
* Returns x value of start point

View File

@@ -28,10 +28,10 @@ class ConsoleWindow : UICanvas, UITypable {
private var commandHistory = HistoryArray<String>(COMMAND_HISTORY_MAX)
private val LINE_HEIGHT = 20
private val MESSAGES_DISPLAY_COUNT = 9
private val MESSAGES_DISPLAY_COUNT = 11
override var width: Int = Terrarum.WIDTH
override var height: Int = 200
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
override var openCloseTime: Int = 0