Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}