mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
btex: <a> tag target if off by one on the index page
This commit is contained in:
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.btex.BTeXDocViewer
|
import net.torvald.btex.BTeXDocViewer
|
||||||
import net.torvald.terrarum.btex.BTeXDocument.Companion.HREF_UNDERLINE
|
import net.torvald.terrarum.btex.BTeXDocument.Companion.HREF_UNDERLINE
|
||||||
|
import net.torvald.terrarum.btex.BTeXDocument.Companion.HREF_UNDERLINE_SHADOW
|
||||||
import net.torvald.terrarum.btex.BTeXDocument.Companion.UNDERLINE_Y
|
import net.torvald.terrarum.btex.BTeXDocument.Companion.UNDERLINE_Y
|
||||||
import net.torvald.terrarum.ceilToInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||||
@@ -65,6 +66,7 @@ class BTeXDocument : Disposable {
|
|||||||
// val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
// val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
||||||
val DEFAULT_ORNAMENTS_COL = Color(0x3f3c3b_ff)
|
val DEFAULT_ORNAMENTS_COL = Color(0x3f3c3b_ff)
|
||||||
val HREF_UNDERLINE = Color(0x0033BBff)
|
val HREF_UNDERLINE = Color(0x0033BBff)
|
||||||
|
val HREF_UNDERLINE_SHADOW = Color(0x7F99ddff) // blend=none makes transparency unusable
|
||||||
val ccPagenum = TerrarumSansBitmap.toColorCode(0xf333)
|
val ccPagenum = TerrarumSansBitmap.toColorCode(0xf333)
|
||||||
|
|
||||||
const val UNDERLINE_Y = 22
|
const val UNDERLINE_Y = 22
|
||||||
@@ -337,7 +339,7 @@ class BTeXDocument : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class BTeXClickable(
|
data class BTeXClickable(
|
||||||
var posX: Int, var posY: Int, val width: Int, val height: Int,
|
var posX: Int, var posY: Int, val width: Int, val height: Int, val drawUnderline: Boolean = true,
|
||||||
val onClick: (BTeXDocViewer) -> Unit,
|
val onClick: (BTeXDocViewer) -> Unit,
|
||||||
// val onHover: () -> Unit = {}
|
// val onHover: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
@@ -348,17 +350,30 @@ data class BTeXClickable(
|
|||||||
pixmap.drawRectangle(
|
pixmap.drawRectangle(
|
||||||
posX - HBPADH + doc.pageMarginH,
|
posX - HBPADH + doc.pageMarginH,
|
||||||
posY - HBPADV + doc.pageMarginV,
|
posY - HBPADV + doc.pageMarginV,
|
||||||
width + 2 * HBPADH,
|
width + HBPADH,
|
||||||
height + 2 * HBPADV
|
height + 2 * HBPADV
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun drawUnderline(pixmap: Pixmap, doc: BTeXDocument) {
|
||||||
|
if (drawUnderline && width > 1) {
|
||||||
|
val x = posX - HBPADH + doc.pageMarginH
|
||||||
|
val y = posY - HBPADV + doc.pageMarginV + UNDERLINE_Y
|
||||||
|
val width = width + HBPADH
|
||||||
|
|
||||||
|
pixmap.setColor(HREF_UNDERLINE_SHADOW)
|
||||||
|
pixmap.drawRectangle(x, y, width + 1, 2)
|
||||||
|
pixmap.setColor(HREF_UNDERLINE)
|
||||||
|
pixmap.drawRectangle(x, y, width, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun pointInHitbox(doc: BTeXDocument, x: Int, y: Int) =
|
fun pointInHitbox(doc: BTeXDocument, x: Int, y: Int) =
|
||||||
(x in posX - HBPADH + doc.pageMarginH until posX - HBPADH + doc.pageMarginH + width + 2 * HBPADH &&
|
(x in posX - HBPADH + doc.pageMarginH until posX - HBPADH + doc.pageMarginH + width + HBPADH &&
|
||||||
y in posY - HBPADV + doc.pageMarginV until posY - HBPADV + doc.pageMarginV + height + 2 * HBPADV)
|
y in posY - HBPADV + doc.pageMarginV until posY - HBPADV + doc.pageMarginV + height + 2 * HBPADV)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val HBPADH = 0
|
private const val HBPADH = 1
|
||||||
private const val HBPADV = 1
|
private const val HBPADV = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,18 +427,19 @@ class BTeXPage(
|
|||||||
drawCalls.sortedBy { if (it.text != null) 16 else 0 }.let { drawCalls ->
|
drawCalls.sortedBy { if (it.text != null) 16 else 0 }.let { drawCalls ->
|
||||||
// paint background
|
// paint background
|
||||||
val backCol = back.cpy().also { it.a = 0.93f }
|
val backCol = back.cpy().also { it.a = 0.93f }
|
||||||
|
pixmap.blending = Pixmap.Blending.None
|
||||||
pixmap.setColor(backCol)
|
pixmap.setColor(backCol)
|
||||||
pixmap.fill()
|
pixmap.fill()
|
||||||
|
|
||||||
// debug underlines on clickableElements
|
// debug underlines on clickableElements
|
||||||
clickableElements.forEach {
|
clickableElements.forEach {
|
||||||
pixmap.setColor(HREF_UNDERLINE)
|
pixmap.setColor(HREF_UNDERLINE)
|
||||||
// it.debugDrawHitboxToPixmap(pixmap, doc)
|
it.drawUnderline(pixmap, doc)
|
||||||
// TODO actually draw underlines
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print texts
|
// print texts
|
||||||
pixmap.setColor(Color.WHITE)
|
pixmap.setColor(Color.WHITE)
|
||||||
|
pixmap.blending = Pixmap.Blending.SourceOver
|
||||||
drawCalls.forEach {
|
drawCalls.forEach {
|
||||||
it.drawToPixmap(pixmap, x + marginH, y + marginV)
|
it.drawToPixmap(pixmap, x + marginH, y + marginV)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -818,7 +818,7 @@ object BTeXParser {
|
|||||||
val pageWidth = doc.textWidth
|
val pageWidth = doc.textWidth
|
||||||
|
|
||||||
doc.indexTable.keys.toList().sorted().forEach { key ->
|
doc.indexTable.keys.toList().sorted().forEach { key ->
|
||||||
typesetTOCline("", key, doc.indexTable[key]!! - 1, handler)
|
typesetTOCline("", key, doc.indexTable[key]!!, handler, isIndex = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1670,7 +1670,7 @@ object BTeXParser {
|
|||||||
val hrefX = if (objectIsSplit) 0 else hrefObj.x
|
val hrefX = if (objectIsSplit) 0 else hrefObj.x
|
||||||
var hrefY = hrefObj.y; if (objectIsSplit) hrefY += doc.lineHeightInPx
|
var hrefY = hrefObj.y; if (objectIsSplit) hrefY += doc.lineHeightInPx
|
||||||
|
|
||||||
val clickable = BTeXClickable(hrefX, hrefY, getFont().getWidth(substr), doc.lineHeightInPx) { viewer ->
|
val clickable = BTeXClickable(hrefX, hrefY, getFont().getWidth(substr), doc.lineHeightInPx, false) { viewer ->
|
||||||
viewer.gotoIndex(hrefObj.hrefTarget)
|
viewer.gotoIndex(hrefObj.hrefTarget)
|
||||||
}
|
}
|
||||||
doc.appendClickable(doc.pages[pageNum], clickable); clickables.add(clickable)
|
doc.appendClickable(doc.pages[pageNum], clickable); clickables.add(clickable)
|
||||||
@@ -1867,8 +1867,12 @@ object BTeXParser {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun typesetTOCline(heading: String, name: String, pageNumInt: Int, handler: BTeXHandler, indentation: Int = 0, pageToWrite: Int? = null) {
|
private fun typesetTOCline(heading: String, name: String, pageNumInt: Int, handler: BTeXHandler, indentation: Int = 0, pageToWrite: Int? = null, isIndex: Boolean = false) {
|
||||||
val pageNum = pageNumInt.plus(1).toString()
|
val pageNum = if (isIndex)
|
||||||
|
pageNumInt.toString()
|
||||||
|
else
|
||||||
|
pageNumInt.plus(1).toString()
|
||||||
|
|
||||||
val pageNumWidth = getFont().getWidth(pageNum)
|
val pageNumWidth = getFont().getWidth(pageNum)
|
||||||
val typeWidth = doc.textWidth - indentation
|
val typeWidth = doc.textWidth - indentation
|
||||||
val dotGap = 10
|
val dotGap = 10
|
||||||
@@ -1929,8 +1933,8 @@ object BTeXParser {
|
|||||||
val target = pageNumInt
|
val target = pageNumInt
|
||||||
val thePage = call.pageObject
|
val thePage = call.pageObject
|
||||||
|
|
||||||
thePage.appendClickable(BTeXClickable(boxx, boxy, boxw, boxh) {
|
thePage.appendClickable(BTeXClickable(boxx, boxy, boxw, boxh, false) {
|
||||||
printdbg("Goto page p. ${target+1}")
|
// printdbg("Goto page p. ${target+1}")
|
||||||
it.gotoPage(target)
|
it.gotoPage(target)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user