fix: btex toc overflow

This commit is contained in:
minjaesong
2024-05-16 13:35:36 +09:00
parent b963e0d3f2
commit e308e9a356
4 changed files with 29 additions and 5 deletions

View File

@@ -160,6 +160,24 @@
</ul>
<section>Figures</section>
<p>Figures, or external images can be inserted using the self-closing <code>img</code> tag.
This tag inserts the image starting from the current line; if the size is taller than the
remaining lines, the image will be printed onto the next page. Its syntax is as follows:</p>
<callout align="left" class="code"><!--
-->&lt;img src="web URL" height="8"/&gt;<br/><!--
-->&lt;img fromgame="basegame:gui/small.png" height="4"/&gt;<br/><!--
-->&lt;img gameitem="basegame:33" height="1"/&gt;
</callout>
<p>The <code>height</code> attribute specifies the height of the image <emph>in the number of lines</emph>,
rather than pixels.</p>
<p>Supported image formats: JPEG, PNG, BMP or TGA</p>
<chapter>The Index Page</chapter>
<p><index id="index page"/>The contents of the Index Page is filled in automatically by reading through your manuscript.

View File

@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.FlippingSpriteBatch
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.imagefont.TinyAlphNum

View File

@@ -792,10 +792,11 @@ object BTeXParser {
if (tocPage != null) {
// estimate the number of TOC pages
// TOC page always takes up a full paper, therefore tocSizeInPages is always multiple of 2
var tocSizeInPages = (cptSectMap.size + 2) / doc.pageLines
var tocSizeInPages = ((cptSectMap.size + 2f) / doc.pageLines).ceilToInt()
if (tocSizeInPages == 0) tocSizeInPages = 2
if (tocSizeInPages % 2 == 1) tocSizeInPages += 1
println("TOC number of entries: ${cptSectMap.size}, estimated page count: $tocSizeInPages")
// renumber things
if (tocSizeInPages > 1) {
@@ -812,6 +813,7 @@ object BTeXParser {
}
}
var currentTOCpage = tocPage!!
cptSectMap.forEach { (type, name, pg, part, cpt, sect) ->
val indent = if (type == "subsection") 2*PAR_INDENTATION else if (type == "section") PAR_INDENTATION else 0
val heading = if (part == null && cpt == null && sect == null)
@@ -823,7 +825,11 @@ object BTeXParser {
else
"$cpt.$sect${spacingBlockToString(HEADING_NUM_TITLE_GAP)}"
typesetTOCline("$heading", name, pg, handler, indent, tocPage)
typesetTOCline("$heading", name, pg, handler, indent, currentTOCpage)
if (doc.linesPrintedOnPage[currentTOCpage] >= doc.pageLines) {
currentTOCpage += 1
}
}
}
}
@@ -1728,7 +1734,7 @@ object BTeXParser {
val ccDefault = TerrarumSansBitmap.toColorCode(0,0,0)
val ccBucks = TerrarumSansBitmap.toColorCode(5,0,0)
val ccCode = TerrarumSansBitmap.toColorCode(8,0,0)
val ccCode = TerrarumSansBitmap.toColorCode(7,0,0)
val ccHref = TerrarumSansBitmap.toColorCode(0,3,11)
val ccEmph = TerrarumSansBitmap.toColorCode(0xfc11)
val ccItemName = TerrarumSansBitmap.toColorCode(0xf03b)

View File

@@ -26,9 +26,10 @@ 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.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.btxbook"