diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7057b47..b693b7f 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,7 +77,7 @@ Up&Down: SXXXXXXX SYYYYYYY 00000000 -Each X and Y numbers are Signed 8-Bit Integer. +Each X and Y numbers are TWO'S COMPLEMENT Signed 8-Bit Integer. X-positive: nudges towards left Y-positive: nudges towards down @@ -87,19 +87,22 @@ Y-positive: nudges towards down 4 Pixels are further divided as follows: | LSB | | Red | Green | Blue | -| ------------ | ------------ | ------------ | ------------ | ------------ | +| ------------ | ------------ | ------------ | ----------- | ------------ | | Y | Anchor point Y for: | undefined | undefined | undefined | | X | Anchor point X for: | undefined | undefined | undefined | -| Y | Anchor point Y for: | (unused) | (unused) | (unused) | +| Y | Anchor point Y for: | Type-0 | Type-1 | Type-2 | | X | Anchor point X for: | Type-0 | Type-1 | Type-2 | | **MSB** | | | | | - 1Y1Y1Y1Y 1Y2Y2Y2Y 1Y3Y3Y3Y - 1X1X1X1X 1X2X2X2X 1X3X3X3X + 1Y1Y1Y1Y 2Y2Y2Y2Y 3Y3Y3Y3Y + 1X1X1X1X 2X2X2X2X 3X3X3X3X where Red is first, Green is second, Blue is the third diacritics. -MSB for each word must be set so that the pixel would appear brighter on the image editor. -(the font program will only read low 7 bits for each RGB channel) + +Each X and Y numbers are SIGN AND MAGNITUDE 8-Bit Integer. + +X-positive: nudges towards left +Y-positive: nudges towards down #### Diacritics Type Bit Encoding diff --git a/demo.PNG b/demo.PNG index 6642950..1112225 100644 Binary files a/demo.PNG and b/demo.PNG differ diff --git a/demotext_unaligned.txt b/demotext_unaligned.txt index 7500d00..847ec9b 100755 --- a/demotext_unaligned.txt +++ b/demotext_unaligned.txt @@ -25,7 +25,7 @@ How multilingual? Real multilingual! 􏻬আমি কাঁচ খেতে পারি, তাতে আমার কোনো ক্ষতি হয় না। 􀀀 􏻬󿿁Под южно дърво, цъфтящо в синьо, бягаше малко пухкаво зайче󿿀􀀀 􏻬ᎠᏍᎦᏯᎡᎦᎢᎾᎨᎢᎣᏍᏓᎤᎩᏍᏗᎥᎴᏓᎯᎲᎢᏔᎵᏕᎦᏟᏗᏖᎸᎳᏗᏗᎧᎵᎢᏘᎴᎩ ᏙᏱᏗᏜᏫᏗᏣᏚᎦᏫᏛᏄᏓᎦᏝᏃᎠᎾᏗᎭᏞᎦᎯᎦᏘᏓᏠᎨᏏᏕᏡᎬᏢᏓᏥᏩᏝᎡᎢᎪᎢ ᎠᎦᏂᏗᎮᎢᎫᎩᎬᏩᎴᎢᎠᏆᏅᏛᎫᏊᎾᎥᎠᏁᏙᎲᏐᏈᎵᎤᎩᎸᏓᏭᎷᏤᎢᏏᏉᏯᏌᏊ ᎤᏂᏋᎢᏡᎬᎢᎰᏩᎬᏤᎵᏍᏗᏱᎩᎱᎱᎤᎩᎴᎢᏦᎢᎠᏂᏧᏣᏨᎦᏥᎪᎥᏌᏊᎤᎶᏒᎢᎢᏡᎬᎢ ᎹᎦᎺᎵᏥᎻᎼᏏᎽᏗᏩᏂᎦᏘᎾᎿᎠᏁᎬᎢᏅᎩᎾᏂᎡᎢᏌᎶᎵᏎᎷᎠᏑᏍᏗᏪᎩ ᎠᎴ ᏬᏗᏲᏭᎾᏓᏍᏓᏴᏁᎢᎤᎦᏅᏮᏰᎵᏳᏂᎨᎢ􀀀 -􏻬Ѳеѡфа́нъ и҆ Алеѯі́й, ѕѣлѡ̀ возлюби́вше ѱалти́рь, воспѣ́ша при свѣ́тѣ ѕвѣ́здъ, помазꙋ́юще сщ҃е́нное мѵ́ро; серафими мн̑оꙮчитїи̑, ꙗ҆́кѡ ѻ҆́гнь, ѡ҆крꙋжа́хꙋ прⷭ҇то́лъ Бж҃їй, и҆ всѧ̀ землѧ̀ и҆спо́лнисѧ свѣ́та, ꙗ҆́кѡ ѕмі́й попра́нъ є҆́сть􀀀 +􏻬Ѳеѡфа́нъ и҆ Алеѯі́й, ѕѣлѡ̀ возлюби́вше ѱалти́рь, воспѣ́ша при свѣ́тѣ ѕвѣ́здъ, помазꙋ́юще сщ҃е́нное мѵ́ро; серафими мн̑оꙮ҆читїи̑, ꙗ҆́кѡ ѻ҆́гнь, ѡ҆крꙋжа́хꙋ прⷭ҇то́лъ Бж҃їй, и҆ всѧ̀ землѧ̀ и҆спо́лнисѧ свѣ́та, ꙗ҆́кѡ ѕмі́й попра́нъ є҆́сть􀀀 􏻬Příliš žluťoučký kůň úpěl ďábelské ódy􀀀 􏻬Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon􀀀 􏻬PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS􀀀 @@ -105,7 +105,7 @@ How multilingual? Real multilingual! 􎳌‣ Full support for Archaic Kana/Hentaigana􀀀 -􏻬серафими мн̑оꙮчитїи̑, ꙗ҆́кѡ ѻ҆́гнь, ѡ҆крꙋжа́хꙋ прⷭ҇то́лъ Бж҃їй, и҆ всѧ̀ землѧ̀ и҆спо́лнисѧ свѣ́та􀀀 +􏻬серафими мн̑оꙮ҆читїи̑, ꙗ҆́кѡ ѻ҆́гнь, ѡ҆крꙋжа́хꙋ прⷭ҇то́лъ Бж҃їй, и҆ всѧ̀ землѧ̀ и҆спо́лнисѧ свѣ́та􀀀 􎳌‣ Fan of Church Slavonic? We’ve got you!􀀀 diff --git a/src/assets/cyrilic_extB_variable.tga b/src/assets/cyrilic_extB_variable.tga index 8d3709f..272c00e 100644 --- a/src/assets/cyrilic_extB_variable.tga +++ b/src/assets/cyrilic_extB_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af0590cae6d254a9ce5b2204e8d6596c57baa4b4760a6acd3d8e9a452348ca1f +oid sha256:d7225a398847b776e1f0d523453bd3facffe5cc296ffec66d469e581c017c526 size 122898 diff --git a/src/assets/cyrilic_variable.tga b/src/assets/cyrilic_variable.tga index a46f6cf..52dc3e6 100755 --- a/src/assets/cyrilic_variable.tga +++ b/src/assets/cyrilic_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c47b422c1a73eaf2fbf429d64905e070cfea5129bde90df01adf1955ae373945 +oid sha256:3bb32f7aa804e303b47d80e404b2f19ca9fa590841efa3039df6a8548b9f2c9e size 389138 diff --git a/src/assets/internal_variable.tga b/src/assets/internal_variable.tga index 8e1deaf..5404a35 100644 --- a/src/assets/internal_variable.tga +++ b/src/assets/internal_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c068c1adeb1cc6a723c41861a8fd54a20f607de7b6434f495e163e1f1d0d5a1e +oid sha256:6994c4a1fc427fed6edbb42a75b6123ff004c1a7abd8487ba7375c6a4b79cd00 size 327698 diff --git a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt index f2f12ca..7514aeb 100755 --- a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt +++ b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt @@ -5,7 +5,9 @@ import net.torvald.terrarumsansbitmap.gdx.CodePoint /** * Created by minjaesong on 2021-11-25. */ -data class DiacriticsAnchor(val type: Int, val x: Int, val y: Int, val xUsed: Boolean, val yUsed: Boolean) +data class DiacriticsAnchor(val type: Int, val x: Int, val y: Int) { + val isZero = (x == 0 && y == 0) +} /** * Created by minjaesong on 2018-08-07. */ @@ -17,7 +19,7 @@ data class GlyphProps( val nudgeX: Int = 0, val nudgeY: Int = 0, - val diacriticsAnchors: Array = Array(6) { DiacriticsAnchor(it, 0, 0, false, false) }, + val diacriticsAnchors: Array = Array(6) { DiacriticsAnchor(it, 0, 0) }, val alignWhere: Int = 0, // ALIGN_LEFT..ALIGN_BEFORE @@ -99,10 +101,6 @@ data class GlyphProps( diacriticsAnchors.forEach { hash = hash xor it.type hash = hash * 16777619 - hash = hash xor (it.x or (if (it.xUsed) 128 else 0)) - hash = hash * 16777619 - hash = hash xor (it.y or (if (it.yUsed) 128 else 0)) - hash = hash * 16777619 } hash = hash xor tags diff --git a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt index 79afc5b..4f1d15e 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt @@ -947,12 +947,12 @@ class TerrarumSansBitmap( val shift = (3 - (it % 3)) * 8 val yPixel = pixmap.getPixel(codeStartX, codeStartY + yPos).tagify() val xPixel = pixmap.getPixel(codeStartX, codeStartY + yPos + 1).tagify() - val yUsed = (yPixel ushr shift) and 128 != 0 - val xUsed = (xPixel ushr shift) and 128 != 0 - val y = if (yUsed) (yPixel ushr shift) and 127 else 0 - val x = if (xUsed) (xPixel ushr shift) and 127 else 0 + val ySgn = ((yPixel ushr shift) and 128).let { if (it == 0) -1 else 1 } + val xSgn = ((xPixel ushr shift) and 128).let { if (it == 0) -1 else 1 } + val y = ((yPixel ushr shift) and 127) * ySgn + val x = ((xPixel ushr shift) and 127) * xSgn - DiacriticsAnchor(it, x, y, xUsed, yUsed) + DiacriticsAnchor(it, x, y) }.toTypedArray() val alignWhere = (0..1).fold(0) { acc, y -> acc or ((pixmap.getPixel(codeStartX, codeStartY + y + 15).and(255) != 0).toInt() shl y) } @@ -1020,17 +1020,6 @@ class TerrarumSansBitmap( (0xD800..0xDFFF).forEach { glyphProps[it] = GlyphProps(0) } (0x100000..0x10FFFF).forEach { glyphProps[it] = GlyphProps(0) } (0xFFFA0..0xFFFFF).forEach { glyphProps[it] = GlyphProps(0) } - - - // manually add width of one orphan insular letter - // WARNING: glyphs in 0xA770..0xA778 has invalid data, further care is required - glyphProps[0x1D79] = GlyphProps(9) - - - // U+007F is DEL originally, but this font stores bitmap of Replacement Character (U+FFFD) - // to this position. String replacer will replace U+FFFD into U+007F. - glyphProps[0x7F] = GlyphProps(15) - } private fun Int.halveWidth() = this / 2 + 1 @@ -1224,30 +1213,32 @@ class TerrarumSansBitmap( // set X pos according to alignment information posXbuffer[charIndex] = -thisProp.nudgeX + when (thisProp.alignWhere) { - GlyphProps.ALIGN_LEFT, GlyphProps.ALIGN_BEFORE -> posXbuffer[nonDiacriticCounter] + GlyphProps.ALIGN_LEFT, GlyphProps.ALIGN_BEFORE -> { + val anchorPointX = if (itsProp.diacriticsAnchors[diacriticsType].isZero) itsProp.width else itsProp.diacriticsAnchors[diacriticsType].x + + posXbuffer[nonDiacriticCounter] + anchorPointX + } GlyphProps.ALIGN_RIGHT -> { // println("thisprop alignright $kerning, $extraWidth") - val anchorPoint = - if (!itsProp.diacriticsAnchors[diacriticsType].xUsed) itsProp.width else itsProp.diacriticsAnchors[diacriticsType].x + val anchorPointX = if (itsProp.diacriticsAnchors[diacriticsType].isZero) itsProp.width else itsProp.diacriticsAnchors[diacriticsType].x extraWidth += thisProp.width - posXbuffer[nonDiacriticCounter] + anchorPoint - W_VAR_INIT + kerning + extraWidth + posXbuffer[nonDiacriticCounter] + anchorPointX - W_VAR_INIT + kerning + extraWidth } GlyphProps.ALIGN_CENTRE -> { - val anchorPoint = - if (!itsProp.diacriticsAnchors[diacriticsType].xUsed) itsProp.width.div(2) else itsProp.diacriticsAnchors[diacriticsType].x + val anchorPointX = if (itsProp.diacriticsAnchors[diacriticsType].isZero) itsProp.width.div(2) else itsProp.diacriticsAnchors[diacriticsType].x if (itsProp.alignWhere == GlyphProps.ALIGN_RIGHT) { if (thisChar in 0x900..0x902) - posXbuffer[nonDiacriticCounter] + anchorPoint + (itsProp.width - 1).div(2) + posXbuffer[nonDiacriticCounter] + anchorPointX + (itsProp.width - 1).div(2) else - posXbuffer[nonDiacriticCounter] + anchorPoint + (itsProp.width + 1).div(2) + posXbuffer[nonDiacriticCounter] + anchorPointX + (itsProp.width + 1).div(2) } else { if (thisChar in 0x900..0x902) - posXbuffer[nonDiacriticCounter] + anchorPoint - (W_VAR_INIT + 1) / 2 + posXbuffer[nonDiacriticCounter] + anchorPointX - (W_VAR_INIT + 1) / 2 else - posXbuffer[nonDiacriticCounter] + anchorPoint - HALF_VAR_INIT + posXbuffer[nonDiacriticCounter] + anchorPointX - HALF_VAR_INIT } } else -> throw InternalError("Unsupported alignment: ${thisProp.alignWhere}") @@ -1326,6 +1317,9 @@ class TerrarumSansBitmap( // for BEFORE_N_AFTER, do nothing in here } + // nudge Y pos according to anchor position + posYbuffer[charIndex] -= itsProp.diacriticsAnchors[diacriticsType].y + // Don't reset extraWidth here! } } @@ -1335,7 +1329,7 @@ class TerrarumSansBitmap( if (str.isNotEmpty()) { val lastCharProp = glyphProps[str.last()] val penultCharProp = glyphProps[str[nonDiacriticCounter]] ?: - (if (errorOnUnknownChar) throw throw InternalError("No GlyphProps for char '${str[nonDiacriticCounter]}' " + + (if (errorOnUnknownChar) throw InternalError("No GlyphProps for char '${str[nonDiacriticCounter]}' " + "(${str[nonDiacriticCounter].charInfo()})") else nullProp) posXbuffer[posXbuffer.lastIndex] = posXbuffer[posXbuffer.lastIndex - 1] + // DON'T add 1 to house the shadow, it totally breaks stuffs if (lastCharProp != null && lastCharProp.writeOnTop >= 0) { @@ -2681,6 +2675,7 @@ class TerrarumSansBitmap( "symbols_for_legacy_computing_variable.tga", "cyrilic_extB_variable.tga", "cyrilic_extA_variable.tga", + "cyrilic_extC_variable.tga", ) internal val codeRange = arrayOf( // MUST BE MATCHING WITH SHEET INDICES!! 0..0xFF, // SHEET_ASCII_VARW diff --git a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt index 5733671..4207850 100644 --- a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt +++ b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt @@ -229,16 +229,16 @@ class TerrarumTypewriterBitmap( val nudgeY = nudgingBits.ushr(16).toByte().toInt() // signed 8-bit int val diacriticsAnchors = (0..5).map { - val yPos = 11 + (it / 3) * 2 + val yPos = 13 - (it / 3) * 2 val shift = (3 - (it % 3)) * 8 val yPixel = pixmap.getPixel(codeStartX, codeStartY + yPos).tagify() val xPixel = pixmap.getPixel(codeStartX, codeStartY + yPos + 1).tagify() - val y = (yPixel ushr shift) and 127 - val x = (xPixel ushr shift) and 127 - val yUsed = (yPixel ushr shift) >= 128 - val xUsed = (yPixel ushr shift) >= 128 + val ySgn = ((yPixel ushr shift) and 128).let { if (it == 0) -1 else 1 } + val xSgn = ((xPixel ushr shift) and 128).let { if (it == 0) -1 else 1 } + val y = ((yPixel ushr shift) and 127) * ySgn + val x = ((xPixel ushr shift) and 127) * xSgn - DiacriticsAnchor(it, x, y, xUsed, yUsed) + DiacriticsAnchor(it, x, y) }.toTypedArray() val alignWhere = (0..1).fold(0) { acc, y -> acc or ((pixmap.getPixel(codeStartX, codeStartY + y + 15).and(255) != 0).toInt() shl y) } diff --git a/work_files/cyrilic_extB_variable.kra b/work_files/cyrilic_extB_variable.kra index 4c45d08..5ff8f7b 100644 --- a/work_files/cyrilic_extB_variable.kra +++ b/work_files/cyrilic_extB_variable.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:50160968f842996eb9e2fc1fea81a940a24b0e214717c56d03c2fce237caf5d3 -size 60549 +oid sha256:0c3babee73cffb9855763f1ed67e61551dcb16cb2b3838e3ba0fd9f24eaf8db6 +size 60530 diff --git a/work_files/cyrilic_variable.psd b/work_files/cyrilic_variable.psd index e266e20..295d141 100644 --- a/work_files/cyrilic_variable.psd +++ b/work_files/cyrilic_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58341e9621efad84fb8e113fe18f86265055e7fd37c3d090d90ec6695052c0a9 -size 419355 +oid sha256:27816ecaa578601b48c04ec386180f641b6f421e2160e97cd01d2721cbc81858 +size 419428 diff --git a/work_files/internal_variable.psd b/work_files/internal_variable.psd index eb5aa92..6f69fbc 100644 --- a/work_files/internal_variable.psd +++ b/work_files/internal_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:95f7b08c3bf6311faf621cde6ba2757737589470460483779a65ffa6a77f360c -size 284761 +oid sha256:2fe1940b2a659e1504d221bb9c52b8f07885a6b91e12c266a410a37b660e2cb0 +size 284777