From 22b12d4a783fef2416748c905328f4836a5bc45c Mon Sep 17 00:00:00 2001 From: soywiz Date: Thu, 26 Jan 2023 21:19:54 +0100 Subject: [PATCH] Fixes characters from being slightly displaced and spaces showing a dot in a LazyBitmapFont --- .../kotlin/com/soywiz/korim/font/LazyBitmapFont.kt | 5 ++++- .../com/soywiz/korim/font/LazyBitmapFontTest.kt | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 korim/src/commonTest/kotlin/com/soywiz/korim/font/LazyBitmapFontTest.kt diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt index 3027214792..7df6eb2caa 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt @@ -98,7 +98,8 @@ class LazyBitmapFont( } val entry = atlas.add(rbmp, Unit) - val slice = entry.slice + val slice = entry.slice.sliceWithBounds(border, border, entry.slice.width - border, entry.slice.height - border) + //val slice = bmp.slice() //val fm = result.fmetrics val g = result.glyphs.first() @@ -106,6 +107,8 @@ class LazyBitmapFont( val m = g.metrics val xadvance = m.xadvance + //println("codePoint='$codePoint': $slice, gx=${g.x}, gy=${g.y}") + //println("codePoint=$codePoint, char='${codePoint.toChar()}', xadvance=${xadvance}, height=${m.height}, top=${m.top}, ascent=${fm.ascent}, slice=$slice") //BitmapFont.Glyph(fontSize, codePoint, entry.slice, 0, (m.height - m.top + fm.ascent).toInt(), xadvance.toInt()) BitmapFont.Glyph( diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/font/LazyBitmapFontTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/font/LazyBitmapFontTest.kt new file mode 100644 index 0000000000..6d23f2e7a4 --- /dev/null +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/font/LazyBitmapFontTest.kt @@ -0,0 +1,13 @@ +package com.soywiz.korim.font + +import kotlin.test.* + +class LazyBitmapFontTest { + @Test + fun testEnsureSpaceIsEmpty() { + val glyph = DefaultTtfFontAsBitmap.getOrNull(' '.code) + val texture = glyph!!.texture + assertEquals(0, texture.width) + assertEquals(0, texture.height) + } +}