more btex documentation; fix: pagenum for btex indices are off by one

This commit is contained in:
minjaesong
2024-05-14 16:23:50 +09:00
parent 23f4557bf2
commit f08857530a
4 changed files with 211 additions and 33 deletions

View File

@@ -82,6 +82,8 @@ object BTeXParser {
private val tagStack = ArrayList<String>() // index zero should be "btex"
private var tagHistory = ArrayList<String>()
private var currentHrefId: String? = null // any Unicode string that is not empty
private var currentTheme = ""
private val elemOpeners: HashMap<String, KFunction<*>> = HashMap()
@@ -698,10 +700,14 @@ object BTeXParser {
@OpenTag // reflective access is impossible with 'private'
fun processElemA(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
paragraphBuffer.append(HREF_BEGIN)
currentHrefId = attribs["href"]
if (currentHrefId != null && currentHrefId!!.isBlank())
throw IllegalStateException("Hyperlink target cannot be empty or blank")
}
@CloseTag
fun closeElemA(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
paragraphBuffer.append(HREF_END)
currentHrefId = null
}
@OpenTag // reflective access is impossible with 'private'
@@ -753,7 +759,7 @@ object BTeXParser {
val pageWidth = doc.textWidth
indexMap.keys.toList().sorted().forEach { key ->
typesetTOCline("", key, indexMap[key]!!, handler)
typesetTOCline("", key, indexMap[key]!! - 1, handler)
}
}

View File

@@ -65,7 +65,7 @@ class BTeXTest : ApplicationAdapter() {
println("Time spent on typesetting [ms]: $it")
}
measureTimeMillis {
/*measureTimeMillis {
document.finalise()
documentHandler.dispose()
}.also {
@@ -76,7 +76,7 @@ class BTeXTest : ApplicationAdapter() {
document.serialise(File("./assets/mods/basegame/books/${filePath.replace(".xml", ".btxbook")}"))
}.also {
println("Time spent on serialisation [ms]: $it")
}
}*/
}
else {
measureTimeMillis {
@@ -114,6 +114,10 @@ class BTeXTest : ApplicationAdapter() {
scroll = (scroll - 2).coerceAtLeast(0)
else if (Gdx.input.isKeyJustPressed(Input.Keys.RIGHT))
scroll = (scroll + 2).coerceAtMost(document.pageIndices.endInclusive.toFloat().div(2f).ceilToInt().times(2))
else if (Gdx.input.isKeyJustPressed(Input.Keys.PAGE_UP))
scroll = 0
else if (Gdx.input.isKeyJustPressed(Input.Keys.PAGE_DOWN))
scroll = document.pageIndices.endInclusive.toFloat().div(2f).ceilToInt().times(2)
}