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

Method getSpineIndexForTextReference

lib/Epub/Epub.cpp:861–887  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

859}
860
861int Epub::getSpineIndexForTextReference() const {
862 if (!bookMetadataCache || !bookMetadataCache->isLoaded()) {
863 LOG_ERR("EBP", "getSpineIndexForTextReference called but cache not loaded");
864 return 0;
865 }
866 LOG_DBG("EBP", "Core Metadata: cover(%d)=%s, textReference(%d)=%s",
867 bookMetadataCache->coreMetadata.coverItemHref.size(), bookMetadataCache->coreMetadata.coverItemHref.c_str(),
868 bookMetadataCache->coreMetadata.textReferenceHref.size(),
869 bookMetadataCache->coreMetadata.textReferenceHref.c_str());
870
871 if (bookMetadataCache->coreMetadata.textReferenceHref.empty()) {
872 // there was no textReference in epub, so we return 0 (the first chapter)
873 return 0;
874 }
875
876 // loop through spine items to get the correct index matching the text href
877 for (size_t i = 0; i < getSpineItemsCount(); i++) {
878 if (getSpineItem(i).href == bookMetadataCache->coreMetadata.textReferenceHref) {
879 LOG_DBG("EBP", "Text reference %s found at index %d", bookMetadataCache->coreMetadata.textReferenceHref.c_str(),
880 i);
881 return i;
882 }
883 }
884 // This should not happen, as we checked for empty textReferenceHref earlier
885 LOG_DBG("EBP", "Section not found for text reference");
886 return 0;
887}
888
889// Calculate progress in book (returns 0.0-1.0)
890float Epub::calculateProgress(const int currentSpineIndex, const float currentSpineRead) const {

Callers 1

onEnterMethod · 0.80

Calls 3

isLoadedMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected