Devanagari BETA; broke Thai diacritics again

This commit is contained in:
minjaesong
2018-08-10 01:29:58 +09:00
parent 4a36d3e7f1
commit a0e2cbf756
12 changed files with 196 additions and 184 deletions

View File

@@ -9,7 +9,8 @@ data class GlyphProps(
val alignWhere: Int,
val alignXPos: Int,
val rtl: Boolean = false,
val diacriticsStackDown: Boolean = false
val diacriticsStackDown: Boolean = false,
val diacriticsBeforeGlyph: Boolean = false
) {
companion object {
const val LEFT = 0
@@ -23,6 +24,7 @@ data class GlyphProps(
tags.ushr(5).and(3),
tags.ushr(1).and(15),
tags.and(1) == 1,
tags.ushr(8).and(1) == 1
tags.ushr(8).and(1) == 1,
tags.ushr(9).and(1) == 1
)
}

View File

@@ -455,25 +455,29 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
Character.toChars(thisChar).forEach { errorGlyphSB.append(it) }
throw InternalError("No GlyphProps for char '$errorGlyphSB' " +
"(U+${thisChar.toString(16).toUpperCase()}: ${Character.getName(thisChar)})")
"(${thisChar.charInfo()})")
}
val thisProp = glyphProps[thisChar] ?: nullProp
val lastNonDiacriticChar = textBuffer[nonDiacriticCounter]
val itsProp = glyphProps[lastNonDiacriticChar] ?: nullProp
//println("char: $thisChar; properties: $thisProp")
//println("char: ${thisChar.charInfo()}\nproperties: $thisProp")
val alignmentOffset = when (thisProp.alignWhere) {
GlyphProps.LEFT -> 0
GlyphProps.RIGHT -> thisProp.width - W_VAR_INIT
GlyphProps.CENTRE -> Math.floor((thisProp.width - W_VAR_INIT) / 2.0).toInt()
else -> throw InternalError("Unsupported alignment: ${thisProp.alignWhere}")
else -> throw InternalError("Unsupported alignment: ${thisProp.alignWhere} for '$thisChar' (${thisChar.charInfo()})")
}
if (!thisProp.writeOnTop) {
posXbuffer[charIndex] = posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar
posXbuffer[charIndex] =
if (itsProp.alignWhere == GlyphProps.RIGHT)
posXbuffer[nonDiacriticCounter] + W_VAR_INIT + alignmentOffset + interchar
else
posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar
nonDiacriticCounter = charIndex
stackUpwardCounter = 0
stackDownwardCounter = 0
@@ -506,13 +510,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
}
}
}
//print("[TerrarumSansBitmap] widthTable for $textBuffer: ")
//posXbuffer.forEach { print("$it ") }; println()
}
//print("[TerrarumSansBitmap] widthTable for $textBuffer: ")
//posXbuffer.forEach { print("$it ") }; println()
originalColour = batch.color.cpy()
var mainCol = originalColour
var shadowCol = mainCol.cpy().mul(0.5f,0.5f,0.5f,1f)
@@ -612,6 +615,8 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
return null
}
private fun Int.charInfo() = "U+${this.toString(16).padStart(4, '0').toUpperCase()}: ${Character.getName(this)}"
override fun dispose() {
super.dispose()
@@ -815,7 +820,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
val codeStartX = cellX + binaryCodeOffset
val codeStartY = cellY
val tagStartY = codeStartY + 11
val tagStartY = codeStartY + 10
var width = 0
var tags = 0
@@ -827,7 +832,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
}
}
for (y in 0..8) {
for (y in 0..9) {
// if ALPHA is not zero, assume it's 1
if (pixmap.getPixel(codeStartX, tagStartY + y).and(0xFF) != 0) {
tags = tags or (1 shl y)
@@ -874,7 +879,9 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
}
/** UTF-16 to ArrayList of Int. UTF-16 is because of Java */
/** UTF-16 to ArrayList of Int. UTF-16 is because of Java
* Note: CharSequence IS a String. java.lang.String implements CharSequence.
*/
private fun CharSequence.toCodePoints(): CodepointSequence {
val seq = ArrayList<Int>()
@@ -902,40 +909,24 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
i++
}
return seq
}
/** As CharSequence is just an Interface, copy-pasting the code would be the fastest way */
private fun String.toCodePoints(): CodepointSequence {
val seq = ArrayList<Int>()
var i = 0
while (i < this.length) {
val c = this[i]
if (i < this.lastIndex) {
if (c.isHighSurrogate()) {
val cNext = this[i + 1]
if (!cNext.isLowSurrogate())
throw IllegalArgumentException("Malformed UTF-16 String: High surrogate must be paired with low surrogate")
val H = c
val L = cNext
seq.add(Character.toCodePoint(H, L))
i++ // skip next char (guaranteed to be Low Surrogate)
}
}
else {
seq.add(c.toInt())
// swap position of {letter, diacritics that comes before the letter}
i = 1
while (i <= seq.lastIndex) {
if ((glyphProps[seq[i]] ?: nullProp).diacriticsBeforeGlyph) {
val t = seq[i - 1]
seq[i - 1] = seq[i]
seq[i] = t
}
i++
}
return seq
}
/** High surrogate comes before the low. */
private fun Char.isHighSurrogate() = (this.toInt() in 0xD800..0xDBFF)
/** CodePoint = 0x10000 + (H - 0xD800) * 0x400 + (L - 0xDC00) */