diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index ffe2bd802..84cd23ca8 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -299,7 +299,7 @@ JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin const std::string path = AndroidUtil::Method_ZLFile_getPath->callForCppString(file); - shared_ptr image = plugin->coverImage(ZLFile(path)); + shared_ptr image = plugin->coverImage(ZLFile(path)); if (!image.isNull()) { jobject javaImage = AndroidUtil::createJavaImage(env, (const ZLFileImage&)*image); env->SetObjectArrayElement(box, 0, javaImage); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp index 05ad133a5..9e69af1f3 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp @@ -89,6 +89,6 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const { return EMPTY; } -shared_ptr FormatPlugin::coverImage(const ZLFile &file) const { +shared_ptr FormatPlugin::coverImage(const ZLFile &file) const { return 0; } diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h index f9d42befa..269137f34 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h @@ -60,7 +60,7 @@ public: virtual bool readMetaInfo(Book &book) const = 0; virtual bool readLanguageAndEncoding(Book &book) const = 0; virtual bool readModel(BookModel &model) const = 0; - virtual shared_ptr coverImage(const ZLFile &file) const; + virtual shared_ptr coverImage(const ZLFile &file) const; protected: static void detectEncodingAndLanguage(Book &book, ZLInputStream &stream); diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp index c60a8c6b6..ecc5e478a 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp @@ -26,7 +26,7 @@ FB2CoverReader::FB2CoverReader(const ZLFile &file) : myFile(file) { } -shared_ptr FB2CoverReader::readCover() { +shared_ptr FB2CoverReader::readCover() { myReadCoverPage = false; myLookForImage = false; myImageId.erase(); diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h index 13859322b..d93d3701c 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h @@ -29,7 +29,7 @@ class FB2CoverReader : public FB2Reader { public: FB2CoverReader(const ZLFile &file); - shared_ptr readCover(); + shared_ptr readCover(); private: void startElementHandler(int tag, const char **attributes); @@ -42,7 +42,7 @@ private: bool myLookForImage; std::string myImageId; int myImageStart; - shared_ptr myImage; + shared_ptr myImage; }; #endif /* __FB2COVERREADER_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.cpp b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.cpp index 4214bcf51..5fdd84ba1 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.cpp @@ -37,7 +37,7 @@ bool FB2Plugin::readModel(BookModel &model) const { return FB2BookReader(model).readBook(); } -shared_ptr FB2Plugin::coverImage(const ZLFile &file) const { +shared_ptr FB2Plugin::coverImage(const ZLFile &file) const { return FB2CoverReader(file).readCover(); } diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h index b7188e32f..11faed68f 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h @@ -32,7 +32,7 @@ public: bool readMetaInfo(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; - shared_ptr coverImage(const ZLFile &file) const; + shared_ptr coverImage(const ZLFile &file) const; }; inline FB2Plugin::FB2Plugin() {} diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp index 3b9448624..34ace4ba2 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp @@ -26,6 +26,7 @@ #include #include "OEBBookReader.h" +#include "XHTMLImageFinder.h" #include "NCXReader.h" #include "../xhtml/XHTMLReader.h" #include "../util/MiscUtil.h" @@ -94,17 +95,15 @@ void OEBBookReader::startElementHandler(const char *tag, const char **xmlattribu ZLFile imageFile(myFilePrefix + reference); myCoverFileName = imageFile.path(); const std::string imageName = imageFile.name(false); - /* - final ZLFileImage image = XHTMLImageFinder.getCoverImage(imageFile); - if (image != null) { + shared_ptr image = XHTMLImageFinder().readImage(imageFile); + if (!image.isNull()) { myModelReader.setMainTextModel(); myModelReader.addImageReference(imageName, (short)0, true); myModelReader.addImage(imageName, image); myModelReader.insertEndOfSectionParagraph(); } else { - myCoverFileName = null; + myCoverFileName.erase(); } - */ } else if (COVER_IMAGE == type) { ZLFile imageFile(myFilePrefix + reference); myCoverFileName = imageFile.path(); @@ -154,14 +153,18 @@ bool OEBBookReader::readBook(const ZLFile &file) { myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); + bool firstFile = true; for (std::vector::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { - if (it != myHtmlFileNames.begin()) { - myModelReader.insertEndOfSectionParagraph(); - } else if (*it == myCoverFileName) { + const ZLFile xhtmlFile(myFilePrefix + *it); + if (firstFile && myCoverFileName == xhtmlFile.path()) { continue; } + if (!firstFile) { + myModelReader.insertEndOfSectionParagraph(); + } XHTMLReader xhtmlReader(myModelReader); - xhtmlReader.readFile(ZLFile(myFilePrefix + *it), *it); + xhtmlReader.readFile(xhtmlFile, *it); + firstFile = false; } generateTOC(); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp index 4e5ac53ac..d7487cce2 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp @@ -29,7 +29,7 @@ OEBCoverReader::OEBCoverReader() { } -shared_ptr OEBCoverReader::readCover(const ZLFile &file) { +shared_ptr OEBCoverReader::readCover(const ZLFile &file) { myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myReadState = READ_NOTHING; myImage.reset(); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.h index 57c869b1b..e1f96b508 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.h @@ -31,7 +31,7 @@ class OEBCoverReader : public ZLXMLReader { public: OEBCoverReader(); - shared_ptr readCover(const ZLFile &file); + shared_ptr readCover(const ZLFile &file); private: void startElementHandler(const char *tag, const char **attributes); @@ -41,7 +41,7 @@ private: void createImage(const char *href); private: - shared_ptr myImage; + shared_ptr myImage; std::string myPathPrefix; std::string myCoverXHTML; std::string myCoverId; diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp index 449f9a796..9be0ff180 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp @@ -128,7 +128,7 @@ bool OEBPlugin::readModel(BookModel &model) const { return OEBBookReader(model).readBook(opfFile(file)); } -shared_ptr OEBPlugin::coverImage(const ZLFile &file) const { +shared_ptr OEBPlugin::coverImage(const ZLFile &file) const { return OEBCoverReader().readCover(opfFile(file)); } diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h index b338fd9a7..1d6364f70 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h @@ -34,7 +34,7 @@ public: bool readMetaInfo(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; - shared_ptr coverImage(const ZLFile &file) const; + shared_ptr coverImage(const ZLFile &file) const; }; #endif /* __OEBPLUGIN_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.cpp index f491200ed..bcd2f7a42 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.cpp @@ -26,7 +26,7 @@ static const std::string TAG_IMG = "img"; static const std::string TAG_IMAGE = "image"; -shared_ptr XHTMLImageFinder::readImage(const ZLFile &file) { +shared_ptr XHTMLImageFinder::readImage(const ZLFile &file) { myImage.reset(); myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path()); readDocument(file); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.h b/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.h index 7eda6836e..00983be12 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.h @@ -29,14 +29,14 @@ class ZLImage; class XHTMLImageFinder : public ZLXMLReader { public: - shared_ptr readImage(const ZLFile &file); + shared_ptr readImage(const ZLFile &file); private: void startElementHandler(const char *tag, const char **attributes); private: std::string myPathPrefix; - shared_ptr myImage; + shared_ptr myImage; }; #endif /* __XHTMLIMAGEFINDER_H__ */