diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4e05633..932e925 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,6 +8,9 @@
+
+
+
@@ -27,8 +30,8 @@
-
-
+
+
@@ -36,8 +39,8 @@
-
-
+
+
@@ -64,11 +67,11 @@
-
+
-
-
+
+
@@ -76,11 +79,16 @@
+
+
+
+
+
-
-
+
+
@@ -97,8 +105,8 @@
-
-
+
+
@@ -153,8 +161,6 @@
- glyphWidthBuffer
- GlyphProps.LE
buildWidthTable
lastNonDiacriticChar
c.toInt()
@@ -183,6 +189,8 @@
xyswap
isXYSwapped
xySw
+ getWidth
+ getWidthOfCharSeq
.141
@@ -209,24 +217,26 @@
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -268,7 +278,6 @@
-
@@ -492,11 +501,11 @@
-
-
+
+
@@ -504,7 +513,7 @@
-
+
@@ -513,22 +522,21 @@
-
-
-
+
+
@@ -536,8 +544,8 @@
-
-
+
+
@@ -556,25 +564,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -899,30 +888,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -930,10 +895,40 @@
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -996,6 +991,7 @@
diff --git a/FontTestGDX/lib/TerrarumSansBitmap.jar b/FontTestGDX/lib/TerrarumSansBitmap.jar
index bcf2f49..38021e1 100644
Binary files a/FontTestGDX/lib/TerrarumSansBitmap.jar and b/FontTestGDX/lib/TerrarumSansBitmap.jar differ
diff --git a/TerrarumSansBitmap.jar b/TerrarumSansBitmap.jar
deleted file mode 100644
index 51beba5..0000000
Binary files a/TerrarumSansBitmap.jar and /dev/null differ
diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt
index 69d9b29..652cea6 100644
--- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt
+++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt
@@ -619,10 +619,15 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
else if (sheetID == SHEET_HANGUL) {
// Flookahead for {I, P, F}
- val cNext = if (index + 1 <= textBuffer.size) textBuffer[index + 1] else 0
- val cNextNext = if (index + 2 <= textBuffer.size) textBuffer[index + 2] else 0
+ val cNext = if (index + 1 < textBuffer.size) textBuffer[index + 1] else 0
+ val cNextNext = if (index + 2 < textBuffer.size) textBuffer[index + 2] else 0
- val hangulLength = if (isHangulJongseong(cNextNext)) 3 else 2
+ val hangulLength = if (isHangulJongseong(cNextNext) && isHangulJungseong(cNext))
+ 3
+ else if (isHangulJungseong(cNext))
+ 2
+ else
+ 1
val (indices, rows) = toHangulIndexAndRow(c, cNext, cNextNext)
@@ -1033,7 +1038,62 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo
private val glyphLayout = GlyphLayout()
fun getWidth(text: String): Int {
- return getWidthOfCharSeq(text.toCodePoints()).sum()
+ var s = text.toCodePoints()
+ var len = 0
+
+ var i = 0
+ while (i <= s.lastIndex) {
+ val chr = s[i]
+ val ctype = getSheetType(s[i])
+
+ var len2 = 0
+ if (variableWidthSheets.contains(ctype)) {
+ if (!glyphProps.containsKey(chr)) {
+ System.err.println("[TerrarumSansBitmap] no width data for glyph number ${Integer.toHexString(chr.toInt()).toUpperCase()}")
+ len2 = W_LATIN_WIDE
+ }
+
+ val prop = glyphProps[chr] ?: nullProp
+
+ if (!prop.writeOnTop)
+ len2 = prop.width
+ }
+ else if (isColourCode(chr) || isCharsetOverride(chr))
+ len2 = 0
+ else if (ctype == SHEET_CJK_PUNCT)
+ len2 = W_ASIAN_PUNCT
+ else if (ctype == SHEET_HANGUL) {
+ // hangul IPF canonical and special cases
+ val cNext = if (i + 1 < s.size) s[i + 1] else 0
+ val cNextNext = if (i + 2 < s.size) s[i + 2] else 0
+ val hangulLength = if (isHangulJongseong(cNextNext) && isHangulJungseong(cNext))
+ 3
+ else if (isHangulJungseong(cNext))
+ 2
+ else
+ 1
+
+ len2 = W_HANGUL
+ i += hangulLength - 1
+ }
+ else if (ctype == SHEET_KANA)
+ len2 = W_KANA
+ else if (unihanWidthSheets.contains(ctype))
+ len2 = W_UNIHAN
+ else if (ctype == SHEET_CUSTOM_SYM)
+ len2 = SIZE_CUSTOM_SYM
+ else
+ len2 = W_LATIN_WIDE
+
+
+ len += len2 * scale
+
+ if (i < s.lastIndex) len += interchar
+
+
+ i++
+ }
+ return len
}