better interchar handling

This commit is contained in:
minjaesong
2024-05-23 14:04:42 +09:00
parent 033fcab9ec
commit 95dfcb91b5
2 changed files with 26 additions and 23 deletions

View File

@@ -1098,8 +1098,6 @@ class MovableType(
val input = this.filter { it.block.text.isNotGlue() }
if (input.isEmpty()) return out
// println("freezeIntoCodepointSequence ${input.joinToString { "${it.posX}..${it.getEndPos()}" }}")
// process line indents
if (input.first().posX > 0)
out.addAll(input.first().posX.glueSizeToGlueChars())
@@ -1117,6 +1115,24 @@ class MovableType(
return out
}
private fun List<Block>.getGlueSizeSum(font: TerrarumSansBitmap): Int {
var out = 0
val input = this.filter { it.block.text.isNotGlue() }
if (input.isEmpty()) return 0
// process blocks
input.forEachIndexed { index, it ->
val posX = it.posX
val prevEndPos = if (index == 0) 0 else input[index-1].getEndPos()
if (index > 0 && posX != prevEndPos) {
out += posX - prevEndPos
}
}
return out
}
data class NoTexGlyphLayout(val text: CodepointSequence, val width: Int) {
/**
* This function differs from `isNotGlue()` in a way that a word-block containing internal representations only
@@ -1140,24 +1156,6 @@ class MovableType(
return NoTexGlyphLayout(str, font.getWidthNormalised(str).div(font.scale))
}
private fun List<Block>.getGlueSizeSum(font: TerrarumSansBitmap): Int {
var out = 0
val input = this.filter { it.block.text.isNotGlue() }
if (input.isEmpty()) return 0
// process blocks
input.forEachIndexed { index, it ->
val posX = it.posX
val prevEndPos = if (index == 0) 0 else input[index-1].getEndPos()
if (index > 0 && posX != prevEndPos) {
out += posX - prevEndPos
}
}
return out
}
inline fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0
private fun List<Block>.getSlugEndPos(): Int {

View File

@@ -1181,14 +1181,17 @@ class TerrarumSansBitmap(
}
// is this glyph NOT a diacritic?
else if (thisProp.writeOnTop < 0) {
// apply interchar only if this character is NOT a control char
val thisInterchar = if (thisChar.isLetter() || Character.isWhitespace(thisChar)) interchar else 0
posXbuffer[charIndex] = -thisProp.nudgeX +
when (itsProp.alignWhere) {
GlyphProps.ALIGN_RIGHT ->
posXbuffer[nonDiacriticCounter] + W_VAR_INIT + alignmentOffset + interchar + kerning + extraWidth
posXbuffer[nonDiacriticCounter] + W_VAR_INIT + alignmentOffset + thisInterchar + kerning + extraWidth
GlyphProps.ALIGN_CENTRE ->
posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + interchar + kerning + extraWidth
posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + thisInterchar + kerning + extraWidth
else ->
posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar + kerning + extraWidth
posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + thisInterchar + kerning + extraWidth
}
posYbuffer[charIndex] = -thisProp.nudgeY
@@ -2766,6 +2769,8 @@ class TerrarumSansBitmap(
return 0xFFE20 + tone1 * 5 + tone2
}
// If this letter is a candidate to be influenced by the interchar property (i.e. is this character visible or whitespace and not a control character)
fun CodePoint.isLetter() = (Character.isLetterOrDigit(this) || Character.isWhitespace(this) || this in 0xF0000 until 0xFFF70)
private fun Int.toHex() = "U+${this.toString(16).padStart(4, '0').toUpperCase()}"