From: Lanius Trolling Date: Thu, 7 Mar 2024 12:53:45 +0000 (-0500) Subject: Refactor conversion of String to GlyphSequence X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=29162cbb62787d9adddf4d28ddd5e7d441490a23;p=factbooks Refactor conversion of String to GlyphSequence --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/fonts.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/fonts.kt index 46f72bc..5924dcd 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/fonts.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/fonts.kt @@ -103,24 +103,18 @@ object MechyrdiaSansFont { } } - private fun TTFFile.getGlyphs(str: String): GlyphSequence { - val length = str.codePointCount(0, str.length) - val codeSeq = str.toCodePointSequence() - val glyphSeq = codeSeq.map { getGlyph(it) } - - val codes = codeSeq.iterator().let { iter -> - IntArray(length) { - assert(iter.hasNext()) - iter.next() - } - } + private fun String.toCodePointArray(): IntArray { + val iter = toCodePointSequence().iterator() - val glyphs = glyphSeq.iterator().let { iter -> - IntArray(length) { - assert(iter.hasNext()) - iter.next() - } + return IntArray(codePointCount(0, length)) { _ -> + assert(iter.hasNext()) + iter.next() } + } + + private fun TTFFile.getGlyphs(str: String): GlyphSequence { + val codes = str.toCodePointArray() + val glyphs = IntArray(codes.size) { i -> getGlyph(codes[i]) } return GlyphSequence(IntBuffer.wrap(codes), IntBuffer.wrap(glyphs), null) }