diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e76ee98..cf35ae2 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,12 +49,12 @@ Rightmost vertical column (should be 20 px tall) contains the tags. Tags are def m --Is this character lowheight? K -, K |= Tags used by the "Keming Machine" - K | - K -' ,- Nudging Bits (see below) - n --' - X -, - X |= Diacritics Anchor Points (see below) + K -' + Q ---Compiler Directive (see below) + n --, + X -, `-Nudging Bits (see below) X | + X |= Diacritics Anchor Points (see below) X -' A -,_ 0 Align 1 Align 0 Align 1 Align before A -' 0 left 0 right 1 centre 1 the glyph @@ -93,6 +93,20 @@ MSB for each word must be set so that the pixel would appear brighter on the ima Right now, only the type-0 diacritics and its anchor point is used by the font. +* Compiler Directives: + + [Opcode] [arg1] [arg2] + +Currently supported opcodes: + + - 00000000: No-operation; does not use the Compiler Directive system. + + - 10000xxx: Replace a character with xxx subchars (yes, number 0 can be used). + Replacement characters are encoded vertically from X-zero, bit by bit + (colour of the pixel doesn't matter) with LSB sitting on Y-zero. + + + -= NOTE =- The code has remnants of one old HACK: using 0th diacritics' X-anchor pos as a type selector @@ -102,7 +116,6 @@ Interpretation: DIA_OVERLAY = 1 DIA_JOINER = 2 - ``` #### Stack Up/Down diff --git a/assets/devanagari_bengali_variable.tga b/assets/devanagari_bengali_variable.tga index 083b632..98b89a2 100755 Binary files a/assets/devanagari_bengali_variable.tga and b/assets/devanagari_bengali_variable.tga differ diff --git a/assets/latinExtA_variable.tga b/assets/latinExtA_variable.tga index fc54ad8..1a6eaee 100755 --- a/assets/latinExtA_variable.tga +++ b/assets/latinExtA_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7d8457b67ae813c4a77a173023927f2aeb923afb0cf74d2c5a83a282c86217c2 +oid sha256:278c6cf9e08d896653db77bbd78dcfb2cc132a13637f882548ddca148aee64f3 size 163858 diff --git a/assets/latinExtB_variable.tga b/assets/latinExtB_variable.tga index 015b614..3de01b0 100755 --- a/assets/latinExtB_variable.tga +++ b/assets/latinExtB_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f433c74fe7cacdf01df12c4bd18991bfef4128b7b882c34f864b2464d3c705a +oid sha256:587aa0491704f6bffb0cf741d4fd18aad8c1929d3b559a7bd738de5b65f541f9 size 266258 diff --git a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt index 7ce8e74..14ce5cc 100755 --- a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt +++ b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt @@ -23,12 +23,16 @@ data class GlyphProps( val stackWhere: Int = 0, // STACK_UP..STACK_UP_N_DOWN - val extInfo: IntArray = DEFAULT_EXTINFO, + val extInfo: IntArray = IntArray(15), val hasKernData: Boolean = false, val isKernYtype: Boolean = false, val kerningMask: Int = 255, + val directiveOpcode: Int = 0, // 8-bits wide + val directiveArg1: Int = 0, // 8-bits wide + val directiveArg2: Int = 0, // 8-bits wide + val rtl: Boolean = false, ) { companion object { @@ -46,8 +50,6 @@ data class GlyphProps( const val DIA_JOINER = 2 private fun Boolean.toInt() = if (this) 1 else 0 - - val DEFAULT_EXTINFO = IntArray(15) } /*constructor(width: Int, tags: Int) : this( @@ -109,5 +111,18 @@ data class GlyphProps( return other is GlyphProps && this.hashCode() == other.hashCode() } - fun requiredExtInfoCount() = if (stackWhere == STACK_BEFORE_N_AFTER) 2 else 0 + fun requiredExtInfoCount() = + if (stackWhere == STACK_BEFORE_N_AFTER) + 2 + else if (directiveOpcode in 0b10000_000..0b10000_111) + directiveOpcode and 7 + else 0 + + fun isPragma(pragma: String) = when (pragma) { + "replacewith" -> directiveOpcode in 0b10000_000..0b10000_111 + else -> false + } + + fun forEachExtInfo(action: (Int) -> Unit) = extInfo.slice(0 until requiredExtInfoCount()).forEach(action) + fun forEachExtInfoIndexed(action: (Int, Int) -> Unit) = extInfo.slice(0 until requiredExtInfoCount()).forEachIndexed(action) } \ No newline at end of file diff --git a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt index 84f9ece..0d79da8 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt @@ -702,6 +702,7 @@ class TerrarumSansBitmap( } private fun Boolean.toInt() = if (this) 1 else 0 + /** @return THIRTY-TWO bit number: this includes alpha channel value; or 0 if alpha is zero */ private fun Int.tagify() = if (this and 255 == 0) 0 else this private fun buildWidthTable(pixmap: Pixmap, codeRange: Iterable, cols: Int = 16) { @@ -725,7 +726,6 @@ class TerrarumSansBitmap( val kerningBit1 = pixmap.getPixel(codeStartX, codeStartY + 6).tagify() val kerningBit2 = pixmap.getPixel(codeStartX, codeStartY + 7).tagify() val kerningBit3 = pixmap.getPixel(codeStartX, codeStartY + 8).tagify() - val kerningBit4 = pixmap.getPixel(codeStartX, codeStartY + 9).tagify() var isKernYtype = ((kerningBit1 and 0x80000000.toInt()) != 0) var kerningMask = kerningBit1.ushr(8).and(0xFFFFFF) val hasKernData = kerningBit1 and 255 != 0//(kerningBit1 and 255 != 0 && kerningMask != 0xFFFF) @@ -734,6 +734,12 @@ class TerrarumSansBitmap( kerningMask = 255 } + val compilerDirectives = pixmap.getPixel(codeStartX, codeStartY + 9).tagify() + val directiveOpcode = compilerDirectives.ushr(24).and(255) + val directiveArg1 = compilerDirectives.ushr(16).and(255) + val directiveArg2 = compilerDirectives.ushr(8).and(255) + + val nudgingBits = pixmap.getPixel(codeStartX, codeStartY + 10).tagify() val nudgeX = nudgingBits.ushr(24).toByte().toInt() // signed 8-bit int val nudgeY = nudgingBits.ushr(16).toByte().toInt() // signed 8-bit int @@ -762,7 +768,7 @@ class TerrarumSansBitmap( val stackWhere = (0..1).fold(0) { acc, y -> acc or ((pixmap.getPixel(codeStartX, codeStartY + y + 18).and(255) != 0).toInt() shl y) } - glyphProps[code] = GlyphProps(width, isLowHeight, nudgeX, nudgeY, diacriticsAnchors, alignWhere, writeOnTop, stackWhere, GlyphProps.DEFAULT_EXTINFO, hasKernData, isKernYtype, kerningMask) + glyphProps[code] = GlyphProps(width, isLowHeight, nudgeX, nudgeY, diacriticsAnchors, alignWhere, writeOnTop, stackWhere, IntArray(15), hasKernData, isKernYtype, kerningMask, directiveOpcode, directiveArg1, directiveArg2) // if (nudgingBits != 0) dbgprn("${code.charInfo()} nudgeX=$nudgeX, nudgeY=$nudgeY, nudgingBits=0x${nudgingBits.toString(16)}") // if (writeOnTop >= 0) dbgprn("WriteOnTop: ${code.charInfo()} (Type-${writeOnTop})") @@ -770,6 +776,7 @@ class TerrarumSansBitmap( // extra info val extCount = glyphProps[code]?.requiredExtInfoCount() ?: 0 if (extCount > 0) { + for (x in 0 until extCount) { var info = 0 for (y in 0..18) { @@ -781,6 +788,9 @@ class TerrarumSansBitmap( glyphProps[code]!!.extInfo[x] = info } + +// println("[TerrarumSansBitmap] char with $extCount extra info: ${code.charInfo()}; opcode: ${directiveOpcode.toString(16)}") +// println("contents: ${glyphProps[code]!!.extInfo.map { it.toString(16) }.joinToString()}") } } @@ -1102,18 +1112,22 @@ class TerrarumSansBitmap( else if (diacriticDotRemoval.containsKey(c) && (glyphProps[cNext]?.writeOnTop ?: -1) >= 0 && glyphProps[cNext]?.stackWhere == GlyphProps.STACK_UP) { seq.add(diacriticDotRemoval[c]!!) } - // rearrange {letter, before-and-after diacritics} as {letter, before-diacritics, after-diacritics} - // {letter, before-diacritics} part will be dealt with swapping code below - // DOES NOT WORK if said diacritics has codepoint > 0xFFFF - else if (i < this.lastIndex && this[i + 1] <= 0xFFFF && - glyphProps[this[i + 1]]?.stackWhere == GlyphProps.STACK_BEFORE_N_AFTER) { + // rearrange {letter, before-and-after diacritics} as {before-diacritics, letter, after-diacritics} + else if (i < this.lastIndex && glyphProps[this[i + 1]]?.stackWhere == GlyphProps.STACK_BEFORE_N_AFTER) { val diacriticsProp = glyphProps[this[i + 1]]!! + seq.add(diacriticsProp.extInfo[0]) seq.add(c) - seq.add(diacriticsProp.extInfo!![0]) - seq.add(diacriticsProp.extInfo!![1]) + seq.add(diacriticsProp.extInfo[1]) i++ } + else if (glyphProps[c]?.isPragma("replacewith") == true) { +// println("[TerrarumSansBitmap] replacing ${c.toString(16)} with:") + glyphProps[c]!!.forEachExtInfo { +// println("${it.charInfo()}") + seq.add(it) + } + } // U+007F is DEL originally, but this font stores bitmap of Replacement Character (U+FFFD) // to this position. This line will replace U+FFFD into U+007F. else if (c == 0xFFFD) { @@ -1390,7 +1404,7 @@ class TerrarumSansBitmap( if (it.first.matches(maskL!!) && it.second.matches(maskR!!)) { val contraction = if (glyphProps[prevChar]?.isKernYtype == true || glyphProps[thisChar]?.isKernYtype == true) it.yy else it.bb -// dbgprn("Kerning rule match #${index+1}: ${prevChar.toChar()}${thisChar.toChar()}, Rule:${it.first.s} ${it.second.s}; Contraction: $contraction") + dbgprn("Kerning rule match #${index+1}: ${prevChar.toChar()}${thisChar.toChar()}, Rule:${it.first.s} ${it.second.s}; Contraction: $contraction") return -contraction } diff --git a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt index 0a2e8d0..3690a1a 100644 --- a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt +++ b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt @@ -252,7 +252,7 @@ class TerrarumTypewriterBitmap( val stackWhere = (0..1).fold(0) { acc, y -> acc or ((pixmap.getPixel(codeStartX, codeStartY + y + 18).and(255) != 0).toInt() shl y) } - glyphProps[code] = GlyphProps(width, isLowHeight, nudgeX, nudgeY, diacriticsAnchors, alignWhere, writeOnTop, stackWhere, GlyphProps.DEFAULT_EXTINFO, hasKernData, isKernYtype, kerningMask) + glyphProps[code] = GlyphProps(width, isLowHeight, nudgeX, nudgeY, diacriticsAnchors, alignWhere, writeOnTop, stackWhere, IntArray(15), hasKernData, isKernYtype, kerningMask) // if (nudgingBits != 0) println("${code.charInfo()} nudgeX=$nudgeX, nudgeY=$nudgeY, nudgingBits=0x${nudgingBits.toString(16)}") diff --git a/testing.PNG b/testing.PNG index edbaa2c..44c2e2f 100755 Binary files a/testing.PNG and b/testing.PNG differ diff --git a/testtext.txt b/testtext.txt index ec527a2..5045b72 100755 --- a/testtext.txt +++ b/testtext.txt @@ -1,22 +1,9 @@ -To -uu -Td -mm -Ye -Yd +ถูกตำรว +ถูกตรว +aำ +แป้นพิมพ์เกษมณี แป้นพิมพ์ปัตตะโชติ +คำเตือน-อนามัยและความปลอดภัย -/œ̃/ -/ɛ̃/ -ẽ -Ẽ -/ẽ -o̸ -O̸ -when the line ends with a diacritics, whole letter wont render -if the line starts with a letter-with-diacritic, it will error out - -Lyklaborð -https://www.java.com/cov/en/download -/a /c /d /e /g /i /j /m /n /o /p /q /r /s /u /v v/ /w /x /y /z -germyndurinnkvikkalkul +UIJTuijt +দৌ ষৌ \ No newline at end of file diff --git a/work_files/devanagari_bengali_variable.psd b/work_files/devanagari_bengali_variable.psd index bdb5d78..fd1618b 100644 Binary files a/work_files/devanagari_bengali_variable.psd and b/work_files/devanagari_bengali_variable.psd differ diff --git a/work_files/latinExtA_variable.psd b/work_files/latinExtA_variable.psd index 4bd36f2..bbffb3b 100644 --- a/work_files/latinExtA_variable.psd +++ b/work_files/latinExtA_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d449898a51dba277923ba73659f8de76523712b3b966999d4e260dc7e7d50814 -size 234948 +oid sha256:7253b2b5bd0fc7b3aefa90fcff96f0b47bd53d83e5fcd228ea71a7acb73f8dd3 +size 234968 diff --git a/work_files/latinExtB_variable.psd b/work_files/latinExtB_variable.psd index 34e9923..dc5847b 100644 --- a/work_files/latinExtB_variable.psd +++ b/work_files/latinExtB_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:49df8df3f5aa65f5cb94f0140f5f7d7db8bc8259cdd0f4cd1fbab2a250492d8c -size 269395 +oid sha256:c21e8a231ee3cd4e3cc76a8f808b4c0c55f8c33ebe8a05c10fbd008908b61b23 +size 269567