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(); } }
bool OEBBookReader::readBook(const ZLFile &file) { myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myCoverFileName.erase(); myCoverFileType.erase(); myCoverMimeType.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(file)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); //ZLLogger::Instance().registerClass("oeb"); XHTMLReader xhtmlReader(myModelReader); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { const ZLFile xhtmlFile(myFilePrefix + *it); if (it == myHtmlFileNames.begin()) { if (myCoverFileName == xhtmlFile.path()) { if (coverIsSingleImage()) { addCoverImage(); continue; } xhtmlReader.setMarkFirstImageAsCover(); } else { addCoverImage(); } } else { myModelReader.insertEndOfSectionParagraph(); } //ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path()); xhtmlReader.readFile(xhtmlFile, *it); //ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path()); //std::string debug = "para count = "; //ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber()); //ZLLogger::Instance().println("oeb", debug); } generateTOC(xhtmlReader); return true; }
bool OEBBookReader::readBook(const ZLFile &file) { const ZLFile epub = file.getContainerArchive(); epub.forceArchiveType(ZLFile::ZIP); shared_ptr<ZLDir> epubDir = epub.directory(); if (!epubDir.isNull()) { myEncryptionMap = new EncryptionMap(); const std::vector<shared_ptr<FileEncryptionInfo> > encodingInfos = OEBEncryptionReader().readEncryptionInfos(epub); for (std::vector<shared_ptr<FileEncryptionInfo> >::const_iterator it = encodingInfos.begin(); it != encodingInfos.end(); ++it) { myEncryptionMap->addInfo(*epubDir, *it); } } myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myCoverFileName.erase(); myCoverFileType.erase(); myCoverMimeType.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(file)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); //ZLLogger::Instance().registerClass("oeb"); XHTMLReader xhtmlReader(myModelReader, myEncryptionMap); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { const ZLFile xhtmlFile(myFilePrefix + *it); if (it == myHtmlFileNames.begin()) { if (myCoverFileName == xhtmlFile.path()) { if (coverIsSingleImage()) { addCoverImage(); continue; } xhtmlReader.setMarkFirstImageAsCover(); } else { addCoverImage(); } } else { myModelReader.insertEndOfSectionParagraph(); } //ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path()); if (!xhtmlReader.readFile(xhtmlFile, *it)) { if (file.exists() && !myEncryptionMap.isNull()) { myModelReader.insertEncryptedSectionParagraph(); } } //ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path()); //std::string debug = "para count = "; //ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber()); //ZLLogger::Instance().println("oeb", debug); } generateTOC(xhtmlReader); return true; }