mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-03-07 11:51:50 +09:00
better interchar handling
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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()}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user