From 92a4084e95ae9a513f5da46719918e0481775f63 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 4 May 2024 05:10:44 +0900 Subject: [PATCH] DTD for btexdoc --- assets/mods/basegame/books/test.xml | 178 +++++++++++++++++++++ btexdoc.dtd | 121 ++++++++++++++ lib/TerrarumSansBitmap.jar | 4 +- src/net/torvald/btex/BTeXParser.kt | 13 +- src/net/torvald/terrarum/tests/BTeXTest.kt | 3 +- 5 files changed, 310 insertions(+), 9 deletions(-) create mode 100644 assets/mods/basegame/books/test.xml create mode 100644 btexdoc.dtd diff --git a/assets/mods/basegame/books/test.xml b/assets/mods/basegame/books/test.xml new file mode 100644 index 000000000..87723c902 --- /dev/null +++ b/assets/mods/basegame/books/test.xml @@ -0,0 +1,178 @@ + + + The Way to Mastery of<br />Lorem Ipsum + Or, How To Write and Publish a Book + Terran Publishing + Test Edition + + + + + + The Book + + What Is a Book + +

This example book is written to give readers the example of the Book Language.

+ +
What Qualifies as a Book
+ +

Under the book typesetting system, a Book is a collection of texts typesetted for an improved + legibility, enumerable pages, with insertion of other helpful resources such as illustrations + and hyperlinks.

+

Books are considered as bound and always presented in two pages for reading.

+ + Writing a Book Using a Typewriter + +

Typewriter allows quick scribbling of the words in convenient manners, just click on them and get + writing!

+

But it comes with big downsides: you cannot type in multiple writing systems, cannot have defined + chapters and sections, cannot include any illustrations, no hyperlinks, and of course, ragged texts.

+

Typed papers are considered as non-bound and only one page at a time will be presented.

+

All in all, you cannot write a true Book using a typewriter.

+ + Writing a Book with Publishers and Printing Presses + +

Professional-looking texts, with all the benefits of a real Book can be made, or even mass-produced + easily with the help of publishers.

+

To have your precious texts to be printed, you must send your manuscripts to a publisher, and the + manuscript must be written in a special language: the .

+

allows concise description of the entire shape of your book, any style the book typesetting + system can support can be described and printing presses will produce the papers accordingly. + You can even try to mimic the look and feel of papers created using a typewriter, if you want to.

+ + + The + + Introduction + +

is a markup language based on XML, with a resemblance of the . + 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.

+ + + The Style Declaration + +

The Style Declaration is the very first line of a document. Its syntax is as follows:

+ + + + <btexdoc cover="hardcover" inner="standard" papersize="standard"> + + +

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
  • +
  • papersize — defines the size of the paper. Possible values: standard
  • +
+ + The Cover + +

The Cover defines the text on the cover of the book. If your text has no cover, this part can be omitted. Its syntax is as follows:

+ + + + + + + <cover> +   <title>Title of your book</title> +   <subtitle>Subtitle if necessary</subtitle> +   <author>Who wrote this book</author> +   <edition>Edition information if necessary</edition> + </cover> + +

Only the title tag is mandatory. Cover texts will be printed using a special font that has wider + gaps between characters. The title text will be printed in a double-size.

+ + + The Table of Contents + +

The contents of the Table of Contents is filled in automatically by reading through your manuscript; + parts, chapters and sections will be added. Its syntax is as follows:

+ + + + <tocpage title="Custom page name if necessary"><tableofcontents /></tocpage> + + +

The optional title attribute allows a custom name can be given to this page. + If unspecified, the default name is “Table of Contents”.

+

The tag <tableofcontents /> is an internal tag used by the typesetter.

+ + + The Manuscript + +

This is the part where you actually write your body texts in. The body text can have the following tags:

+
    +
  • part — inserts part separation page to your book
  • +
  • chapter, section — inserts a new chapter/section. If an alternative name is required on the Table of Contents, the alt attribute can be used. If the chapter/section needs to be hidden on the Table of Contents, add the hide="1" attribute. If the chapter must start on a new page, simply add newpage in front of the chapter tag
  • +
  • p — inserts a new paragraph. The body texts must be written inside this tag. All paragraphs will have a 16-pixel indentation, with the following exceptions: first p of the part/chapter/section; first p after br, newpage, pbox, ul, ol or anonbreak
  • +
  • span — allows changing the colour of the texts. The colour must be specified in the colour attribute. Six-digit hex code, three-digit hex code and CSS Colors Level 4 named colours are supported. Note that all the colours will be rounded to the nearest three-digit hex code
  • +
  • emph — is a special case of the span tag. The resulting text will be red
  • +
  • itemname — is a special case of the span tag used to highlight the name of the ingame item. The resulting text will be blue
  • +
  • targetname — is a special case of the span tag used to highlight the name of an arbitrary target or goals. The resulting text will be green
  • +
  • code — is a special case of the span tag used to highlight the code element in-line. The resulting text will be surrounded in a grey box
  • +
  • br — self-closing tag; inserts an anonymous line break
  • +
  • newpage — self-closing tag; inserts an anonymous page break
  • +
  • anonbreak — self-closing tag; inserts a paragraph break in the text. The break will be in a form of a long straight line on the centre of the text. Useful for typesetting novels
  • +
  • pbox — is a paragraph box that holds a text in a grey box, a style similar to the code tag
  • +
  • ul — starts an unordered list. List elements are defined using the li tag
  • +
  • ol — starts an ordered list. List elements are defined using the li tag
  • +
  • fullpagebox — is used to typeset its child tags into a box that fills an entire page, with its contents centred on the page. Must be used after the newpage
  • +
  • btex — self-closing tag; inserts an inline form of the logo in the text
  • +
+

Self-closing tags have no child tags. To use a self-closing tag, simply do <tagname />.

+ + +
Hyperlinking
+ +

Hyperlinks can be defined using index and a tags.

+
    +
  • index — will define a target for a link. Indices require a unique identifier to work as a link, and the identifier must be defined in the id attribute
  • +
  • a — will make its child texts to be clickable. The link target (index identifier) must be defined in the href attribute
  • +
+ + The Index Page + +

The contents of the Index Page is filled in automatically by reading through your manuscript. + All the usage of index tags will be shown here. Its syntax is as follows:

+ + + + <indexpage title="Custom page name if necessary"><tableofindices /></indexpage> + + +

The optional title attribute allows a custom name can be given to this page. If unspecified, + the default name is “Index”.

+ + + Ending the Document + +

The document must begin with the opening btexdoc tag, and therefore must + end with a matching closing tag. Simply write away </btexdoc> and the + document is finished.

+ + + Conclusion + +

The finished book description using can be sent to a publisher, and if there are no errors + on your submission, the printed books of specified number of copies will be delivered to your + location within a reasonable amount of business days. Happy writing!

+ + + + +

this page is intentionally left blank

+
+ +
+ + +
diff --git a/btexdoc.dtd b/btexdoc.dtd new file mode 100644 index 000000000..387d259e9 --- /dev/null +++ b/btexdoc.dtd @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/TerrarumSansBitmap.jar b/lib/TerrarumSansBitmap.jar index 80eded83d..ca03cd4f2 100644 --- a/lib/TerrarumSansBitmap.jar +++ b/lib/TerrarumSansBitmap.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:82f10fc3ef4ab42fb87502b3cf309fb0bde8b4b45ec214be70a9c6f826862b3d -size 226415 +oid sha256:6509a3c37695401b3026865683fb2f54f715d81168f497dbd938b479fff3c3d9 +size 199551 diff --git a/src/net/torvald/btex/BTeXParser.kt b/src/net/torvald/btex/BTeXParser.kt index f6225fe1c..fc6474f1f 100644 --- a/src/net/torvald/btex/BTeXParser.kt +++ b/src/net/torvald/btex/BTeXParser.kt @@ -226,8 +226,8 @@ object BTeXParser { override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) { val tag = qName - if (tagStack.isEmpty() && tag.lowercase() != "btexdoc") throw BTeXParsingException("Document is not BTeX") val theTag = tag.uppercase() + if (tagStack.isEmpty() && theTag != "BTEXDOC") throw BTeXParsingException("Document is not BTeX") if (tagStack.isNotEmpty() && tagStack.any { textTags.contains(it) } && textTags.contains(theTag)) throw IllegalStateException("Text tag '$theTag' used inside of text tags (tag stack is ${tagStack.joinToString()}, $theTag)") @@ -284,6 +284,7 @@ object BTeXParser { private var oldSpanColour: String? = null private var oldCodeMode = false + private val CODE_TAG_MARGIN = 2 override fun characters(ch: CharArray, start: Int, length: Int) { var str = @@ -310,17 +311,17 @@ object BTeXParser { // process code request if (codeMode != oldCodeMode || codeMode) { - println("CODE tag for str '$str'") - - str = CodepointSequence(listOf(0xF901D, 0xF901D, 0xF901D)).toUTF8Bytes().decodeToString() if (!codeMode) { paragraphBuffer.append(TerrarumSansBitmap.charsetOverrideDefault) + paragraphBuffer.append(glueToString(CODE_TAG_MARGIN)) } else { - val w = getFont().getWidth(str) + println("CODE tag for str '$str'") + val w = getFont().getWidth(str) + 2*CODE_TAG_MARGIN getOrPutCodeTagRef(w) - paragraphBuffer.appendObjectPlaceholder("TAG@CODE-$w") + paragraphBuffer.appendObjectPlaceholder("TAG@CODE-${w}") + paragraphBuffer.append(glueToString(CODE_TAG_MARGIN)) paragraphBuffer.append(TerrarumSansBitmap.charsetOverrideCodestyle) } } diff --git a/src/net/torvald/terrarum/tests/BTeXTest.kt b/src/net/torvald/terrarum/tests/BTeXTest.kt index f1b6f5831..a5cb1aa79 100644 --- a/src/net/torvald/terrarum/tests/BTeXTest.kt +++ b/src/net/torvald/terrarum/tests/BTeXTest.kt @@ -26,7 +26,8 @@ import kotlin.system.measureTimeMillis */ class BTeXTest : ApplicationAdapter() { - val filePath = "btex.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"