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

Method getParagraphIndexForPage

lib/Epub/Epub/Section.cpp:439–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437}
438
439std::optional<uint16_t> Section::getParagraphIndexForPage(const uint16_t page) const {
440 HalFile f;
441 if (!Storage.openFileForRead("SCT", filePath, f)) {
442 return std::nullopt;
443 }
444
445 const uint32_t fileSize = f.size();
446 f.seek(HEADER_SIZE - sizeof(uint32_t) * 2);
447 uint32_t paragraphLutOffset;
448 serialization::readPod(f, paragraphLutOffset);
449 if (paragraphLutOffset == 0 || paragraphLutOffset >= fileSize) {
450 return std::nullopt;
451 }
452
453 f.seek(paragraphLutOffset);
454 uint16_t count;
455 serialization::readPod(f, count);
456 if (count == 0 || page >= count) {
457 return std::nullopt;
458 }
459
460 const uint32_t entryEnd = paragraphLutOffset + sizeof(uint16_t) + (page + 1) * sizeof(uint16_t);
461 if (entryEnd > fileSize) {
462 return std::nullopt;
463 }
464
465 f.seek(paragraphLutOffset + sizeof(uint16_t) + page * sizeof(uint16_t));
466 uint16_t pIdx;
467 serialization::readPod(f, pIdx);
468 return pIdx;
469}
470
471std::optional<uint16_t> Section::getPageForListItemIndex(const uint16_t liIndex) const {
472 HalFile f;

Callers 2

launchKOReaderSyncMethod · 0.80
getCurrentPositionMethod · 0.80

Calls 4

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

Tested by

no test coverage detected