From c05c4de192849296930dff96d63b88af4bc8c365 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Sun, 12 Feb 2017 04:12:26 +0900 Subject: [PATCH] new greek and more tweaks Former-commit-id: 0c480dd7ce173a37f2f48b5b5d711c2641cbda00 Former-commit-id: 18492d01862bdeecb9c0eba825a3b25da76211b0 --- src/net/torvald/imagefont/GameFontBase.kt | 136 +++++--------------- src/net/torvald/imagefont/GameFontWhite.kt | 12 +- src/net/torvald/terrarum/StateFontTester.kt | 12 +- 3 files changed, 44 insertions(+), 116 deletions(-) diff --git a/src/net/torvald/imagefont/GameFontBase.kt b/src/net/torvald/imagefont/GameFontBase.kt index 0ddbe9714..5e92b1ee1 100644 --- a/src/net/torvald/imagefont/GameFontBase.kt +++ b/src/net/torvald/imagefont/GameFontBase.kt @@ -112,9 +112,6 @@ open class GameFontBase : Font { private fun greekIndexX(c: Char) = (c.toInt() - 0x370) % 16 private fun greekIndexY(c: Char) = (c.toInt() - 0x370) / 16 - 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 @@ -128,7 +125,6 @@ open class GameFontBase : Font { private fun keycapIndexY(c: Char) = (c.toInt() - 0xE000) / 16 private val narrowWidthSheets = arrayOf( - SHEET_GREEK_EF, SHEET_EXTB_ROMANIAN_EF ) private val unihanWidthSheets = arrayOf( @@ -140,6 +136,12 @@ open class GameFontBase : Font { private val zeroWidthSheets = arrayOf( SHEET_COLOURCODE ) + private val variableWidthSheets = arrayOf( + SHEET_ASCII_VARW, + SHEET_CYRILIC_VARW, + SHEET_EXTA_VARW, + SHEET_GREEK_VARW + ) override fun getWidth(s: String) = getWidthSubstr(s, s.length) @@ -150,14 +152,17 @@ open class GameFontBase : Font { val chr = s[i] val ctype = getSheetType(s[i]) - if (chr.toInt() == 0x21B) // HAX! + if (chr.toInt() == 0x21B) // Romanian t; HAX! len += 6 - else if ( - ctype == SHEET_ASCII_VARW || - ctype == SHEET_EXTA_VARW || - ctype == SHEET_CYRILIC_VARW - ) - len += asciiWidths[chr.toInt()]!! + else if (variableWidthSheets.contains(ctype)) { + try { + len += asciiWidths[chr.toInt()]!! + } + catch (e: kotlin.KotlinNullPointerException) { + println("KotlinNullPointerException on glyph number ${Integer.toHexString(chr.toInt()).toUpperCase()}") + System.exit(1) + } + } else if (zeroWidthSheets.contains(ctype)) len += 0 else if (narrowWidthSheets.contains(ctype)) @@ -271,12 +276,6 @@ open class GameFontBase : Font { if (isWenQuanYi1(ch)) { val glyphW = getWidth("" + ch) - /*wenQuanYi_1.renderInUse( - Math.round(x + getWidthSubstr(s, i + 1) - glyphW), - Math.round((H - H_UNIHAN) / 2 + y), - wenQuanYiIndexX(ch), - wenQuanYi1IndexY(ch) - )*/ wenQuanYi_1.getSubImage(wenQuanYiIndexX(ch), wenQuanYi1IndexY(ch)).drawWithShadow( Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(), Math.round((H - H_UNIHAN) / 2 + y).toFloat(), @@ -299,12 +298,6 @@ open class GameFontBase : Font { if (isWenQuanYi2(ch)) { val glyphW = getWidth("" + ch) - /*wenQuanYi_2.renderInUse( - Math.round(x + getWidthSubstr(s, i + 1) - glyphW), - Math.round((H - H_UNIHAN) / 2 + y), - wenQuanYiIndexX(ch), - wenQuanYi2IndexY(ch) - )*/ wenQuanYi_2.getSubImage(wenQuanYiIndexX(ch), wenQuanYi2IndexY(ch)).drawWithShadow( Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(), Math.round((H - H_UNIHAN) / 2 + y).toFloat(), @@ -365,14 +358,10 @@ open class GameFontBase : Font { sheetX = uniPunctIndexX(ch) sheetY = uniPunctIndexY(ch) } - SHEET_GREEK_EM -> { + SHEET_GREEK_VARW -> { sheetX = greekIndexX(ch) sheetY = greekIndexY(ch) } - SHEET_GREEK_EF -> { - sheetX = greekEFIndexX(ch) - sheetY = greekEFIndexY(ch) - } SHEET_EXTB_ROMANIAN_EM -> { sheetX = romanianIndexX(ch) sheetY = romanianIndexY(ch) @@ -428,9 +417,7 @@ open class GameFontBase : Font { private fun getSheetType(c: Char): Int { // EFs - if (isGreekEF(c)) - return SHEET_GREEK_EF - else if (isRomanianEF(c)) + if (isRomanianEF(c)) return SHEET_EXTB_ROMANIAN_EF else if (isThaiEF(c)) return SHEET_EXTA_VARW // will use fourth glyph in EXTA_EF @@ -455,7 +442,7 @@ open class GameFontBase : Font { else if (isFullwidthUni(c)) return SHEET_FW_UNI else if (isGreek(c)) - return SHEET_GREEK_EM + return SHEET_GREEK_VARW else if (isRomanian(c)) return SHEET_EXTB_ROMANIAN_EM else if (isThai(c)) @@ -504,19 +491,16 @@ open class GameFontBase : Font { fun Char.isColourCode() = colourKey.containsKey(this) - /** - * Assumes spritesheet to has 16x16 cells - */ - fun buildAsciiWidthTable() { + fun buildWidthTable(sheet: SpriteSheet, codeOffset: Int, codeRange: IntRange, rows: Int = 16) { val binaryCodeOffset = 15 - val cellW = asciiSheet.getSubImage(0, 0).width + 1 // should be 16 - val cellH = asciiSheet.getSubImage(0, 0).height + 1 // should be 20 + val cellW = sheet.getSubImage(0, 0).width + 1 // should be 16 + val cellH = sheet.getSubImage(0, 0).height + 1 // should be 20 // control chars - for (ccode in 0..255) { - val glyphX = ccode % 16 - val glyphY = ccode / 16 + for (ccode in codeRange) { + val glyphX = ccode % rows + val glyphY = ccode / rows val codeStartX = (glyphX * cellW) + binaryCodeOffset val codeStartY = (glyphY * cellH) @@ -524,64 +508,12 @@ open class GameFontBase : Font { var glyphWidth = 0 for (downCtr in 0..3) { // if alpha is not zero, assume it's 1 - if (asciiSheet.texture.getPixel(codeStartX, codeStartY + downCtr)[3] == 255) { + if (sheet.texture.getPixel(codeStartX, codeStartY + downCtr)[3] == 255) { glyphWidth = glyphWidth or (1 shl downCtr) } } - asciiWidths[ccode] = glyphWidth - } - } - - fun buildLatinExtAWidthTable() { - val binaryCodeOffset = 15 - - val cellW = extASheet.getSubImage(0, 0).width + 1 // should be 16 - val cellH = extASheet.getSubImage(0, 0).height + 1 // should be 20 - - // control chars - for (ccode in 0..127) { - val glyphX = ccode % 16 - val glyphY = ccode / 16 - - val codeStartX = (glyphX * cellW) + binaryCodeOffset - val codeStartY = (glyphY * cellH) - - var glyphWidth = 0 - for (downCtr in 0..3) { - // if alpha is not zero, assume it's 1 - if (extASheet.texture.getPixel(codeStartX, codeStartY + downCtr)[3] == 255) { - glyphWidth = glyphWidth or (1 shl downCtr) - } - } - - asciiWidths[0x100 + ccode] = glyphWidth - } - } - - fun buildCyrillicWidthTable() { - val binaryCodeOffset = 15 - - val cellW = cyrilic.getSubImage(0, 0).width + 1 // should be 16 - val cellH = cyrilic.getSubImage(0, 0).height + 1 // should be 20 - - // control chars - for (ccode in 0..0x5F) { - val glyphX = ccode % 16 - val glyphY = ccode / 16 - - val codeStartX = (glyphX * cellW) + binaryCodeOffset - val codeStartY = (glyphY * cellH) - - var glyphWidth = 0 - for (downCtr in 0..3) { - // if alpha is not zero, assume it's 1 - if (cyrilic.texture.getPixel(codeStartX, codeStartY + downCtr)[3] == 255) { - glyphWidth = glyphWidth or (1 shl downCtr) - } - } - - asciiWidths[0x400 + ccode] = glyphWidth + asciiWidths[codeOffset + ccode] = glyphWidth } } @@ -603,7 +535,6 @@ open class GameFontBase : Font { lateinit internal var wenQuanYi_1: SpriteSheet 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 @@ -638,13 +569,12 @@ open class GameFontBase : Font { internal val SHEET_UNI_PUNCT = 9 internal val SHEET_WENQUANYI_1 = 10 internal val SHEET_WENQUANYI_2 = 11 - internal val SHEET_GREEK_EM = 12 - internal val SHEET_GREEK_EF = 13 - internal val SHEET_EXTB_ROMANIAN_EM = 14 - internal val SHEET_EXTB_ROMANIAN_EF = 15 - internal val SHEET_THAI_EM = 16 - internal val SHEET_THAI_EF = 17 - internal val SHEET_KEYCAP = 18 + internal val SHEET_GREEK_VARW = 12 + internal val SHEET_EXTB_ROMANIAN_EM = 13 + internal val SHEET_EXTB_ROMANIAN_EF = 14 + internal val SHEET_THAI_EM = 15 + internal val SHEET_THAI_EF = 16 + internal val SHEET_KEYCAP = 17 internal val SHEET_UNKNOWN = 254 internal val SHEET_COLOURCODE = 255 diff --git a/src/net/torvald/imagefont/GameFontWhite.kt b/src/net/torvald/imagefont/GameFontWhite.kt index 3ccfca489..b8fff7c14 100644 --- a/src/net/torvald/imagefont/GameFontWhite.kt +++ b/src/net/torvald/imagefont/GameFontWhite.kt @@ -39,9 +39,7 @@ class GameFontWhite : GameFontBase() { GameFontBase.wenQuanYi_2 = SpriteSheet( "./assets/graphics/fonts/wenquanyi_11pt_part2.tga", 16, 18, 2) GameFontBase.greekSheet = SpriteSheet( - "./assets/graphics/fonts/greek_fullwidth.tga", GameFontBase.W_LATIN_WIDE, GameFontBase.H) - GameFontBase.greekSheetEF = SpriteSheet( - "./assets/graphics/fonts/greek_ef.tga", GameFontBase.W_LATIN_NARROW, GameFontBase.H) + "./assets/graphics/fonts/greek_variable.tga", 15, 19, 1) GameFontBase.romanianSheet = SpriteSheet( "./assets/graphics/fonts/romana_fullwidth.tga", GameFontBase.W_LATIN_WIDE, GameFontBase.H) GameFontBase.romanianSheetEF = SpriteSheet( @@ -65,7 +63,6 @@ class GameFontWhite : GameFontBase() { GameFontBase.wenQuanYi_1, GameFontBase.wenQuanYi_2, GameFontBase.greekSheet, - GameFontBase.greekSheetEF, GameFontBase.romanianSheet, GameFontBase.romanianSheetEF, GameFontBase.thaiSheet, @@ -75,8 +72,9 @@ class GameFontWhite : GameFontBase() { GameFontBase.sheetKey = shk - buildAsciiWidthTable() - buildLatinExtAWidthTable() - buildCyrillicWidthTable() + buildWidthTable(asciiSheet, 0, 0..0xFF) + buildWidthTable(extASheet, 0x100, 0..0x7F) + buildWidthTable(cyrilic, 0x400, 0..0x5F) + buildWidthTable(greekSheet, 0x370, 0..0x5F) } } diff --git a/src/net/torvald/terrarum/StateFontTester.kt b/src/net/torvald/terrarum/StateFontTester.kt index 5b7f6c824..7d70cb711 100644 --- a/src/net/torvald/terrarum/StateFontTester.kt +++ b/src/net/torvald/terrarum/StateFontTester.kt @@ -72,14 +72,14 @@ nopqrstuvwxyz val line = " **** TERRAN BASIC V0.5 **** " - g.drawString("ABCDEFGHIJKLM", 10f, 10f) - g.drawString("NOPQRSTÜVWXYZ", 10f, 30f) + g.drawString("ABCDEFGHIJKLMN", 10f, 10f) + g.drawString("OPQRSTÜVWXYZÆŒ", 10f, 30f) g.drawString("abcdefghijklmno", 160f, 10f) - g.drawString("pqrstuvwxyzߌ", 160f, 30f) + g.drawString("pqrstuvwxyzßæœ", 160f, 30f) g.drawString("1234567890", 320f, 10f) - g.drawString("minimum kerning keming Nannu Namu", 320f, 30f) + g.drawString("minimum kerning keming Narnu Namu", 320f, 30f) g.drawString("Syö salmiakkia perkele", 480f, 10f) @@ -97,9 +97,9 @@ nopqrstuvwxyz "britiske besiddelser, foreløbigt i 1957 og endeligt i 1963.", "", "διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα", + "ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ", "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.", "Příliš žluťoučký kůň úpěl ďábelské ódy. Árvíztűrő tükörfúrógép ", - "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis ", "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich", "Pijamalı hasta yağız şoföre çabucak güvendi. Kŕdeľ ďatľov učí koňa žrať kôru.", "Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi", @@ -113,7 +113,7 @@ nopqrstuvwxyz "mála sem einkenndust af því að opinberir aðilar virtu ekki stjórnarskrárvarin réttindi einstaklingsins.", "", "Also supports:", - "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다. 대한민국 머한민국 대구 머구 명작 띵작 유식 윾싀", + "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다. 대한민국 머한민국 (대구) {머구} 명작 띵작 유식 윾싀", "とりなくこゑす ゆめさませ みよあけわたる ひんかしを そらいろはえて おきつへに ほふねむれゐぬ もやのうち", "鳥啼く声す 夢覚ませ 見よ明け渡る 東を 空色栄えて 沖つ辺に 帆船群れゐぬ 靄の中 (using WenQuanYi)", ""