mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
btex: <a> boxing better detection of hyphenation
This commit is contained in:
@@ -343,6 +343,24 @@ data class BTeXClickable(
|
||||
) {
|
||||
var deltaX = 0
|
||||
var deltaY = 0
|
||||
|
||||
fun debugDrawHitboxToPixmap(pixmap: Pixmap, doc: BTeXDocument) {
|
||||
pixmap.drawRectangle(
|
||||
posX - HBPADH + doc.pageMarginH,
|
||||
posY - HBPADV + doc.pageMarginV,
|
||||
width + 2 * HBPADH,
|
||||
doc.lineHeightInPx + 2 * HBPADV
|
||||
)
|
||||
}
|
||||
|
||||
fun pointInHitbox(doc: BTeXDocument, x: Int, y: Int) =
|
||||
(x in posX - HBPADH + doc.pageMarginH until posX - HBPADH + doc.pageMarginH + width + 2 * HBPADH &&
|
||||
y in posY - HBPADV + doc.pageMarginV until posY - HBPADV + doc.pageMarginV + doc.lineHeightInPx + 2 * HBPADV)
|
||||
|
||||
companion object {
|
||||
private const val HBPADH = 0
|
||||
private const val HBPADV = 1
|
||||
}
|
||||
}
|
||||
|
||||
class BTeXPage(
|
||||
@@ -407,7 +425,7 @@ class BTeXPage(
|
||||
// debug underlines on clickableElements
|
||||
clickableElements.forEach {
|
||||
pixmap.setColor(HREF_UNDERLINE)
|
||||
pixmap.drawRectangle(it.posX + doc.pageMarginH, it.posY + doc.pageMarginV, it.width, doc.lineHeightInPx)
|
||||
it.debugDrawHitboxToPixmap(pixmap, doc)
|
||||
}
|
||||
|
||||
// print texts
|
||||
|
||||
@@ -1653,10 +1653,10 @@ object BTeXParser {
|
||||
|
||||
val indexOfSequence = str.indexOfSequence(objSeq)
|
||||
|
||||
val theIndex = if (objectIsSplit) -(objSeq.size + 4) else indexOfSequence
|
||||
val theIndex = if (objectIsSplit) -(objSeq.size) else indexOfSequence
|
||||
|
||||
theIndex?.let { index -> // we never know which line the object appears
|
||||
val wordOffset = index + objSeq.size + 4 // must be index of starting NUL
|
||||
val wordOffset = index + objSeq.size // must be index of starting NUL
|
||||
// target word is on the current line
|
||||
if (wordOffset < str.size) {
|
||||
var wordEnd = wordOffset + 1 // will be right on the ending NUL
|
||||
@@ -1724,10 +1724,10 @@ object BTeXParser {
|
||||
|
||||
val indexOfSequence = str.indexOfSequence(objSeq)
|
||||
|
||||
val theIndex = if (objectIsSplit) -(objSeq.size + 4) else indexOfSequence
|
||||
val theIndex = if (objectIsSplit) -(objSeq.size) else indexOfSequence
|
||||
|
||||
theIndex?.let { index -> // we never know which line the object appears
|
||||
val wordOffset = index + objSeq.size + 4 // must be index of starting NUL
|
||||
val wordOffset = index + objSeq.size // must be index of starting NUL
|
||||
// target word is on the current line
|
||||
if (wordOffset < str.size) {
|
||||
var wordEnd = wordOffset + 1 // will be right on the ending NUL
|
||||
@@ -1735,6 +1735,10 @@ object BTeXParser {
|
||||
while (!(wordEnd >= str.size || str[wordEnd] == OBJ)) {
|
||||
wordEnd++
|
||||
}
|
||||
// if searching finished without finding OBJ, mark it
|
||||
val objectIsSplit2 = (wordEnd >= str.size)
|
||||
|
||||
// retrieve the actual word
|
||||
val substr = CodepointSequence(str.subList(wordOffset + 1, wordEnd))
|
||||
|
||||
printdbg("2HREF word: ${substr.toReadable()}")
|
||||
@@ -1748,7 +1752,7 @@ object BTeXParser {
|
||||
}
|
||||
doc.appendClickable(doc.pages[pageNum], clickable); clickables.add(clickable)
|
||||
|
||||
objectIsSplit = false
|
||||
objectIsSplit = objectIsSplit2
|
||||
}
|
||||
// target word is on the next line (probably)
|
||||
else {
|
||||
@@ -2083,7 +2087,11 @@ object BTeXParser {
|
||||
if (pattern.isEmpty())
|
||||
throw IllegalArgumentException("Pattern is empty")
|
||||
if (this.isEmpty())
|
||||
throw IllegalArgumentException("Pattern is empty")
|
||||
throw IllegalArgumentException("String is empty")
|
||||
|
||||
// pattern cannot exist because the string is shorter than the pattern
|
||||
if (this.size < pattern.size)
|
||||
return null
|
||||
|
||||
// next[i] stores the index of the next best partial match
|
||||
val next = IntArray(pattern.size + 1)
|
||||
|
||||
Reference in New Issue
Block a user