MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / getPageForParagraphIndex

Method getPageForParagraphIndex

lib/Epub/Epub/Section.cpp:400–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398}
399
400std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex) const {
401 HalFile f;
402 if (!Storage.openFileForRead("SCT", filePath, f)) {
403 return std::nullopt;
404 }
405
406 const uint32_t fileSize = f.size();
407 f.seek(HEADER_SIZE - sizeof(uint32_t) * 2);
408 uint32_t paragraphLutOffset;
409 serialization::readPod(f, paragraphLutOffset);
410 if (paragraphLutOffset == 0 || paragraphLutOffset >= fileSize) {
411 return std::nullopt;
412 }
413
414 f.seek(paragraphLutOffset);
415 uint16_t count;
416 serialization::readPod(f, count);
417 if (count == 0) {
418 return std::nullopt;
419 }
420
421 const uint32_t lutEnd = paragraphLutOffset + sizeof(uint16_t) + count * sizeof(uint16_t);
422 if (lutEnd > fileSize) {
423 return std::nullopt;
424 }
425
426 uint16_t resultPage = count - 1;
427 for (uint16_t i = 0; i < count; i++) {
428 uint16_t pagePIdx;
429 serialization::readPod(f, pagePIdx);
430 if (pagePIdx >= pIndex) {
431 resultPage = i;
432 break;
433 }
434 }
435
436 return resultPage;
437}
438
439std::optional<uint16_t> Section::getParagraphIndexForPage(const uint16_t page) const {
440 HalFile f;

Callers 1

toCrossPointMethod · 0.80

Calls 4

readPodFunction · 0.85
openFileForReadMethod · 0.80
seekMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected