mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-06-12 17:04:03 +09:00
til antonym of indent is exdent
This commit is contained in:
@@ -92,7 +92,7 @@ class MovableType(
|
|||||||
|
|
||||||
width = maxOf(width, nextPosX + box.width)
|
width = maxOf(width, nextPosX + box.width)
|
||||||
}
|
}
|
||||||
fun dispatchSlug(align: TypesettingStrategy, unindent: Int) {
|
fun dispatchSlug(align: TypesettingStrategy, exdentSize: Int) {
|
||||||
val frozen = slug.freezeIntoCodepointSequence(font)
|
val frozen = slug.freezeIntoCodepointSequence(font)
|
||||||
|
|
||||||
// insert empty blocks to the left
|
// insert empty blocks to the left
|
||||||
@@ -131,8 +131,8 @@ class MovableType(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unindent != 0) {
|
if (exdentSize != 0) {
|
||||||
frozen.addAll(0, (-unindent).glueSizeToGlueChars())
|
frozen.addAll(0, (-exdentSize).glueSizeToGlueChars())
|
||||||
}
|
}
|
||||||
|
|
||||||
typesettedSlugs.add(frozen)
|
typesettedSlugs.add(frozen)
|
||||||
@@ -144,7 +144,7 @@ class MovableType(
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// the slug is likely end with a glue, must take care of it (but don't modify the slug itself)
|
// the slug is likely end with a glue, must take care of it (but don't modify the slug itself)
|
||||||
fun getBadnessW(box: NoTexGlyphLayout, availableGlues: Int, unindentSize: Int): Triple<Double, Int, Any?> {
|
fun getBadnessW(box: NoTexGlyphLayout, availableGlues: Int, exdentSize: Int): Triple<Double, Int, Any?> {
|
||||||
val slug = slug.toMutableList()
|
val slug = slug.toMutableList()
|
||||||
|
|
||||||
// remove the trailing glue(s?) in the slug copy
|
// remove the trailing glue(s?) in the slug copy
|
||||||
@@ -152,7 +152,7 @@ class MovableType(
|
|||||||
slug.removeLastOrNull()
|
slug.removeLastOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
var slugWidth = (slug.lastOrNull()?.getEndPos() ?: 0) - unindentSize
|
var slugWidth = (slug.lastOrNull()?.getEndPos() ?: 0) - exdentSize
|
||||||
if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangable.contains(slug.last().block.penultimateCharOrNull))
|
if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangable.contains(slug.last().block.penultimateCharOrNull))
|
||||||
slugWidth -= hangWidth
|
slugWidth -= hangWidth
|
||||||
else if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangableFW.contains(slug.last().block.penultimateCharOrNull))
|
else if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangableFW.contains(slug.last().block.penultimateCharOrNull))
|
||||||
@@ -164,14 +164,14 @@ class MovableType(
|
|||||||
return Triple(badness, difference, null)
|
return Triple(badness, difference, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBadnessT(box: NoTexGlyphLayout, availableGlues: Int, unindentSize: Int): Triple<Double, Int, Any?> {
|
fun getBadnessT(box: NoTexGlyphLayout, availableGlues: Int, exdentSize: Int): Triple<Double, Int, Any?> {
|
||||||
val slug = slug.toMutableList()
|
val slug = slug.toMutableList()
|
||||||
|
|
||||||
// add the box to the slug copy
|
// add the box to the slug copy
|
||||||
val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0)
|
val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0)
|
||||||
slug.add(Block(nextPosX, box))
|
slug.add(Block(nextPosX, box))
|
||||||
|
|
||||||
var slugWidth = slugWidth + box.width - unindentSize
|
var slugWidth = slugWidth + box.width - exdentSize
|
||||||
if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangable.contains(slug.last().block.penultimateCharOrNull))
|
if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangable.contains(slug.last().block.penultimateCharOrNull))
|
||||||
slugWidth -= hangWidth
|
slugWidth -= hangWidth
|
||||||
else if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangableFW.contains(slug.last().block.penultimateCharOrNull))
|
else if (slug.isNotEmpty() && slug.last().block.penultimateCharOrNull != null && hangableFW.contains(slug.last().block.penultimateCharOrNull))
|
||||||
@@ -187,7 +187,7 @@ class MovableType(
|
|||||||
return Triple(badness, difference, null)
|
return Triple(badness, difference, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBadnessH(box: NoTexGlyphLayout, diff: Int, availableGlues: Int, unindentSize: Int, currentWidth: Int): Triple<Double, Int, Any?> {
|
fun getBadnessH(box: NoTexGlyphLayout, diff: Int, availableGlues: Int, exdentSize: Int, currentWidth: Int): Triple<Double, Int, Any?> {
|
||||||
// don't hyphenate if:
|
// don't hyphenate if:
|
||||||
// - the word is too short (5 chars or less)
|
// - the word is too short (5 chars or less)
|
||||||
// - the word is pre-hyphenated (ends with hyphen-null)
|
// - the word is pre-hyphenated (ends with hyphen-null)
|
||||||
@@ -198,7 +198,7 @@ class MovableType(
|
|||||||
val slug = slug.toMutableList() // ends with a glue
|
val slug = slug.toMutableList() // ends with a glue
|
||||||
|
|
||||||
// calculate new slug width which contains the given box
|
// calculate new slug width which contains the given box
|
||||||
val slugWidth = slugWidth + box.width - unindentSize
|
val slugWidth = slugWidth + box.width - exdentSize
|
||||||
|
|
||||||
// println("Width: $slugWidth/$paperWidth")
|
// println("Width: $slugWidth/$paperWidth")
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ class MovableType(
|
|||||||
val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0)
|
val nextPosX = (slug.lastOrNull()?.getEndPos() ?: 0)
|
||||||
slug.add(Block(nextPosX, hyphHead)) // now ends with 'word-'
|
slug.add(Block(nextPosX, hyphHead)) // now ends with 'word-'
|
||||||
|
|
||||||
val slugWidth1 = slug.last().getEndPos() - unindentSize - hyphenWidth
|
val slugWidth1 = slug.last().getEndPos() - exdentSize - hyphenWidth
|
||||||
|
|
||||||
val difference = paperWidth - slugWidth1
|
val difference = paperWidth - slugWidth1
|
||||||
val badness = penaliseHyphenation(difference.absoluteValue, availableGlues.toDouble())
|
val badness = penaliseHyphenation(difference.absoluteValue, availableGlues.toDouble())
|
||||||
@@ -231,7 +231,7 @@ class MovableType(
|
|||||||
// deal with the hangables
|
// deal with the hangables
|
||||||
val firstChar = slug.firstOrNull()?.block?.secondCharOrNull
|
val firstChar = slug.firstOrNull()?.block?.secondCharOrNull
|
||||||
val lastChar = box.penultimateCharOrNull
|
val lastChar = box.penultimateCharOrNull
|
||||||
val slugUnindent = when (strategy) {
|
val slugExdent = when (strategy) {
|
||||||
TypesettingStrategy.JUSTIFIED -> {
|
TypesettingStrategy.JUSTIFIED -> {
|
||||||
if (firstChar == null)
|
if (firstChar == null)
|
||||||
0
|
0
|
||||||
@@ -243,18 +243,18 @@ class MovableType(
|
|||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (slugUnindent != 0) println("Slug unindentation $slugUnindent on text ${slug.joinToString(" ") { it.block.text.toReadable() }}")
|
// if (slugExdent != 0) println("Slug exdentation $slugExdent on text ${slug.joinToString(" ") { it.block.text.toReadable() }}")
|
||||||
|
|
||||||
val slugWidthForOverflowCalc = when (strategy) {
|
val slugWidthForOverflowCalc = when (strategy) {
|
||||||
TypesettingStrategy.JUSTIFIED -> {
|
TypesettingStrategy.JUSTIFIED -> {
|
||||||
if (lastChar == null)
|
if (lastChar == null)
|
||||||
slugWidth - slugUnindent
|
slugWidth - slugExdent
|
||||||
else if (hangable.contains(lastChar))
|
else if (hangable.contains(lastChar))
|
||||||
slugWidth - hangWidth - slugUnindent
|
slugWidth - hangWidth - slugExdent
|
||||||
else if (hangableFW.contains(lastChar))
|
else if (hangableFW.contains(lastChar))
|
||||||
slugWidth - hangWidthFW - slugUnindent
|
slugWidth - hangWidthFW - slugExdent
|
||||||
else
|
else
|
||||||
slugWidth - slugUnindent
|
slugWidth - slugExdent
|
||||||
}
|
}
|
||||||
else -> slugWidth
|
else -> slugWidth
|
||||||
}
|
}
|
||||||
@@ -278,18 +278,18 @@ class MovableType(
|
|||||||
var (badnessW, widthDeltaW, _) = getBadnessW(
|
var (badnessW, widthDeltaW, _) = getBadnessW(
|
||||||
box,
|
box,
|
||||||
initialGlueCount,
|
initialGlueCount,
|
||||||
slugUnindent
|
slugExdent
|
||||||
) // widthDeltaW is always positive
|
) // widthDeltaW is always positive
|
||||||
var (badnessT, widthDeltaT, _) = getBadnessT(
|
var (badnessT, widthDeltaT, _) = getBadnessT(
|
||||||
box,
|
box,
|
||||||
initialGlueCount,
|
initialGlueCount,
|
||||||
slugUnindent
|
slugExdent
|
||||||
) // widthDeltaT is always positive
|
) // widthDeltaT is always positive
|
||||||
var (badnessH, widthDeltaH, hyph) = getBadnessH(
|
var (badnessH, widthDeltaH, hyph) = getBadnessH(
|
||||||
box,
|
box,
|
||||||
box.width - slugWidthForOverflowCalc,
|
box.width - slugWidthForOverflowCalc,
|
||||||
initialGlueCount,
|
initialGlueCount,
|
||||||
slugUnindent,
|
slugExdent,
|
||||||
slugWidthForOverflowCalc + box.width
|
slugWidthForOverflowCalc + box.width
|
||||||
) // widthDeltaH can be anything
|
) // widthDeltaH can be anything
|
||||||
|
|
||||||
@@ -395,7 +395,7 @@ class MovableType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// println(" > Line ${typesettedSlugs.size + 1} Final Slug: [ ${slug.map { it.block.text.toReadable() }.joinToString(" | ")} ]")
|
// println(" > Line ${typesettedSlugs.size + 1} Final Slug: [ ${slug.map { it.block.text.toReadable() }.joinToString(" | ")} ]")
|
||||||
dispatchSlug(strategy, slugUnindent)
|
dispatchSlug(strategy, slugExdent)
|
||||||
}
|
}
|
||||||
// if adding the box would cause overflow (ragged-something, centred)
|
// if adding the box would cause overflow (ragged-something, centred)
|
||||||
else {
|
else {
|
||||||
@@ -406,7 +406,7 @@ class MovableType(
|
|||||||
|
|
||||||
addHyphenatedTail(box)
|
addHyphenatedTail(box)
|
||||||
|
|
||||||
dispatchSlug(strategy, slugUnindent)
|
dispatchSlug(strategy, slugExdent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// typeset the boxes normally
|
// typeset the boxes normally
|
||||||
|
|||||||
Reference in New Issue
Block a user