fix: btex toc overflow

This commit is contained in:
minjaesong
2024-05-16 13:35:36 +09:00
parent b963e0d3f2
commit e308e9a356
4 changed files with 29 additions and 5 deletions

View File

@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.FlippingSpriteBatch
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.imagefont.TinyAlphNum

View File

@@ -792,10 +792,11 @@ object BTeXParser {
if (tocPage != null) {
// estimate the number of TOC pages
// TOC page always takes up a full paper, therefore tocSizeInPages is always multiple of 2
var tocSizeInPages = (cptSectMap.size + 2) / doc.pageLines
var tocSizeInPages = ((cptSectMap.size + 2f) / doc.pageLines).ceilToInt()
if (tocSizeInPages == 0) tocSizeInPages = 2
if (tocSizeInPages % 2 == 1) tocSizeInPages += 1
println("TOC number of entries: ${cptSectMap.size}, estimated page count: $tocSizeInPages")
// renumber things
if (tocSizeInPages > 1) {
@@ -812,6 +813,7 @@ object BTeXParser {
}
}
var currentTOCpage = tocPage!!
cptSectMap.forEach { (type, name, pg, part, cpt, sect) ->
val indent = if (type == "subsection") 2*PAR_INDENTATION else if (type == "section") PAR_INDENTATION else 0
val heading = if (part == null && cpt == null && sect == null)
@@ -823,7 +825,11 @@ object BTeXParser {
else
"$cpt.$sect${spacingBlockToString(HEADING_NUM_TITLE_GAP)}"
typesetTOCline("$heading", name, pg, handler, indent, tocPage)
typesetTOCline("$heading", name, pg, handler, indent, currentTOCpage)
if (doc.linesPrintedOnPage[currentTOCpage] >= doc.pageLines) {
currentTOCpage += 1
}
}
}
}
@@ -1728,7 +1734,7 @@ object BTeXParser {
val ccDefault = TerrarumSansBitmap.toColorCode(0,0,0)
val ccBucks = TerrarumSansBitmap.toColorCode(5,0,0)
val ccCode = TerrarumSansBitmap.toColorCode(8,0,0)
val ccCode = TerrarumSansBitmap.toColorCode(7,0,0)
val ccHref = TerrarumSansBitmap.toColorCode(0,3,11)
val ccEmph = TerrarumSansBitmap.toColorCode(0xfc11)
val ccItemName = TerrarumSansBitmap.toColorCode(0xf03b)

View File

@@ -26,9 +26,10 @@ import kotlin.system.measureTimeMillis
*/
class BTeXTest : ApplicationAdapter() {
val filePath = "btex.xml"
// val filePath = "btex_ko.xml"
// val filePath = "test.xml"
val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
// val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"
// val filePath = "literature/koKR/yisang_nalgae.btxbook"