1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

XHTMLImageFinder used in OEBBookReader

This commit is contained in:
Nikolay Pultsin 2012-05-10 14:21:21 +01:00
parent 67f2922418
commit 5e68f8602f
14 changed files with 28 additions and 25 deletions

View file

@ -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<ZLImage> image = plugin->coverImage(ZLFile(path));
shared_ptr<const ZLImage> image = plugin->coverImage(ZLFile(path));
if (!image.isNull()) {
jobject javaImage = AndroidUtil::createJavaImage(env, (const ZLFileImage&)*image);
env->SetObjectArrayElement(box, 0, javaImage);

View file

@ -89,6 +89,6 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const {
return EMPTY;
}
shared_ptr<ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
shared_ptr<const ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
return 0;
}

View file

@ -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<ZLImage> coverImage(const ZLFile &file) const;
virtual shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
protected:
static void detectEncodingAndLanguage(Book &book, ZLInputStream &stream);

View file

@ -26,7 +26,7 @@
FB2CoverReader::FB2CoverReader(const ZLFile &file) : myFile(file) {
}
shared_ptr<ZLImage> FB2CoverReader::readCover() {
shared_ptr<const ZLImage> FB2CoverReader::readCover() {
myReadCoverPage = false;
myLookForImage = false;
myImageId.erase();

View file

@ -29,7 +29,7 @@ class FB2CoverReader : public FB2Reader {
public:
FB2CoverReader(const ZLFile &file);
shared_ptr<ZLImage> readCover();
shared_ptr<const ZLImage> readCover();
private:
void startElementHandler(int tag, const char **attributes);
@ -42,7 +42,7 @@ private:
bool myLookForImage;
std::string myImageId;
int myImageStart;
shared_ptr<ZLImage> myImage;
shared_ptr<const ZLImage> myImage;
};
#endif /* __FB2COVERREADER_H__ */

View file

@ -37,7 +37,7 @@ bool FB2Plugin::readModel(BookModel &model) const {
return FB2BookReader(model).readBook();
}
shared_ptr<ZLImage> FB2Plugin::coverImage(const ZLFile &file) const {
shared_ptr<const ZLImage> FB2Plugin::coverImage(const ZLFile &file) const {
return FB2CoverReader(file).readCover();
}

View file

@ -32,7 +32,7 @@ public:
bool readMetaInfo(Book &book) const;
bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const;
shared_ptr<ZLImage> coverImage(const ZLFile &file) const;
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
};
inline FB2Plugin::FB2Plugin() {}

View file

@ -26,6 +26,7 @@
#include <ZLXMLNamespace.h>
#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<const ZLImage> 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<std::string>::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();

View file

@ -29,7 +29,7 @@
OEBCoverReader::OEBCoverReader() {
}
shared_ptr<ZLImage> OEBCoverReader::readCover(const ZLFile &file) {
shared_ptr<const ZLImage> OEBCoverReader::readCover(const ZLFile &file) {
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
myReadState = READ_NOTHING;
myImage.reset();

View file

@ -31,7 +31,7 @@ class OEBCoverReader : public ZLXMLReader {
public:
OEBCoverReader();
shared_ptr<ZLImage> readCover(const ZLFile &file);
shared_ptr<const ZLImage> 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<ZLImage> myImage;
shared_ptr<const ZLImage> myImage;
std::string myPathPrefix;
std::string myCoverXHTML;
std::string myCoverId;

View file

@ -128,7 +128,7 @@ bool OEBPlugin::readModel(BookModel &model) const {
return OEBBookReader(model).readBook(opfFile(file));
}
shared_ptr<ZLImage> OEBPlugin::coverImage(const ZLFile &file) const {
shared_ptr<const ZLImage> OEBPlugin::coverImage(const ZLFile &file) const {
return OEBCoverReader().readCover(opfFile(file));
}

View file

@ -34,7 +34,7 @@ public:
bool readMetaInfo(Book &book) const;
bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const;
shared_ptr<ZLImage> coverImage(const ZLFile &file) const;
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
};
#endif /* __OEBPLUGIN_H__ */

View file

@ -26,7 +26,7 @@
static const std::string TAG_IMG = "img";
static const std::string TAG_IMAGE = "image";
shared_ptr<ZLImage> XHTMLImageFinder::readImage(const ZLFile &file) {
shared_ptr<const ZLImage> XHTMLImageFinder::readImage(const ZLFile &file) {
myImage.reset();
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
readDocument(file);

View file

@ -29,14 +29,14 @@ class ZLImage;
class XHTMLImageFinder : public ZLXMLReader {
public:
shared_ptr<ZLImage> readImage(const ZLFile &file);
shared_ptr<const ZLImage> readImage(const ZLFile &file);
private:
void startElementHandler(const char *tag, const char **attributes);
private:
std::string myPathPrefix;
shared_ptr<ZLImage> myImage;
shared_ptr<const ZLImage> myImage;
};
#endif /* __XHTMLIMAGEFINDER_H__ */