better interchar handling for MovableType

This commit is contained in:
minjaesong
2024-05-23 14:26:22 +09:00
parent 95dfcb91b5
commit 2a15785f57
2 changed files with 6 additions and 4 deletions

View File

@@ -89,7 +89,7 @@ class MovableType(
// println("Paper width: $paperWidth") // println("Paper width: $paperWidth")
val lines = inputText.tokenise() val lines = inputText.tokenise(font)
// lines.debugprint() // lines.debugprint()
lines.forEachIndexed { linenum, it -> lines.forEachIndexed { linenum, it ->
@@ -592,7 +592,7 @@ class MovableType(
* *
* Inner list (ArrayList) contains the boxes for the single line. * Inner list (ArrayList) contains the boxes for the single line.
*/ */
private fun CodepointSequence.tokenise(): List<ArrayList<CodepointSequence>> { private fun CodepointSequence.tokenise(font: TerrarumSansBitmap): List<ArrayList<CodepointSequence>> {
val lines = ArrayList<ArrayList<CodepointSequence>>() val lines = ArrayList<ArrayList<CodepointSequence>>()
var tokens = ArrayList<CodepointSequence>() var tokens = ArrayList<CodepointSequence>()
var boxBuffer = ArrayList<CodePoint>() var boxBuffer = ArrayList<CodePoint>()
@@ -657,7 +657,9 @@ class MovableType(
} }
fun appendGlue(char: CodePoint) { fun appendGlue(char: CodePoint) {
glue += whitespaceGlues[char] ?: throw NullPointerException("${char.toHex()} is not a whitespace") glue += (whitespaceGlues[char] ?: throw NullPointerException("${char.toHex()} is not a whitespace")).let {
if (it == 0) it else it + font.interchar
}
} }
fun appendZeroGlue() { fun appendZeroGlue() {

View File

@@ -1182,7 +1182,7 @@ class TerrarumSansBitmap(
// is this glyph NOT a diacritic? // is this glyph NOT a diacritic?
else if (thisProp.writeOnTop < 0) { else if (thisProp.writeOnTop < 0) {
// apply interchar only if this character is NOT a control char // apply interchar only if this character is NOT a control char
val thisInterchar = if (thisChar.isLetter() || Character.isWhitespace(thisChar)) interchar else 0 val thisInterchar = if (thisChar.isLetter()) interchar else 0
posXbuffer[charIndex] = -thisProp.nudgeX + posXbuffer[charIndex] = -thisProp.nudgeX +
when (itsProp.alignWhere) { when (itsProp.alignWhere) {