part/chapter type macros

This commit is contained in:
minjaesong
2024-05-14 17:10:43 +09:00
parent 1c86162ff8
commit fc69c6f5b7
5 changed files with 43 additions and 14 deletions

View File

@@ -109,7 +109,7 @@
<li><index id="part (tag)"/><code>part</code> — inserts part separation page to your book</li>
<li><index id="chapter (tag)"/><index id="section (tag)"/><code>chapter</code>, <code>section</code> — inserts a new chapter/section. If an alternative name is required on the Table of Contents, the <code>alt</code> attribute can be used. If the chapter/section needs to be hidden on the Table of Contents, add the <code>hide="1"</code> attribute. If the chapter must start on a new page, simply add <code>newpage</code> in front of the chapter tag</li>
<li><index id="p (tag)"/><code>p</code> — 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 <code>p</code> of the part/chapter/section; first <code>p</code> after <code>br</code>, <code>newpage</code>, <code>callout</code>, <code>ul</code>, <code>ol</code> or <code>anonbreak</code></li>
<li><index id="span (tag)"/><code>span</code> — allows changing the colour or the style of the texts. The colour must be specified in the <code>colour</code> 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</li>
<li><index id="span (tag)"/><code>span</code> — allows changing the colour or the style of the texts. The colour must be specified in the <code>colour</code> attribute. Six-digit hex code, three-digit hex code and CSS Colours Level 4 named colours are supported. Note that all the colours will be rounded to the nearest three-digit hex code</li>
<li><index id="emph (tag)"/><code>emph</code> — is a special case of the <code>span</code> tag. The resulting text will be <emph>red</emph></li>
<li><index id="itemname (tag)"/><code>itemname</code> — is a special case of the <code>span</code> tag used to highlight the name of the ingame item. The resulting text will be <itemname>blue</itemname></li>
<li><index id="targetname (tag)"/><code>targetname</code> — is a special case of the <code>span</code> tag used to highlight the name of an arbitrary target or goals. The resulting text will be <targetname>green</targetname></li>
@@ -211,14 +211,22 @@
<ul>
<li><code>thepart</code> — Part heading. Default: <code>Part %1$s</code></li>
<li><code>parttype</code> — Default style of the <code>part</code> tag. Default: <code>I</code></li>
<li><code>thechapter</code> — Chapter heading. Default: <code>%1$s</code></li>
<li><code>parttype</code> — Default style of the <code>chapter</code> tag. Default: <code>1</code></li>
</ul>
<p>The argument key <code>%1$s</code> will be replaced into a number, Roman numerals, etc.
depending on the value of <code>type</code> attribute.</p>
<p>These macros can be used to localise the chapter headings for your language. For example,
in Korean text, you might want to change <code>thechapter</code> into <code>%1$s장</code>.</p>
in Korean text, the following idiomatic definition will be useful:</p>
<callout align="left" class="code">&lt;macrodef&gt;<br/><!--
-->  &lt;pair key="thepart" value="제%1$s부"/&gt;<br/><!--
-->  &lt;pair key="parttype" value="1"/&gt;<br/><!--
-->  &lt;pair key="thechapter" value="%1$s장"/&gt;<br/><!--
-->&lt;/macrodef&gt;</callout>
<chapter>Printing External Variables</chapter>

View File

@@ -3,6 +3,7 @@
<btexdoc cover="hardcover" inner="standard" papersize="standard">
<macrodef>
<pair key="thepart" value="제%1$s부"/>
<pair key="parttype" value="1"/>
<pair key="thechapter" value="%1$s장"/>
</macrodef>
<cover>
@@ -15,7 +16,7 @@
<tocpage title="목차"><tableofcontents/></tocpage>
<manuscript>
<part type="1"></part>
<part></part>
<chapter>책이란 무엇인가</chapter>
@@ -40,7 +41,7 @@
<p><btex/>을 통하며 책 전체의 생김새를 간단히 기술할 수 있다. 사용할 수 있는 스타일은 조판 시스템이 지원하는 범위 안에서 제약이 없다. 타자기로 찍어낸 듯한 글도 원한다면 얼마든지 인쇄되도록 할 수 있다.</p>
<part type="1"><btex/></part>
<part><btex/></part>
<chapter>소개</chapter>
@@ -104,7 +105,7 @@
<li><index id="part (태그)"/><code>part</code> — 원고에 새 부(part)를 추가함</li>
<li><index id="chapter (태그)"/><index id="section (태그)"/><code>chapter</code>, <code>section</code> — 원고에 새 장(chapter)·절(section)을 추가함. 목차 페이지에는 다른 이름을 표시하고 싶다면 <code>alt</code> 속성을 사용할 수 있음. 목차 페이지에서 숨기고 싶다면 <code>hide="1"</code> 속성을 추가할 것. 장이 새 페이지에서 시작되게 하려면 <code>chapter</code> 태그 앞에 <code>newpage</code>를 추가할 것</li>
<li><index id="p (태그)"/><code>p</code> — 새 문단을 삽입함. 본문의 글은 반드시 이 태그 내부에 작성되어야 함. 모든 문단는 16픽셀의 들여쓰기로 조판되나, 다음의 경우 들여쓰기가 적용되지 않음: 부·장·절의 첫 문단, <code>br</code>, <code>newpage</code>, <code>callout</code>, <code>ul</code>, <code>ol</code>, <code>anonbreak</code> 태그 직후의 문단</li>
<li><index id="span (태그)"/><code>span</code> — 문구의 색상이나 스타일을 변경함. 색상은 <code>colour</code> 속성에 작성되어야 함. 6자리 헥스코드, 3자리 헥스코드, CSS Colour Level 4에 정의된 색상명을 사용할 수 있음. 모든 색상은 내부적으로 가장 가까운 3자리 헥스코드로 변경됨에 유의할 것</li>
<li><index id="span (태그)"/><code>span</code> — 문구의 색상이나 스타일을 변경함. 색상은 <code>colour</code> 속성에 작성되어야 함. 6자리 헥스코드, 3자리 헥스코드, CSS Colours Level 4에 정의된 색상명을 사용할 수 있음. 모든 색상은 내부적으로 가장 가까운 3자리 헥스코드로 변경됨에 유의할 것</li>
<li><index id="emph (태그)"/><code>emph</code><code>span</code>의 특수한 경우로, 문구를 <emph>빨간색으로</emph> 인자함</li>
<li><index id="itemname (태그)"/><code>itemname</code><code>span</code>의 특수한 경우로, 게임 내 아이템의 이름을 강조 표시할 때 사용함. 문구는 <itemname>파란색으로</itemname> 인자됨</li>
<li><index id="targetname (태그)"/><code>targetname</code><code>span</code>의 특수한 경우로, 임의의 목표를 강조 표시할 때 사용함. 문구는 <targetname>초록색으로</targetname> 인자됨</li>
@@ -178,7 +179,7 @@
<part>고급 매크로</part>
<part type="1">고급 매크로</part>
<chapter>매크로 정의문</chapter>
@@ -198,13 +199,20 @@
<ul>
<li><code>thepart</code> — 부 제목 번호. 기본값: <code>Part %1$s</code></li>
<li><code>parttype</code><code>part</code> 태그의 기본 스타일. 기본값: <code>I</code></li>
<li><code>thechapter</code> — 장 제목 번호. 기본값: <code>%1$s</code></li>
<li><code>parttype</code><code>chapter</code> 태그의 기본 스타일. 기본값: <code>1</code></li>
</ul>
<p>매개변수인 <code>%1$s</code>는 각 제목의 <code>type</code> 속성에 따라 적절한 숫자로 치환된다.</p>
<p>이 매크로는 장제목을 원하는 언어의 스타일로 변경하는 데에 사용될 수 있다. 예를 들면 한국어 환경에서는 <code>thechapter</code><code>%1$s장</code>으로 정의하는 것이 되겠다.</p>
<p>이 매크로는 장제목을 원하는 언어의 스타일로 변경하는 데에 사용될 수 있다. 예를 들면 한국어 환경에서는 다음과 같은 정의가 바람직할 것이다.</p>
<callout align="left" class="code">&lt;macrodef&gt;<br/><!--
-->  &lt;pair key="thepart" value="제%1$s부"/&gt;<br/><!--
-->  &lt;pair key="parttype" value="1"/&gt;<br/><!--
-->  &lt;pair key="thechapter" value="%1$s장"/&gt;<br/><!--
-->&lt;/macrodef&gt;</callout>
<chapter>외부 변수 인자하기</chapter>

View File

@@ -150,6 +150,8 @@ class BTeXDocument : Disposable {
if (fromArchive) throw IllegalStateException("Document is loaded from the archive and thus cannot be finalised")
if (isFinalised) throw IllegalStateException("Page is already been finalised")
// TODO serialise and finalise via CPU (store every page as Pixmap)
pageTextures = ArrayList()
pageFrameBuffers = ArrayList()

View File

@@ -122,6 +122,7 @@ object BTeXParser {
private var coverCol: Color? = null
private lateinit var testFont: TerrarumSansBitmap
private lateinit var partTitleFont: TerrarumSansBitmap
private lateinit var titleFont: TerrarumSansBitmap
private lateinit var subtitleFont: TerrarumSansBitmap
@@ -129,7 +130,9 @@ object BTeXParser {
private val macrodefs = hashMapOf(
"thepart" to "Part %1\$s",
"thechapter" to "%1\$s"
"parttype" to "I",
"thechapter" to "%1\$s",
"chaptertype" to "1"
)
private fun invokeMacro(name: String, vararg args: String): String {
@@ -211,6 +214,7 @@ object BTeXParser {
fun dispose() {
if (::testFont.isInitialized) testFont.tryDispose()
if (::titleFont.isInitialized) titleFont.tryDispose()
if (::partTitleFont.isInitialized) partTitleFont.tryDispose()
if (::subtitleFont.isInitialized) subtitleFont.tryDispose()
}
@@ -359,6 +363,13 @@ object BTeXParser {
}
}
private fun getPartTitleFont(): TerrarumSansBitmap {
if (!::partTitleFont.isInitialized) partTitleFont = TerrarumSansBitmap(App.FONT_DIR, shadowAlpha = bodyTextShadowAlpha).also {
it.interchar = 1
}
return partTitleFont
}
private fun getTitleFont(): TerrarumSansBitmap {
if (!::titleFont.isInitialized) titleFont = TerrarumSansBitmap(App.FONT_DIR).also {
it.interchar = 1
@@ -1119,18 +1130,18 @@ object BTeXParser {
clearParBuffer()
if (attribs["hide"] == null)
cptSectStack.add(CptSect("part", attribs["alt"], attribs["type"] ?: "I", attribs["start"]?.toInt()))
cptSectStack.add(CptSect("part", attribs["alt"], attribs["type"] ?: macrodefs["parttype"]!!, attribs["start"]?.toInt()))
else
cptSectStack.add(CptSect("part-hidden", attribs["alt"], attribs["type"] ?: "I", attribs["start"]?.toInt()))
cptSectStack.add(CptSect("part-hidden", attribs["alt"], attribs["type"] ?: macrodefs["parttype"]!!, attribs["start"]?.toInt()))
}
@OpenTag // reflective access is impossible with 'private'
fun processElemCHAPTER(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
clearParBuffer()
if (attribs["hide"] == null)
cptSectStack.add(CptSect("chapter", attribs["alt"], attribs["type"] ?: "1", attribs["start"]?.toInt()))
cptSectStack.add(CptSect("chapter", attribs["alt"], attribs["type"] ?: macrodefs["chaptertype"]!!, attribs["start"]?.toInt()))
else
cptSectStack.add(CptSect("chapter-hidden", attribs["alt"], attribs["type"] ?: "1", attribs["start"]?.toInt()))
cptSectStack.add(CptSect("chapter-hidden", attribs["alt"], attribs["type"] ?: macrodefs["chaptertype"]!!, attribs["start"]?.toInt()))
}
@OpenTag // reflective access is impossible with 'private'
fun processElemSECTION(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
@@ -1304,7 +1315,7 @@ object BTeXParser {
private fun typesetPartHeading(num: String, thePar: String, handler: BTeXHandler, indent: Int = PAR_INDENTATION, width: Int = doc.textWidth) {
typesetParagraphs("${ccDefault} $num ", handler, align = "left")
typesetParagraphs(" ", handler, align = "left")
typesetParagraphs(getSubtitleFont(), "$ccDefault$thePar", handler, align = "left")
typesetParagraphs(getPartTitleFont(), "$ccDefault$thePar", handler, align = "left")
// get global yDelta
doc.currentPageObj.let { page ->

View File

@@ -24,7 +24,7 @@ import kotlin.system.measureTimeMillis
*/
class BTeXTest : ApplicationAdapter() {
val filePath = "btex.xml"
val filePath = "btex_ko.xml"
// val filePath = "test.xml"
// val filePath = "literature/en/daniel_defoe_robinson_crusoe.btxbook"
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"