mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Merge 8a99436e6a into 67da8139b3
This commit is contained in:
commit
36e44bbfcd
@ -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) {
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user