| 859 | } |
| 860 | |
| 861 | int 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) |
| 890 | float Epub::calculateProgress(const int currentSpineIndex, const float currentSpineRead) const { |