From d758c79289d762614e16b3777755993cbb4cd6e6 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 7 May 2024 05:46:16 +0900 Subject: [PATCH] more XML --- assets/mods/basegame/books/btex.xml | 12 ++++--- btexdoc.dtd | 35 +++++++++++++------ src/net/torvald/btex/BTeXParser.kt | 40 ++++++++++++++++++---- src/net/torvald/terrarum/tests/BTeXTest.kt | 4 +-- 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/assets/mods/basegame/books/btex.xml b/assets/mods/basegame/books/btex.xml index 87723c902..316fd94b5 100644 --- a/assets/mods/basegame/books/btex.xml +++ b/assets/mods/basegame/books/btex.xml @@ -1,3 +1,4 @@ + The Way to Mastery of<br />Lorem Ipsum @@ -50,10 +51,10 @@ abstracts away the meticulous styling and typesetting configurations, so you can focus on actually writing your texts than debugging the macros. This does come with a downside of not being able to change the given style.

-

document is divided up to five parts: the Style Declaration, the - Cover, the Table of Contents, the - Manuscript, and the Index Page. Of which the - Style Declaration and the Manuscript is the mandatory parts.

+

document is divided up to five parts: the Style Declaration, the + Cover, the Table of Contents, the + Manuscript, and the Index Page, of which the + Style Declaration and the Manuscript are the mandatory parts.

The Style Declaration @@ -65,7 +66,8 @@ <btexdoc cover="hardcover" inner="standard" papersize="standard"> -

The btexdoc tag takes three attributes: cover, inner and papersize.

+

The btexdoc tag takes three attributes:
+ cover, inner and papersize.

  • cover — changes the style of the cover. Possible values: hardcover, none
  • inner — changes the style of the body. Possible values: standard, typewriter
  • diff --git a/btexdoc.dtd b/btexdoc.dtd index 8086fe8b1..427c7095b 100644 --- a/btexdoc.dtd +++ b/btexdoc.dtd @@ -2,31 +2,36 @@ - + - + + + + + - + @@ -52,10 +57,10 @@ - - - - + + + + @@ -98,11 +103,15 @@ - + - + @@ -124,4 +133,10 @@ %attrs; type %LIStyle; #IMPLIED value %Number; #IMPLIED + > + + + \ No newline at end of file diff --git a/src/net/torvald/btex/BTeXParser.kt b/src/net/torvald/btex/BTeXParser.kt index 21abe5ad5..d092c7138 100644 --- a/src/net/torvald/btex/BTeXParser.kt +++ b/src/net/torvald/btex/BTeXParser.kt @@ -90,6 +90,7 @@ object BTeXParser { private var currentTheme = "" private var spanColour: String? = null private var codeMode: Boolean = false + private var hrefMode: Boolean = false private var bucksMode: Boolean = false @@ -189,7 +190,7 @@ object BTeXParser { } } - private fun getOrPutCodeTagRef(width: Int): ((BTeXDrawCall) -> BTeXBatchDrawCall)? { + /*private fun getOrPutCodeTagRef(width: Int): ((BTeXDrawCall) -> BTeXBatchDrawCall)? { val tagname = "TAG@CODE-$width" if (!objDict.contains(tagname)) { objWidthDict[tagname] = 0 @@ -207,7 +208,7 @@ object BTeXParser { } } return objDict[tagname] - } + }*/ fun dispose() { if (::testFont.isInitialized) testFont.tryDispose() @@ -309,6 +310,7 @@ object BTeXParser { private var oldSpanColour: String? = null private var oldCodeMode = false + private var oldHrefMode = false private var oldBucksMode = false private val CODE_TAG_MARGIN = 2 @@ -339,18 +341,30 @@ object BTeXParser { if (codeMode != oldCodeMode || codeMode) { if (!codeMode) { paragraphBuffer.append(TerrarumSansBitmap.charsetOverrideDefault) + paragraphBuffer.append(ccDefault) paragraphBuffer.append(glueToString(CODE_TAG_MARGIN)) } else { // println("CODE tag for str '$str'") - val w = getFont().getWidth(str) + 2*CODE_TAG_MARGIN - getOrPutCodeTagRef(w) - paragraphBuffer.appendObjectPlaceholder("TAG@CODE-${w}") +// val w = getFont().getWidth(str) + 2*CODE_TAG_MARGIN +// getOrPutCodeTagRef(w) +// paragraphBuffer.appendObjectPlaceholder("TAG@CODE-${w}") paragraphBuffer.append(glueToString(CODE_TAG_MARGIN)) + paragraphBuffer.append(ccCode) paragraphBuffer.append(TerrarumSansBitmap.charsetOverrideCodestyle) } } + // process href request + if (hrefMode != oldHrefMode || hrefMode) { + if (!hrefMode) { + paragraphBuffer.append(ccDefault) + } + else { + paragraphBuffer.append(ccHref) + } + } + // process bucks request if (bucksMode != oldBucksMode || bucksMode) { if (!bucksMode) { @@ -369,6 +383,7 @@ object BTeXParser { oldSpanColour = spanColour oldCodeMode = codeMode + oldHrefMode = hrefMode oldBucksMode = bucksMode } } @@ -618,7 +633,7 @@ object BTeXParser { ) private val ccEmph = "#C11"// TerrarumSansBitmap.toColorCode(0xfd44) - private val ccItemName = "#14C" // TerrarumSansBitmap.toColorCode(0xf37d) + private val ccItemName = "#03B" // TerrarumSansBitmap.toColorCode(0xf37d) private val ccTargetName = "#170" // TerrarumSansBitmap.toColorCode(0xf3c4) @OpenTag // reflective access is impossible with 'private' @@ -726,6 +741,15 @@ object BTeXParser { handler.codeMode = false } + @OpenTag // reflective access is impossible with 'private' + fun processElemA(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + handler.hrefMode = true + } + @CloseTag + fun closeElemA(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) { + handler.hrefMode = false + } + @OpenTag // reflective access is impossible with 'private' fun processElemBUCKS(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { handler.bucksMode = true @@ -830,7 +854,7 @@ object BTeXParser { val heading = if (part == null && cpt == null && sect == null) "" else if (part != null && cpt == null && sect == null) - "Part ${part.toRomanNum()}.${glueToString(9)}" + "Part ${part.toRomanNum()}${glueToString(9)}" else listOfNotNull(cpt, sect).joinToString(".") + "${glueToString(9)}" + (if (cpt != null && cpt < 10) "${glueToString(9)}" else "") @@ -1408,6 +1432,8 @@ object BTeXParser { companion object { val ccDefault = TerrarumSansBitmap.toColorCode(0,0,0) val ccBucks = TerrarumSansBitmap.toColorCode(4,0,0) + val ccCode = TerrarumSansBitmap.toColorCode(0,5,7) + val ccHref = TerrarumSansBitmap.toColorCode(0,3,11) private const val ZWSP = 0x200B private const val SHY = 0xAD diff --git a/src/net/torvald/terrarum/tests/BTeXTest.kt b/src/net/torvald/terrarum/tests/BTeXTest.kt index fb0467649..8594dac0e 100644 --- a/src/net/torvald/terrarum/tests/BTeXTest.kt +++ b/src/net/torvald/terrarum/tests/BTeXTest.kt @@ -26,8 +26,8 @@ import kotlin.system.measureTimeMillis */ class BTeXTest : ApplicationAdapter() { -// val filePath = "btex.xml" - val filePath = "test.xml" + val filePath = "btex.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.btexbin"