Skip to content

Commit

Permalink
Automatic merge branch 'current-stable' into 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Auto CI committed Nov 4, 2023
2 parents 7525ce8 + 913022c commit 791033f
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,23 @@ fun EpubBackendState.optimizeEpub() {
return docs
}

fun getOrdinalRange(doc: Document): IntRange {
fun getOrdinalRange(doc: Document): IntRange? {
val bvas = useXPathInstance { xp ->
xp.compile(
"//ns:BVA",
Filters.element(), null, xhtmlNamespace
).evaluate(doc)
}
if(bvas.size == 0) return 0..0
if(bvas.size == 0) return null
return bvas.first().getAttribute("ordinal").intValue ..
bvas.last().getAttribute("ordinal").intValue
}

fun splitIntoFragments(originalId: String, origDocument: Document, maxOrdinal: Int): List<EpubFragment> {
return splitIntoN(origDocument, 0..maxOrdinal, maxOrdinal/ORDINALS_PER_FRAGMENT).map {
return splitIntoN(origDocument, 0..maxOrdinal, maxOrdinal/ORDINALS_PER_FRAGMENT).mapNotNull {
val ordinalRange = getOrdinalRange(it)
EpubFragment(originalId = originalId, ordinalRange.first, ordinalRange.last).apply {
if (ordinalRange == null) null
else EpubFragment(originalId = originalId, ordinalRange.first, ordinalRange.last).apply {
element=it.rootElement
}
}
Expand Down

0 comments on commit 791033f

Please sign in to comment.