From 385dc8bdff4dd5bfecac33bfbd91390561bb5dd1 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 14 May 2024 00:34:53 +0900 Subject: [PATCH] fix: bad hyphenation on Hangul because the code was always assuming left part of the 'hyphenated' text always ends with a hyphen --- src/net/torvald/terrarumsansbitmap/MovableType.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/torvald/terrarumsansbitmap/MovableType.kt b/src/net/torvald/terrarumsansbitmap/MovableType.kt index 259ae93..f45e311 100644 --- a/src/net/torvald/terrarumsansbitmap/MovableType.kt +++ b/src/net/torvald/terrarumsansbitmap/MovableType.kt @@ -212,9 +212,10 @@ class MovableType( // add the hyphHead to the slug copy val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0) - slug.add(Block(nextPosX, hyphHead)) // now ends with 'word-' + slug.add(Block(nextPosX, hyphHead)) // now ends with 'word-' (but not in Hangul) + val hasHyphen = hyphHead.penultimateCharOrNull == 0x2D - val slugWidth1 = slug.last().getEndPos() - exdentSize - hyphenWidth + val slugWidth1 = slug.last().getEndPos() - exdentSize - hyphenWidth * hasHyphen.toInt() val difference = paperWidth - slugWidth1 val badness = penaliseHyphenation(difference.absoluteValue, availableGlues.toDouble()) @@ -1137,7 +1138,8 @@ class MovableType( return out } + inline fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0 + } // end of companion object } -