This commit is contained in:
Arthur Tazhitdinov 2025-12-16 17:22:56 +00:00 committed by GitHub
commit 36e44bbfcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -73,10 +73,8 @@ bool Epub::parseContentOpf(const std::string& contentOpfFilePath) {
coverImageItem = opfParser.items.at(opfParser.coverItemId); coverImageItem = opfParser.items.at(opfParser.coverItemId);
} }
if (opfParser.items.count("ncx")) { if (!opfParser.tocNcxPath.empty()) {
tocNcxItem = opfParser.items.at("ncx"); tocNcxItem = opfParser.tocNcxPath;
} else if (opfParser.items.count("ncxtoc")) {
tocNcxItem = opfParser.items.at("ncxtoc");
} }
for (auto& spineRef : opfParser.spineRefs) { for (auto& spineRef : opfParser.spineRefs) {

View File

@ -3,6 +3,10 @@
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <ZipFile.h> #include <ZipFile.h>
namespace {
constexpr const char MEDIA_TYPE_NCX[] = "application/x-dtbncx+xml";
}
bool ContentOpfParser::setup() { bool ContentOpfParser::setup() {
parser = XML_ParserCreate(nullptr); parser = XML_ParserCreate(nullptr);
if (!parser) { if (!parser) {
@ -111,16 +115,28 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
if (self->state == IN_MANIFEST && (strcmp(name, "item") == 0 || strcmp(name, "opf:item") == 0)) { if (self->state == IN_MANIFEST && (strcmp(name, "item") == 0 || strcmp(name, "opf:item") == 0)) {
std::string itemId; std::string itemId;
std::string href; std::string href;
std::string mediaType;
for (int i = 0; atts[i]; i += 2) { for (int i = 0; atts[i]; i += 2) {
if (strcmp(atts[i], "id") == 0) { if (strcmp(atts[i], "id") == 0) {
itemId = atts[i + 1]; itemId = atts[i + 1];
} else if (strcmp(atts[i], "href") == 0) { } else if (strcmp(atts[i], "href") == 0) {
href = self->baseContentPath + atts[i + 1]; href = self->baseContentPath + atts[i + 1];
} else if (strcmp(atts[i], "media-type") == 0) {
mediaType = atts[i + 1];
} }
} }
self->items[itemId] = href; self->items[itemId] = href;
if (mediaType == MEDIA_TYPE_NCX) {
if (self->tocNcxPath.empty()) {
self->tocNcxPath = href;
} else {
Serial.printf("[%lu] [COF] Warning: Multiple NCX files found in manifest. Ignoring duplicate: %s\n", millis(),
href.c_str());
}
}
return; return;
} }