bool FB2Plugin::readModel(const BookDescription &description, BookModel &model) const { // this code fixes incorrect config entry created by fbreader of version <= 0.6.1 // makes no sense if old fbreader was not used if (description.encoding() != "auto") { BookInfo(description.fileName()).EncodingOption.setValue("auto"); } return FB2BookReader(model).readBook(description.fileName()); }
bool HtmlPlugin::readModel(const BookDescription &description, BookModel &model) const { std::string fileName = description.fileName(); shared_ptr<ZLInputStream> stream = ZLFile(fileName).inputStream(); if (stream.isNull()) { return false; } PlainTextFormat format(fileName); if (!format.initialized()) { PlainTextFormatDetector detector; detector.detect(*stream, format); } int index0 = fileName.rfind('/'); int index1 = fileName.rfind(':'); HtmlBookReader(fileName.substr(0, std::max(index0, index1) + 1), model, format, description.encoding()).readDocument(*stream); return true; }
bool PluckerPlugin::readModel(const BookDescription &description, BookModel &model) const { return PluckerBookReader(description.fileName(), model, description.encoding()).readDocument(); }
bool CHMPlugin::readModel(const BookDescription &description, BookModel &model) const { shared_ptr<ZLInputStream> stream = ZLFile(description.fileName()).inputStream(); if (stream.isNull() || !stream->open()) { return false; } shared_ptr<CHMFileInfo> info = new CHMFileInfo(description.fileName()); if (!info->init(*stream)) { return false; } CHMFileInfo::FileNames names = info->sectionNames(stream); if (names.empty()) { return false; } CHMReferenceCollection referenceCollection; referenceCollection.addReference(names.Start, false); referenceCollection.addReference(names.Home, false); shared_ptr<ZLInputStream> tocStream = info->entryStream(stream, names.TOC); HHCReader hhcReader(referenceCollection, model, description.encoding()); if (!tocStream.isNull() && tocStream->open()) { referenceCollection.setPrefix(names.TOC); hhcReader.readDocument(*tocStream); } /* if (!tocStream.isNull() && tocStream->open()) { std::string buf; buf.append(tocStream->sizeOfOpened(), '\0'); tocStream->read((char*)buf.data(), buf.length()); std::cerr << "[ " << names.TOC << " ]\n" << buf << "\n"; } */ int contentCounter = 0; PlainTextFormat format(description.fileName()); HtmlSectionReader reader(model, format, description.encoding(), info, referenceCollection); while (referenceCollection.containsNonProcessedReferences()) { const std::string fileName = referenceCollection.nextReference(); if (ZLStringUtil::stringEndsWith(fileName, ".jpg") || ZLStringUtil::stringEndsWith(fileName, ".gif")) { std::string lowerCasedFileName = ZLUnicodeUtil::toLower(fileName); BookReader bookReader(model); bookReader.setMainTextModel(); bookReader.addHyperlinkLabel(lowerCasedFileName); bookReader.pushKind(REGULAR); bookReader.beginParagraph(); bookReader.addImageReference(lowerCasedFileName); bookReader.addImage(fileName, new CHMFileImage(info, fileName)); bookReader.endParagraph(); bookReader.insertEndOfTextParagraph(); } else { shared_ptr<ZLInputStream> entryStream = info->entryStream(stream, fileName); if (!entryStream.isNull() && entryStream->open()) { /* std::string buf; buf.append(entryStream->sizeOfOpened(), '\0'); entryStream->read((char*)buf.data(), buf.length()); std::cerr << "[ " << fileName << " ]\n" << buf << "\n"; entryStream->open(); */ reader.setSectionName(fileName); reader.readDocument(*entryStream); ++contentCounter; } } } if (contentCounter == 0) { return false; } hhcReader.setReferences(); return true; }
bool DummyPlugin::readModel(const BookDescription &description, BookModel &model) const { return DummyBookReader(model).readBook(ZLFile(description.fileName()).inputStream()); }
bool OpenReaderPlugin::readModel(const BookDescription &description, BookModel &model) const { return ORBookReader(model).readBook(description.fileName()); }
bool DocBookPlugin::readModel(const BookDescription &description, BookModel &model) const { return DocBookBookReader(model).readDocument(ZLFile(description.fileName()).inputStream()); }