new charset override 'codestyle ascii'

This commit is contained in:
minjaesong
2024-05-03 16:09:18 +09:00
parent b3e6f61f96
commit accbecfb3e
4 changed files with 44 additions and 19 deletions

Binary file not shown.

View File

@@ -126,13 +126,13 @@ class MovableType(
// - the word is pre-hyphenated (ends with hyphen-null) // - the word is pre-hyphenated (ends with hyphen-null)
val glyphCount = box.text.count { it in 32..0xfffff } val glyphCount = box.text.count { it in 32..0xfffff }
if (glyphCount <= (if (paperWidth < 350) 4 else if (paperWidth < 480) 5 else 6) || box.text.penultimate() == 0x2D) if (glyphCount <= (if (paperWidth < 350) 4 else if (paperWidth < 480) 5 else 6) || box.text.penultimate() == 0x2D)
return Triple(1111111111.0, 2147483647, null) return Triple(Double.POSITIVE_INFINITY, 2147483647, null)
val slug = slug.toMutableList() val slug = slug.toMutableList()
val (hyphHead, hyphTail) = box.text.hyphenate(font, diff).toList().map { createGlyphLayout(font, it) } val (hyphHead, hyphTail) = box.text.hyphenate(font, diff).toList().map { createGlyphLayout(font, it) }
if (hyphTail.text.isEmpty()) if (hyphTail.text.isEmpty())
return Triple(2222222222.0, 2147483647, null) return Triple(Double.POSITIVE_INFINITY, 2147483647, null)
// add the hyphHead to the slug copy // add the hyphHead to the slug copy
val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0) val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0)
@@ -183,19 +183,27 @@ class MovableType(
badnessH -= 0.01 // try to break even badnessH -= 0.01 // try to break even
val disableHyphThre = 5.0 val disableHyphThre = 5.0
// println("\nLine: ${slug.map { it.block.text }.filter { it.isNotGlue() }.joinToString(" ") { it.toReadable() }}") // disable hyphenation if badness of others is lower than the threshold
// println("W diff: $widthDeltaW, badness: $badnessW")
// println("T diff: $widthDeltaT, badness: $badnessT")
if ((badnessW <= disableHyphThre || badnessT <= disableHyphThre)) { if ((badnessW <= disableHyphThre || badnessT <= disableHyphThre)) {
// println("H diff: $widthDeltaH, badness: $badnessH (disabled)") badnessH = Double.POSITIVE_INFINITY
badnessH = 2147483648.0
} }
else {
// println("H diff: $widthDeltaH, badness: $badnessH") // disable hyphenation if hyphenating a word is impossible
if (hyph == null) {
badnessH = Double.POSITIVE_INFINITY
} }
if (badnessH.isInfinite() && badnessW.isInfinite() && badnessT.isInfinite()) {
throw Error("Typesetting failed: badness of all three strategies diverged to infinity\ntext (${slug.size} tokens): ${slug.map { it.block.text }.filter { it.isNotGlue() }.joinToString(" ") { it.toReadable() }}")
}
println("\nLine: ${slug.map { it.block.text }.filter { it.isNotGlue() }.joinToString(" ") { it.toReadable() }}")
println("W diff: $widthDeltaW, badness: $badnessW")
println("T diff: $widthDeltaT, badness: $badnessT")
println("H diff: $widthDeltaH, badness: $badnessH")
val (selectedBadness, selectedWidthDelta, selectedStrat) = listOf( val (selectedBadness, selectedWidthDelta, selectedStrat) = listOf(
Triple(badnessW, widthDeltaW, "Widen"), Triple(badnessW, widthDeltaW, "Widen"),
Triple(badnessT, widthDeltaT, "Tighten"), Triple(badnessT, widthDeltaT, "Tighten"),
@@ -203,12 +211,12 @@ class MovableType(
).minByOrNull { it.first }!! ).minByOrNull { it.first }!!
// if (selectedStrat == "Hyphenate") { if (selectedStrat == "Hyphenate") {
// val (hyphHead, hyphTail) = hyph as Pair<NoTexGlyphLayout?, NoTexGlyphLayout?> val (hyphHead, hyphTail) = hyph as Pair<NoTexGlyphLayout?, NoTexGlyphLayout?>
// println("Selected: $selectedStrat (${hyphHead?.text?.toReadable()}, ${hyphTail?.text?.toReadable()}) (badness $selectedBadness, diff $selectedWidthDelta)") println("Selected: $selectedStrat (${hyphHead?.text?.toReadable()}, ${hyphTail?.text?.toReadable()}) (badness $selectedBadness, diff $selectedWidthDelta)")
// } }
// else else
// println("Selected: $selectedStrat (badness $selectedBadness, diff $selectedWidthDelta)") println("Selected: $selectedStrat (badness $selectedBadness, diff $selectedWidthDelta)")
// println(" Line ${typesettedSlugs.size + 1} Strat: $selectedStrat (badness $selectedBadness, delta $selectedWidthDelta; full badness WTH = $badnessW, $badnessT, $badnessH; full delta WTH = $widthDeltaW, $widthDeltaT, $widthDeltaH)") // println(" Line ${typesettedSlugs.size + 1} Strat: $selectedStrat (badness $selectedBadness, delta $selectedWidthDelta; full badness WTH = $badnessW, $badnessT, $badnessH; full delta WTH = $widthDeltaW, $widthDeltaT, $widthDeltaH)")
// println(" Interim Slug: [ ${slug.map { it.block.text.toReadable() }.joinToString(" | ")} ]") // println(" Interim Slug: [ ${slug.map { it.block.text.toReadable() }.joinToString(" | ")} ]")
@@ -829,6 +837,7 @@ class MovableType(
private val whitespaceGlues = hashMapOf( private val whitespaceGlues = hashMapOf(
0x20 to 4, 0x20 to 4,
0x3000 to 16, 0x3000 to 16,
0xf0520 to 9,
) )
private val cjpuncts = listOf(0x203c, 0x2047, 0x2048, 0x2049, 0x3001, 0x3002, 0x3006, 0x303b, 0x30a0, 0x30fb, 0x30fc, 0x301c, 0xff01, 0xff0c, 0xff0e, 0xff1a, 0xff1b, 0xff1f, 0xff5e, 0xff65).toSortedSet() private val cjpuncts = listOf(0x203c, 0x2047, 0x2048, 0x2049, 0x3001, 0x3002, 0x3006, 0x303b, 0x30a0, 0x30fb, 0x30fc, 0x301c, 0xff01, 0xff0c, 0xff0e, 0xff1a, 0xff1b, 0xff1f, 0xff5e, 0xff65).toSortedSet()
private val cjparenStarts = listOf(0x3008, 0x300A, 0x300C, 0x300E, 0x3010, 0x3014, 0x3016, 0x3018, 0x301A, 0x30fb, 0xff65).toSortedSet() private val cjparenStarts = listOf(0x3008, 0x300A, 0x300C, 0x300E, 0x3010, 0x3014, 0x3016, 0x3018, 0x301A, 0x30fb, 0xff65).toSortedSet()

View File

@@ -607,6 +607,7 @@ class TerrarumSansBitmap(
SHEET_BRAILLE_VARW -> brailleIndexY(ch) SHEET_BRAILLE_VARW -> brailleIndexY(ch)
SHEET_SUNDANESE_VARW -> sundaneseIndexY(ch) SHEET_SUNDANESE_VARW -> sundaneseIndexY(ch)
SHEET_DEVANAGARI2_INTERNAL_VARW -> devanagari2IndexY(ch) SHEET_DEVANAGARI2_INTERNAL_VARW -> devanagari2IndexY(ch)
SHEET_CODESTYLE_ASCII_VARW -> codestyleAsciiIndexY(ch)
else -> ch / 16 else -> ch / 16
} }
@@ -1789,6 +1790,7 @@ class TerrarumSansBitmap(
val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString() val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString()
val charsetOverrideBulgarian = Character.toChars(CHARSET_OVERRIDE_BG_BG).toSurrogatedString() val charsetOverrideBulgarian = Character.toChars(CHARSET_OVERRIDE_BG_BG).toSurrogatedString()
val charsetOverrideSerbian = Character.toChars(CHARSET_OVERRIDE_SR_SR).toSurrogatedString() val charsetOverrideSerbian = Character.toChars(CHARSET_OVERRIDE_SR_SR).toSurrogatedString()
val charsetOverrideCodestyle = Character.toChars(CHARSET_OVERRIDE_CODESTYLE).toSurrogatedString()
// randomiser effect hash ONLY // randomiser effect hash ONLY
private val hashBasis = -3750763034362895579L private val hashBasis = -3750763034362895579L
@@ -2170,6 +2172,7 @@ class TerrarumSansBitmap(
internal const val SHEET_BRAILLE_VARW = 34 internal const val SHEET_BRAILLE_VARW = 34
internal const val SHEET_SUNDANESE_VARW = 35 internal const val SHEET_SUNDANESE_VARW = 35
internal const val SHEET_DEVANAGARI2_INTERNAL_VARW = 36 internal const val SHEET_DEVANAGARI2_INTERNAL_VARW = 36
internal const val SHEET_CODESTYLE_ASCII_VARW = 37
internal const val SHEET_UNKNOWN = 254 internal const val SHEET_UNKNOWN = 254
@@ -2184,6 +2187,7 @@ class TerrarumSansBitmap(
internal const val CHARSET_OVERRIDE_DEFAULT = 0xFFFC0 internal const val CHARSET_OVERRIDE_DEFAULT = 0xFFFC0
internal const val CHARSET_OVERRIDE_BG_BG = 0xFFFC1 internal const val CHARSET_OVERRIDE_BG_BG = 0xFFFC1
internal const val CHARSET_OVERRIDE_SR_SR = 0xFFFC2 internal const val CHARSET_OVERRIDE_SR_SR = 0xFFFC2
internal const val CHARSET_OVERRIDE_CODESTYLE = 0xFFFC3
internal const val FIXED_BLOCK_1 = 0xFFFD0 internal const val FIXED_BLOCK_1 = 0xFFFD0
internal const val MOVABLE_BLOCK_M1 = 0xFFFE0 internal const val MOVABLE_BLOCK_M1 = 0xFFFE0
@@ -2232,6 +2236,7 @@ class TerrarumSansBitmap(
"braille_variable.tga", "braille_variable.tga",
"sundanese_variable.tga", "sundanese_variable.tga",
"devanagari_internal_extrawide_variable.tga", "devanagari_internal_extrawide_variable.tga",
"pua_codestyle_ascii_variable.tga",
) )
internal val codeRange = arrayOf( // MUST BE MATCHING WITH SHEET INDICES!! internal val codeRange = arrayOf( // MUST BE MATCHING WITH SHEET INDICES!!
0..0xFF, // SHEET_ASCII_VARW 0..0xFF, // SHEET_ASCII_VARW
@@ -2271,19 +2276,22 @@ class TerrarumSansBitmap(
0x2800..0x28FF, // SHEET_BRAILLE_VARW 0x2800..0x28FF, // SHEET_BRAILLE_VARW
(0x1B80..0x1BBF) + (0x1CC0..0x1CCF) + (0xF0500..0xF050F), // SHEET_SUNDANESE_VARW (0x1B80..0x1BBF) + (0x1CC0..0x1CCF) + (0xF0500..0xF050F), // SHEET_SUNDANESE_VARW
0xF0110..0xF012F, // SHEET_DEVANAGARI2_INTERNAL_VARW 0xF0110..0xF012F, // SHEET_DEVANAGARI2_INTERNAL_VARW
0xF0520..0xF057F, // SHEET_CODESTYLE_ASCII_VARW
) )
private val codeRangeHangulCompat = 0x3130..0x318F private val codeRangeHangulCompat = 0x3130..0x318F
private val altCharsetCodepointOffsets = arrayOf( private val altCharsetCodepointOffsets = arrayOf(
0, // null 0, // null
0xF0000 - 0x400, // bulgarian 0xF0000 - 0x400, // bulgarian
0xF0060 - 0x400 // serbian 0xF0060 - 0x400, // serbian
0xF0520 - 0x20, // codestyle
) )
private val altCharsetCodepointDomains = arrayOf( private val altCharsetCodepointDomains = arrayOf(
0..0x10FFFF, 0..0x10FFFF,
0x400..0x45F, 0x400..0x45F,
0x400..0x45F 0x400..0x45F,
0x20..0x7F,
) )
private val diacriticDotRemoval = hashMapOf( private val diacriticDotRemoval = hashMapOf(
@@ -2593,10 +2601,12 @@ class TerrarumSansBitmap(
private fun brailleIndexY(c: CodePoint) = (c - 0x2800) / 16 private fun brailleIndexY(c: CodePoint) = (c - 0x2800) / 16
private fun sundaneseIndexY(c: CodePoint) = (if (c >= 0xF0500) (c - 0xF04B0) else if (c < 0x1BC0) (c - 0x1B80) else (c - 0x1C80)) / 16 private fun sundaneseIndexY(c: CodePoint) = (if (c >= 0xF0500) (c - 0xF04B0) else if (c < 0x1BC0) (c - 0x1B80) else (c - 0x1C80)) / 16
private fun devanagari2IndexY(c: CodePoint) = (c - 0xF0110) / 16 private fun devanagari2IndexY(c: CodePoint) = (c - 0xF0110) / 16
private fun codestyleAsciiIndexY(c: CodePoint) = (c - 0xF0520) / 16
val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString() val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString()
val charsetOverrideBulgarian = Character.toChars(CHARSET_OVERRIDE_BG_BG).toSurrogatedString() val charsetOverrideBulgarian = Character.toChars(CHARSET_OVERRIDE_BG_BG).toSurrogatedString()
val charsetOverrideSerbian = Character.toChars(CHARSET_OVERRIDE_SR_SR).toSurrogatedString() val charsetOverrideSerbian = Character.toChars(CHARSET_OVERRIDE_SR_SR).toSurrogatedString()
val charsetOverrideCodestyle = Character.toChars(CHARSET_OVERRIDE_CODESTYLE).toSurrogatedString()
fun toColorCode(argb4444: Int): String = Character.toChars(0x100000 + argb4444).toSurrogatedString() fun toColorCode(argb4444: Int): String = Character.toChars(0x100000 + argb4444).toSurrogatedString()
fun toColorCode(r: Int, g: Int, b: Int, a: Int = 0x0F): String = toColorCode(a.shl(12) or r.shl(8) or g.shl(4) or b) fun toColorCode(r: Int, g: Int, b: Int, a: Int = 0x0F): String = toColorCode(a.shl(12) or r.shl(8) or g.shl(4) or b)
private fun CharArray.toSurrogatedString(): String = "${this[0]}${this[1]}" private fun CharArray.toSurrogatedString(): String = "${this[0]}${this[1]}"

Binary file not shown.