mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
btex: serialise now saves original xml
This commit is contained in:
BIN
assets/graphics/fonts/terrarum-sans-bitmap/cjkpunct_variable.tga
LFS
Normal file
BIN
assets/graphics/fonts/terrarum-sans-bitmap/cjkpunct_variable.tga
LFS
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -62,6 +62,8 @@ class BTeXDocument : Disposable {
|
|||||||
|
|
||||||
val indexTable = HashMap<String, Int>()
|
val indexTable = HashMap<String, Int>()
|
||||||
|
|
||||||
|
internal var inputXML: String? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
|
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
|
||||||
// val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
// val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
||||||
@@ -84,6 +86,9 @@ class BTeXDocument : Disposable {
|
|||||||
val ra = RandomAccessFile(file, "r")
|
val ra = RandomAccessFile(file, "r")
|
||||||
val DOM = ClusteredFormatDOM(ra)
|
val DOM = ClusteredFormatDOM(ra)
|
||||||
|
|
||||||
|
val xml = Clustfile(DOM, "/src.xml")
|
||||||
|
doc.inputXML = xml.readBytes().toString(Common.CHARSET)
|
||||||
|
|
||||||
// get meta file
|
// get meta file
|
||||||
val meta = Clustfile(DOM, "/bibliography.json")
|
val meta = Clustfile(DOM, "/bibliography.json")
|
||||||
if (!meta.exists()) throw IllegalStateException("No bibliography.json found on the archive")
|
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()
|
ra.close()
|
||||||
|
|
||||||
return doc
|
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")
|
if (!isFinalised) throw IllegalStateException("Document must be finalised before being serialised")
|
||||||
|
|
||||||
val diskFile = ClusteredFormatDOM.createNewArchive(archiveFile, Common.CHARSET, "", 0x7FFFF)
|
val diskFile = ClusteredFormatDOM.createNewArchive(archiveFile, Common.CHARSET, "", 0x7FFFF)
|
||||||
val DOM = ClusteredFormatDOM(diskFile)
|
val DOM = ClusteredFormatDOM(diskFile)
|
||||||
|
|
||||||
|
inputXML?.let { xmlstr ->
|
||||||
|
Clustfile(DOM, "src.xml").also {
|
||||||
|
it.createNewFile()
|
||||||
|
it.writeBytes(xmlstr.toByteArray(Common.CHARSET))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
"title":"${theTitle.escape()}",
|
"title":"${theTitle.escape()}",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import net.torvald.terrarum.btex.*
|
|||||||
import net.torvald.terrarum.btex.BTeXDocument.Companion.DEFAULT_ORNAMENTS_COL
|
import net.torvald.terrarum.btex.BTeXDocument.Companion.DEFAULT_ORNAMENTS_COL
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
|
import net.torvald.terrarum.serialise.Common
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarumsansbitmap.MovableType
|
import net.torvald.terrarumsansbitmap.MovableType
|
||||||
import net.torvald.terrarumsansbitmap.TypesettingStrategy
|
import net.torvald.terrarumsansbitmap.TypesettingStrategy
|
||||||
@@ -54,6 +55,7 @@ object BTeXParser {
|
|||||||
it.isValidating = true
|
it.isValidating = true
|
||||||
it.newSAXParser()
|
it.newSAXParser()
|
||||||
}
|
}
|
||||||
|
doc.inputXML = file.readText(Common.CHARSET)
|
||||||
val stream = FileInputStream(file)
|
val stream = FileInputStream(file)
|
||||||
val handler = BTeXHandler(doc, varMap, progressIndicator)
|
val handler = BTeXHandler(doc, varMap, progressIndicator)
|
||||||
parser.parse(stream, handler)
|
parser.parse(stream, handler)
|
||||||
@@ -67,6 +69,7 @@ object BTeXParser {
|
|||||||
it.isValidating = true
|
it.isValidating = true
|
||||||
it.newSAXParser()
|
it.newSAXParser()
|
||||||
}
|
}
|
||||||
|
doc.inputXML = string
|
||||||
val handler = BTeXHandler(doc, varMap, progressIndicator)
|
val handler = BTeXHandler(doc, varMap, progressIndicator)
|
||||||
parser.parse(InputSource(StringReader(string)), handler)
|
parser.parse(InputSource(StringReader(string)), handler)
|
||||||
return doc to handler
|
return doc to handler
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ import kotlin.system.measureTimeMillis
|
|||||||
*/
|
*/
|
||||||
class BTeXTest : ApplicationAdapter() {
|
class BTeXTest : ApplicationAdapter() {
|
||||||
|
|
||||||
// val filePath = "btex.xml"
|
val filePath = "btex.xml"
|
||||||
// val filePath = "btex_ko.xml"
|
// val filePath = "btex_ko.xml"
|
||||||
// val filePath = "test.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/ruRU/anton_chekhov_palata_no_6.xml"
|
||||||
// val filePath = "literature/koKR/yisang_nalgae.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
|
private lateinit var document: BTeXDocument
|
||||||
|
|||||||
Reference in New Issue
Block a user