fixed a bug where diacritics with align right would not get positioned correctly

This commit is contained in:
minjaesong
2022-03-22 15:47:24 +09:00
parent 44b2450fbf
commit ac85217998
5 changed files with 41 additions and 28 deletions

View File

@@ -57,11 +57,13 @@ Rightmost vertical column (should be 20 px tall) contains the tags. Tags are def
Y |= Diacritics Anchor Points (see below) Y |= Diacritics Anchor Points (see below)
X -' X -'
A -,_ 0 Align 1 Align 0 Align 1 Align before A -,_ 0 Align 1 Align 0 Align 1 Align before
A -' 0 left 0 right 1 centre 1 the glyph A -' 0 Left 0 Right 1 Centre* 1 the glyph
D --Diacritics Type Bit (see below; not all diacritics are actually marked as a diacritics on the spritesheet) D --Diacritics Type Bit (see below; not all diacritics are actually marked as a diacritics on the spritesheet)
S -,_ 0 Stack 1 Stack 0 Before 1 Up & S -,_ 0 Stack 1 Stack 0 Before 1 Up &
(MSB) S -' 0 up 0 down 1 &After 1 Down* (e.g. U+0C48) (MSB) S -' 0 up 0 down 1 &After 1 Down* (e.g. U+0C48)
Align Centre is actually "align to where the anchor point is". Said anchor point default to the X-centre of the glyph.
Up&Down: Up&Down:
1. when two pixels are both #00FF00 it's "don't stack" 1. when two pixels are both #00FF00 it's "don't stack"
2. otherwise, it's actually up&down 2. otherwise, it's actually up&down

Binary file not shown.

Binary file not shown.

View File

@@ -657,6 +657,7 @@ class TerrarumSansBitmap(
// if (directiveOpcode != 0) dbgprn("Directive opcode ${directiveOpcode.toString(2)}: ${code.charInfo()}") // if (directiveOpcode != 0) dbgprn("Directive opcode ${directiveOpcode.toString(2)}: ${code.charInfo()}")
// if (glyphProps[code]?.isPragma("replacewith") == true) dbgprn("Replacer: ${code.charInfo()} into ${glyphProps[code]!!.extInfo.map { it.toString(16) }.joinToString()}") // if (glyphProps[code]?.isPragma("replacewith") == true) dbgprn("Replacer: ${code.charInfo()} into ${glyphProps[code]!!.extInfo.map { it.toString(16) }.joinToString()}")
// if (stackWhere == GlyphProps.STACK_DONT) dbgprn("Diacritics Don't stack: ${code.charInfo()}") // if (stackWhere == GlyphProps.STACK_DONT) dbgprn("Diacritics Don't stack: ${code.charInfo()}")
if (stackWhere == GlyphProps.STACK_DOWN) dbgprn("Diacritics stack down: ${code.charInfo()}")
} }
} }
@@ -790,7 +791,7 @@ class TerrarumSansBitmap(
stackUpwardCounter = 0 stackUpwardCounter = 0
stackDownwardCounter = 0 stackDownwardCounter = 0
extraWidth = thisProp.nudgeX // NOTE: sign is flipped! extraWidth = thisProp.nudgeX // This resets extraWidth. NOTE: sign is flipped!
} }
// FIXME HACK: using 0th diacritics' X-anchor pos as a type selector // FIXME HACK: using 0th diacritics' X-anchor pos as a type selector
/*else if (thisProp.writeOnTop && thisProp.diacriticsAnchors[0].x == GlyphProps.DIA_JOINER) { /*else if (thisProp.writeOnTop && thisProp.diacriticsAnchors[0].x == GlyphProps.DIA_JOINER) {
@@ -808,21 +809,23 @@ class TerrarumSansBitmap(
else { else {
val diacriticsType = thisProp.writeOnTop val diacriticsType = thisProp.writeOnTop
// set X pos according to alignment information // set X pos according to alignment information
posXbuffer[charIndex] = when (thisProp.alignWhere) { posXbuffer[charIndex] = -thisProp.nudgeX +
when (thisProp.alignWhere) {
GlyphProps.ALIGN_LEFT, GlyphProps.ALIGN_BEFORE -> posXbuffer[nonDiacriticCounter] GlyphProps.ALIGN_LEFT, GlyphProps.ALIGN_BEFORE -> posXbuffer[nonDiacriticCounter]
GlyphProps.ALIGN_RIGHT -> { GlyphProps.ALIGN_RIGHT -> {
val alignXPos = if (!itsProp.diacriticsAnchors[diacriticsType].xUsed) itsProp.width else itsProp.diacriticsAnchors[diacriticsType].x println("thisprop alignright $kerning, $extraWidth")
posXbuffer[nonDiacriticCounter] - W_VAR_INIT + alignXPos extraWidth += thisProp.width
posXbuffer[nonDiacriticCounter]+ kerning + extraWidth - thisProp.width
} }
GlyphProps.ALIGN_CENTRE -> { GlyphProps.ALIGN_CENTRE -> {
val alignXPos = if (!itsProp.diacriticsAnchors[diacriticsType].xUsed) itsProp.width.div(2) else itsProp.diacriticsAnchors[diacriticsType].x val anchorPoint =
if (!itsProp.diacriticsAnchors[diacriticsType].xUsed) itsProp.width.div(2) else itsProp.diacriticsAnchors[diacriticsType].x
if (itsProp.alignWhere == GlyphProps.ALIGN_RIGHT) { if (itsProp.alignWhere == GlyphProps.ALIGN_RIGHT) {
posXbuffer[nonDiacriticCounter] + alignXPos + (itsProp.width + 1).div(2) posXbuffer[nonDiacriticCounter] + anchorPoint + (itsProp.width + 1).div(2)
} } else {
else { posXbuffer[nonDiacriticCounter] + anchorPoint - HALF_VAR_INIT
posXbuffer[nonDiacriticCounter] + alignXPos - HALF_VAR_INIT
} }
} }
else -> throw InternalError("Unsupported alignment: ${thisProp.alignWhere}") else -> throw InternalError("Unsupported alignment: ${thisProp.alignWhere}")
@@ -830,14 +833,13 @@ class TerrarumSansBitmap(
// set Y pos according to diacritics position // set Y pos according to diacritics position
// if (thisProp.alignWhere == GlyphProps.ALIGN_CENTRE) {
when (thisProp.stackWhere) { when (thisProp.stackWhere) {
GlyphProps.STACK_DOWN -> { GlyphProps.STACK_DOWN -> {
posYbuffer[charIndex] = (H_DIACRITICS * stackDownwardCounter + -thisProp.nudgeY) * flipY.toSign() posYbuffer[charIndex] = -thisProp.nudgeY + (H_DIACRITICS * stackDownwardCounter + -thisProp.nudgeY) * flipY.toSign()
stackDownwardCounter++ stackDownwardCounter++
} }
GlyphProps.STACK_UP -> { GlyphProps.STACK_UP -> {
posYbuffer[charIndex] = (-H_DIACRITICS * stackUpwardCounter + -thisProp.nudgeY) * flipY.toSign() posYbuffer[charIndex] = -thisProp.nudgeY + (-H_DIACRITICS * stackUpwardCounter + -thisProp.nudgeY) * flipY.toSign()
// shift down on lowercase if applicable // shift down on lowercase if applicable
if (getSheetType(thisChar) in autoShiftDownOnLowercase && if (getSheetType(thisChar) in autoShiftDownOnLowercase &&
lastNonDiacriticChar.isLowHeight()) { lastNonDiacriticChar.isLowHeight()) {
@@ -855,11 +857,11 @@ class TerrarumSansBitmap(
// dbgprn("lastNonDiacriticChar: ${lastNonDiacriticChar.charInfo()}; stack counter: $stackUpwardCounter") // dbgprn("lastNonDiacriticChar: ${lastNonDiacriticChar.charInfo()}; stack counter: $stackUpwardCounter")
} }
GlyphProps.STACK_UP_N_DOWN -> { GlyphProps.STACK_UP_N_DOWN -> {
posYbuffer[charIndex] = (H_DIACRITICS * stackDownwardCounter + -thisProp.nudgeY) * flipY.toSign() posYbuffer[charIndex] = -thisProp.nudgeY + (H_DIACRITICS * stackDownwardCounter + -thisProp.nudgeY) * flipY.toSign()
stackDownwardCounter++ stackDownwardCounter++
posYbuffer[charIndex] = (-H_DIACRITICS * stackUpwardCounter + -thisProp.nudgeY) * flipY.toSign() posYbuffer[charIndex] = -thisProp.nudgeY + (-H_DIACRITICS * stackUpwardCounter + -thisProp.nudgeY) * flipY.toSign()
// shift down on lowercase if applicable // shift down on lowercase if applicable
if (getSheetType(thisChar) in autoShiftDownOnLowercase && if (getSheetType(thisChar) in autoShiftDownOnLowercase &&
lastNonDiacriticChar.isLowHeight()) { lastNonDiacriticChar.isLowHeight()) {
@@ -873,7 +875,8 @@ class TerrarumSansBitmap(
} }
// for BEFORE_N_AFTER, do nothing in here // for BEFORE_N_AFTER, do nothing in here
} }
// }
// Don't reset extraWidth here!
} }
} }
} }
@@ -2163,6 +2166,14 @@ class TerrarumSansBitmap(
private const val MARWARI_HALFLIG_DD_Y = 0xF016F private const val MARWARI_HALFLIG_DD_Y = 0xF016F
private const val MARWARI_LIG_DD_R = 0xF010E private const val MARWARI_LIG_DD_R = 0xF010E
private const val SUNDANESE_ING = 0xF0500
private const val SUNDANESE_ENG = 0xF0501
private const val SUNDANESE_EUNG = 0xF0502
private const val SUNDANESE_IR = 0xF0503
private const val SUNDANESE_ER = 0xF0504
private const val SUNDANESE_EUR = 0xF0505
private const val SUNDANESE_LU = 0xF0506
private val devanagariConsonants = ((0x0915..0x0939) + (0x0958..0x095F) + (0x0978..0x097F) + private val devanagariConsonants = ((0x0915..0x0939) + (0x0958..0x095F) + (0x0978..0x097F) +
(0xF0140..0xF04FF) + (0xF0106..0xF0109)).toHashSet() (0xF0140..0xF04FF) + (0xF0106..0xF0109)).toHashSet()

Binary file not shown.