From 222bf0811cd6ed8cae486912c11093977179155a Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Sun, 17 Jul 2016 21:05:47 +0900 Subject: [PATCH] Romanian and Thai language support, GameFont: scaling Former-commit-id: 960bbc00b2d16111b5b63fc31a71a8093bae9dc1 Former-commit-id: 159beb538d151a6b332809ddfeb66ce1e02be52d --- res/books/polyglot_test.txt | 2 +- res/graphics/fonts/romana_ef.png | Bin 0 -> 134 bytes res/graphics/fonts/romana_majuscule.png | Bin 0 -> 197 bytes res/graphics/fonts/thai_fullwidth.png | Bin 0 -> 1941 bytes res/locales/en/configurator.json | 4 +- res/locales/frFR/configurator.json | 15 +++ res/locales/jaJP/configurator.json | 4 +- res/locales/koKR/configurator.json | 4 +- src/net/torvald/imagefont/GameFontBase.kt | 102 +++++++++++++----- src/net/torvald/imagefont/GameFontWhite.kt | 25 +++-- src/net/torvald/terrarum/StateMonitorCheck.kt | 2 +- src/net/torvald/terrarum/gameactors/Hitbox.kt | 4 +- src/net/torvald/terrarum/ui/ConsoleWindow.kt | 4 +- 13 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 res/graphics/fonts/romana_ef.png create mode 100644 res/graphics/fonts/romana_majuscule.png create mode 100644 res/graphics/fonts/thai_fullwidth.png create mode 100644 res/locales/frFR/configurator.json diff --git a/res/books/polyglot_test.txt b/res/books/polyglot_test.txt index 24b0742cc..6d13ed242 100644 --- a/res/books/polyglot_test.txt +++ b/res/books/polyglot_test.txt @@ -26,6 +26,6 @@ Og som krystaller står en tanke ganske klar Ще спра да бъда аз на миналото в плен La den gå, la den gå, jeg skal stige lik solen nå -[thai language not supported] +ปล่อยออกมา เลิกซ่อนเร้น เด็กดี ไม่เห็นมีค่า Je suis là, comme je l'ai rêvé En de storm raast door! De vrieskou, daar zat ik toch al niet mee \ No newline at end of file diff --git a/res/graphics/fonts/romana_ef.png b/res/graphics/fonts/romana_ef.png new file mode 100644 index 0000000000000000000000000000000000000000..48c1735e7a2ec770e5353fdeb066b2303792f05d GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^tUxTn!3-petl3`zDb4_&5ZC|z|Cg7S1IeqG#LfT( znM;EFg8%<#xPFS)5y;i_ba4!+xYc?}k&l6a=g@&^|Lv;|p3!xlqo8_MdtHM|$$#%m eVeN>uvl!JbF-(`bxYQJ=iNVv=&t;ucLK6Uivn;j% literal 0 HcmV?d00001 diff --git a/res/graphics/fonts/romana_majuscule.png b/res/graphics/fonts/romana_majuscule.png new file mode 100644 index 0000000000000000000000000000000000000000..7cd48090b7f2252bb37605f447697183cd87f4ee GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^(m*W2!3-q5W43JqQk(%kA+G=b|1U2u2a;DWiJbuo zGM5DT1^@rgaQzgoBaoZn>EaktacgUzqtF2b9;So;?RRk&3d!C|w$wP;$8l}@za)l= zw_Yw0lfMpfV`+@dsb&roJjDgcMKcuWS6Snj5@;E~C5s@csb00io+_R3^*>$7fN}!z#p00i_>zopr04M26)c^nh literal 0 HcmV?d00001 diff --git a/res/graphics/fonts/thai_fullwidth.png b/res/graphics/fonts/thai_fullwidth.png new file mode 100644 index 0000000000000000000000000000000000000000..803ac7378c61bc76580440690a1bd5e82fe387c1 GIT binary patch literal 1941 zcmeAS@N?(olHy`uVBq!ia0vp^6M(pagBeI_^>?Q-FfcO&_=LFr|Np5UAIlM6jY+k7T)NLth>?wCh&?Dug&&oemAqPf?T$3n;K+XUT?N77S^g>DdccG zM&*|6OdUmzzzYtltvdqqSoB4e*j+gkEG-fmeKz$^(O+|I9nrb^iK`2SiG;~cK_V6i?mvLELL^Ba8QZnnP@Fr#$IcZ zz_9A*O0%0+y_A2PhSR(<0*>7t8Xfve>^y zSGKfl@aB6eJNXGy$hj`Y6*o#PXE{}AHS#S_ce#I z+?#b7%&{^ab{}u6&Aj@?*C9;4Rnagb_@kP_w2XNRbL<87zg)7e?B{2PZK+4Xng14h zobJ$P+Z4ji`uTKYQj#9akq+SnwyD!+Z#tQ#yzk@HxO2@lnhKxS`Tf(F5UX~_{*s~B zB+F-iL*_GI+Iu~aW9f`X`z2Szq`eg>uF>i|kuGksw*EN9$p^U?lt)Pe=AKM0HGOI(f_Cei+n+)kB0iX|Td0|-^T^gg=Z973 z=WknoYbto|;}EE~xH11w9x!&J8=stKJSijgo?{++)ECuvQ4Ea%f= 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 + lateinit internal var sheetKey: Array 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 diff --git a/src/net/torvald/imagefont/GameFontWhite.kt b/src/net/torvald/imagefont/GameFontWhite.kt index 622f3494c..d91f570d0 100644 --- a/src/net/torvald/imagefont/GameFontWhite.kt +++ b/src/net/torvald/imagefont/GameFontWhite.kt @@ -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 - );*/ - } } diff --git a/src/net/torvald/terrarum/StateMonitorCheck.kt b/src/net/torvald/terrarum/StateMonitorCheck.kt index 1be2ec2bf..0c3190e4a 100644 --- a/src/net/torvald/terrarum/StateMonitorCheck.kt +++ b/src/net/torvald/terrarum/StateMonitorCheck.kt @@ -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), diff --git a/src/net/torvald/terrarum/gameactors/Hitbox.kt b/src/net/torvald/terrarum/gameactors/Hitbox.kt index 1b748827b..327a3a877 100644 --- a/src/net/torvald/terrarum/gameactors/Hitbox.kt +++ b/src/net/torvald/terrarum/gameactors/Hitbox.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt index 32080648a..f9c514adb 100644 --- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt +++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt @@ -28,10 +28,10 @@ class ConsoleWindow : UICanvas, UITypable { private var commandHistory = HistoryArray(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