shared_ptr<ZLImage> OEBCoverReader::readCover(const std::string &filePath) { myPathPrefix = MiscUtil::htmlDirectoryPrefix(filePath); myReadGuide = false; myImage = 0; myCoverXHTML.erase(); readDocument(filePath); myPathPrefix = MiscUtil::htmlDirectoryPrefix(myCoverXHTML); if (!myCoverXHTML.empty()) { XHTMLImageFinder(*this).readDocument(myCoverXHTML); } return myImage; }
void OEBBookReader::addCoverImage() { ZLFile imageFile(myCoverFileName); shared_ptr<const ZLImage> image = coverIsSingleImage() ? new ZLFileImage(imageFile, "", 0) : XHTMLImageFinder().readImage(imageFile); if (!image.isNull()) { const std::string imageName = imageFile.name(false); myModelReader.setMainTextModel(); myModelReader.addImageReference(imageName, (short)0, true); myModelReader.addImage(imageName, image); myModelReader.insertEndOfSectionParagraph(); } }
shared_ptr<ZLImage> OEBCoverReader::readCover(const ZLFile &file) { myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myReadGuide = false; myImage = 0; myCoverXHTML.erase(); readDocument(file); myPathPrefix = MiscUtil::htmlDirectoryPrefix(myCoverXHTML); if (!myCoverXHTML.empty()) { ZLFile coverFile(myCoverXHTML); const std::string ext = coverFile.extension(); if (ext == "gif" || ext == "jpeg" || ext == "jpg") { myImage = new ZLFileImage(ZLFile(myCoverXHTML), 0); } else { XHTMLImageFinder(*this).readDocument(coverFile); } } return myImage; }
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) { std::string tagString = ZLUnicodeUtil::toLower(tag); switch (myState) { case READ_NONE: if (isOPFTag(MANIFEST, tagString)) { myState = READ_MANIFEST; } else if (isOPFTag(SPINE, tagString)) { const char *toc = attributeValue(xmlattributes, "toc"); if (toc != 0) { myNCXTOCFileName = myIdToHref[toc]; } myState = READ_SPINE; } else if (isOPFTag(GUIDE, tagString)) { myState = READ_GUIDE; } else if (isOPFTag(TOUR, tagString)) { myState = READ_TOUR; } break; case READ_MANIFEST: if (isOPFTag(ITEM, tagString)) { const char *href = attributeValue(xmlattributes, "href"); if (href != 0) { const std::string sHref = MiscUtil::decodeHtmlURL(href); const char *id = attributeValue(xmlattributes, "id"); const char *mediaType = attributeValue(xmlattributes, "media-type"); if (id != 0) { myIdToHref[id] = sHref; } if (mediaType != 0) { myHrefToMediatype[sHref] = mediaType; } } } break; case READ_SPINE: if (isOPFTag(ITEMREF, tagString)) { const char *id = attributeValue(xmlattributes, "idref"); if (id != 0) { const std::string &fileName = myIdToHref[id]; if (!fileName.empty()) { myHtmlFileNames.push_back(fileName); } } } break; case READ_GUIDE: if (isOPFTag(REFERENCE, tagString)) { const char *type = attributeValue(xmlattributes, "type"); const char *title = attributeValue(xmlattributes, "title"); const char *href = attributeValue(xmlattributes, "href"); if (href != 0) { const std::string reference = MiscUtil::decodeHtmlURL(href); if (title != 0) { myGuideTOC.push_back(std::make_pair(std::string(title), reference)); } if (type != 0) { if (COVER == type) { ZLFile imageFile(myFilePrefix + reference); myCoverFileName = imageFile.path(); const std::map<std::string,std::string>::const_iterator it = myHrefToMediatype.find(reference); const std::string mimeType = it != myHrefToMediatype.end() ? it->second : std::string(); shared_ptr<const ZLImage> image; if (ZLStringUtil::stringStartsWith(mimeType, "image/")) { image = new ZLFileImage(imageFile, 0); } else { image = XHTMLImageFinder().readImage(imageFile); } if (!image.isNull()) { const std::string imageName = imageFile.name(false); myModelReader.setMainTextModel(); myModelReader.addImageReference(imageName, 0); myModelReader.addImage(imageName, image); myModelReader.insertEndOfSectionParagraph(); } else { myCoverFileName.erase(); } } else if (COVER_IMAGE == type) { ZLFile imageFile(myFilePrefix + reference); myCoverFileName = imageFile.path(); const std::string imageName = imageFile.name(false); myModelReader.setMainTextModel(); myModelReader.addImageReference(imageName, 0); myModelReader.addImage(imageName, new ZLFileImage(imageFile, 0)); myModelReader.insertEndOfSectionParagraph(); } } } } break; case READ_TOUR: if (isOPFTag(SITE, tagString)) { const char *title = attributeValue(xmlattributes, "title"); const char *href = attributeValue(xmlattributes, "href"); if ((title != 0) && (href != 0)) { myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href))); } } break; } }