From 5c534ed388e6b9d32f08d621becdec219d573bac Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 25 Nov 2021 10:31:16 +0900 Subject: [PATCH] glyph control bits spec change --- CONTRIBUTING.md | 12 +++++------ .../torvald/terrarumsansbitmap/GlyphProps.kt | 21 +++++++++++-------- .../gdx/TerrarumSansBitmap.kt | 19 +++++++++-------- .../gdx/TerrarumTypewriterBitmap.kt | 21 ++++++++++--------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a20314c..f8538b7 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,12 +50,12 @@ Rightmost vertical column (should be 20 px tall) contains the tags. Tags are def K -, K |= Tags used by the "Keming Machine" K | - K -' ,-Unused - ยท --' - X -, Align to this X pos of prev char, only valid if write-on-top is 1 - X |= and is centre-aligned and non-zero - X | (if this is zero, floorOf(width/2) will be used instead) - X -' + K -' ,-Nudging control bit (see below) + N --' + X -, write-on-top and centre-aligned: Align to this X pos of prev char + X | (if this is zero, floorOf(width/2) will be used instead) + X | NOT write-on-top: nudge the texture by this pixels to the + X -' left (if N is unset) or right (if N is set) A -,_ 0 Align 1 Align 0 Align 1 Align before A -' 0 left 0 right 1 centre 1 the glyph D --write-on-top, usually it's diatritics but not always (e.g. devanagari vowel sign O) diff --git a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt index 60b7f06..147a6ef 100755 --- a/src/net/torvald/terrarumsansbitmap/GlyphProps.kt +++ b/src/net/torvald/terrarumsansbitmap/GlyphProps.kt @@ -6,10 +6,11 @@ package net.torvald.terrarumsansbitmap data class GlyphProps( val width: Int, val writeOnTop: Boolean, - val alignWhere: Int, - val alignXPos: Int, + val alignWhere: Int, // ALIGN_LEFT..ALIGN_BEFORE + val alignXPos: Int, // 0..15 or DIA_OVERLAY/DIA_JOINER depends on the context val rtl: Boolean = false, - val stackWhere: Int = 0, + val stackWhere: Int = 0, // STACK_UP..STACK_UP_N_DOWN + var nudgeRight: Boolean = false, var extInfo: IntArray? = null, val hasKernData: Boolean = false, @@ -35,12 +36,13 @@ data class GlyphProps( } constructor(width: Int, tags: Int) : this( - width, - tags.ushr(7).and(1) == 1, - tags.ushr(5).and(3), - tags.ushr(1).and(15), - tags.and(1) == 1, - tags.ushr(8).and(3) + width, + tags.ushr(7).and(1) == 1, + tags.ushr(5).and(3), + tags.ushr(1).and(15), + tags.and(1) == 1, + tags.ushr(8).and(3), + tags.and(1) == 1 ) constructor(width: Int, tags: Int, isLowheight: Boolean, isKernYtype: Boolean, kerningMask: Int) : this( @@ -50,6 +52,7 @@ data class GlyphProps( tags.ushr(1).and(15), tags.and(1) == 1, tags.ushr(8).and(3), + tags.and(1) == 1, null, true, diff --git a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt index 381bdb0..6119b80 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/TerrarumSansBitmap.kt @@ -884,20 +884,21 @@ class TerrarumSansBitmap( posXbuffer[charIndex] = posXbuffer[nonDiacriticCounter] } else if (!thisProp.writeOnTop) { - posXbuffer[charIndex] = when (itsProp.alignWhere) { - GlyphProps.ALIGN_RIGHT -> - posXbuffer[nonDiacriticCounter] + W_VAR_INIT + alignmentOffset + interchar + kerning + extraWidth - GlyphProps.ALIGN_CENTRE -> - posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + interchar + kerning + extraWidth - else -> - posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar + kerning + extraWidth - } + posXbuffer[charIndex] = ((if (thisProp.nudgeRight) 1 else -1) * thisProp.alignXPos) + + when (itsProp.alignWhere) { + GlyphProps.ALIGN_RIGHT -> + posXbuffer[nonDiacriticCounter] + W_VAR_INIT + alignmentOffset + interchar + kerning + extraWidth + GlyphProps.ALIGN_CENTRE -> + posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + interchar + kerning + extraWidth + else -> + posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar + kerning + extraWidth + } nonDiacriticCounter = charIndex stackUpwardCounter = 0 stackDownwardCounter = 0 - extraWidth = 0 + extraWidth = (if (thisProp.nudgeRight) -1 else 1) * thisProp.alignXPos // NOTE: sign is flipped! } else if (thisProp.writeOnTop && thisProp.alignXPos == GlyphProps.DIA_JOINER) { posXbuffer[charIndex] = when (itsProp.alignWhere) { diff --git a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt index 8f9433f..47e5a9d 100644 --- a/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt +++ b/src/net/torvald/terrarumtypewriterbitmap/gdx/TerrarumTypewriterBitmap.kt @@ -51,7 +51,7 @@ class TerrarumTypewriterBitmap( var interchar = 0 - private val glyphProps = HashMap() + val glyphProps = HashMap() private val sheets = HashMap() private val spriteSheetNames = HashMap() @@ -424,20 +424,21 @@ class TerrarumTypewriterBitmap( if (!thisProp.writeOnTop) { - posXbuffer[charIndex] = when (itsProp.alignWhere) { - GlyphProps.ALIGN_RIGHT -> - posXbuffer[nonDiacriticCounter] + TerrarumSansBitmap.W_VAR_INIT + alignmentOffset + interchar + kerning + extraWidth - GlyphProps.ALIGN_CENTRE -> - posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + interchar + kerning + extraWidth - else -> - posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar + kerning + extraWidth - } + posXbuffer[charIndex] = ((if (thisProp.nudgeRight) 1 else -1) * thisProp.alignXPos) + + when (itsProp.alignWhere) { + GlyphProps.ALIGN_RIGHT -> + posXbuffer[nonDiacriticCounter] + TerrarumSansBitmap.W_VAR_INIT + alignmentOffset + interchar + kerning + extraWidth + GlyphProps.ALIGN_CENTRE -> + posXbuffer[nonDiacriticCounter] + HALF_VAR_INIT + itsProp.width + alignmentOffset + interchar + kerning + extraWidth + else -> + posXbuffer[nonDiacriticCounter] + itsProp.width + alignmentOffset + interchar + kerning + extraWidth + } nonDiacriticCounter = charIndex stackUpwardCounter = 0 stackDownwardCounter = 0 - extraWidth = 0 + extraWidth = (if (thisProp.nudgeRight) -1 else 1) * thisProp.alignXPos // NOTE: sign is flipped! } else if (thisProp.writeOnTop && thisProp.alignXPos == GlyphProps.DIA_JOINER) { posXbuffer[charIndex] = when (itsProp.alignWhere) {