Epub tts fix (#103)
* build: bump version to 1.0.38 and improve CFI page lookup logic * fix: resolve duplicate TTS audio and broken highlights in Vertical Mode Updated the text extraction logic in epub_reader.js to pick only the most granular matching elements, preventing duplication when elements like <p> are nested inside <li>.
This commit is contained in:
parent
fbe8e7aa56
commit
32e29dfc07
5 changed files with 44 additions and 24 deletions
|
|
@ -1041,17 +1041,21 @@ class BookPaginator(
|
|||
override fun findPageForCfiAndOffset(chapterIndex: Int, cfi: String, charOffset: Int): Int? {
|
||||
val index = chapterCharacterIndex[chapterIndex]
|
||||
if (index.isNullOrEmpty()) {
|
||||
Timber.tag("TTS_PAGE_JUMP_DIAG").w("Lookup failed: No character index for chapter $chapterIndex")
|
||||
return null
|
||||
}
|
||||
|
||||
val targetPath = CfiUtils.getPath(cfi)
|
||||
val foundRange = index.find { range ->
|
||||
|
||||
val matches = index.filter { range ->
|
||||
val rangePath = CfiUtils.getPath(range.cfi)
|
||||
val cfiMatches = targetPath == rangePath || targetPath.startsWith(rangePath) || rangePath.startsWith(targetPath)
|
||||
val pathMatches = targetPath == rangePath || targetPath.startsWith(rangePath)
|
||||
val offsetMatches = charOffset >= range.startOffset && charOffset < range.endOffset
|
||||
cfiMatches && offsetMatches
|
||||
pathMatches && offsetMatches
|
||||
}
|
||||
|
||||
val foundRange = matches.maxByOrNull { CfiUtils.getPath(it.cfi).length }
|
||||
|
||||
return if (foundRange != null) {
|
||||
val chapterStartPage = chapterStartPageIndices[chapterIndex]
|
||||
if (chapterStartPage == null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue