btex: serialise now saves original xml

This commit is contained in:
minjaesong
2024-05-23 19:06:32 +09:00
parent 87ff1abe96
commit 32991b7ba8
6 changed files with 25 additions and 5 deletions

View File

@@ -62,6 +62,8 @@ class BTeXDocument : Disposable {
val indexTable = HashMap<String, Int>()
internal var inputXML: String? = null
companion object {
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
// val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
@@ -84,6 +86,9 @@ class BTeXDocument : Disposable {
val ra = RandomAccessFile(file, "r")
val DOM = ClusteredFormatDOM(ra)
val xml = Clustfile(DOM, "/src.xml")
doc.inputXML = xml.readBytes().toString(Common.CHARSET)
// get meta file
val meta = Clustfile(DOM, "/bibliography.json")
if (!meta.exists()) throw IllegalStateException("No bibliography.json found on the archive")
@@ -126,6 +131,8 @@ class BTeXDocument : Disposable {
}
}
// TODO read hrefs.json
ra.close()
return doc
@@ -227,12 +234,19 @@ class BTeXDocument : Disposable {
}
}
fun serialise(viewer: BTeXDocViewer,archiveFile: File) {
fun serialise(viewer: BTeXDocViewer, archiveFile: File) {
if (!isFinalised) throw IllegalStateException("Document must be finalised before being serialised")
val diskFile = ClusteredFormatDOM.createNewArchive(archiveFile, Common.CHARSET, "", 0x7FFFF)
val DOM = ClusteredFormatDOM(diskFile)
inputXML?.let { xmlstr ->
Clustfile(DOM, "src.xml").also {
it.createNewFile()
it.writeBytes(xmlstr.toByteArray(Common.CHARSET))
}
}
val json = """
{
"title":"${theTitle.escape()}",

View File

@@ -16,6 +16,7 @@ import net.torvald.terrarum.btex.*
import net.torvald.terrarum.btex.BTeXDocument.Companion.DEFAULT_ORNAMENTS_COL
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarumsansbitmap.MovableType
import net.torvald.terrarumsansbitmap.TypesettingStrategy
@@ -54,6 +55,7 @@ object BTeXParser {
it.isValidating = true
it.newSAXParser()
}
doc.inputXML = file.readText(Common.CHARSET)
val stream = FileInputStream(file)
val handler = BTeXHandler(doc, varMap, progressIndicator)
parser.parse(stream, handler)
@@ -67,6 +69,7 @@ object BTeXParser {
it.isValidating = true
it.newSAXParser()
}
doc.inputXML = string
val handler = BTeXHandler(doc, varMap, progressIndicator)
parser.parse(InputSource(StringReader(string)), handler)
return doc to handler

View File

@@ -32,13 +32,13 @@ import kotlin.system.measureTimeMillis
*/
class BTeXTest : ApplicationAdapter() {
// val filePath = "btex.xml"
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/ruRU/anton_chekhov_palata_no_6.xml"
// val filePath = "literature/koKR/yisang_nalgae.xml"
val filePath = "literature/koKR/yisang_geonchukmuhanyukmyeongakche.xml"
// val filePath = "literature/koKR/yisang_geonchukmuhanyukmyeongakche.xml"
private lateinit var document: BTeXDocument