mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
XHTMLImageFinder used in OEBBookReader
This commit is contained in:
parent
67f2922418
commit
5e68f8602f
14 changed files with 28 additions and 25 deletions
|
@ -299,7 +299,7 @@ JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
||||||
|
|
||||||
const std::string path = AndroidUtil::Method_ZLFile_getPath->callForCppString(file);
|
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()) {
|
if (!image.isNull()) {
|
||||||
jobject javaImage = AndroidUtil::createJavaImage(env, (const ZLFileImage&)*image);
|
jobject javaImage = AndroidUtil::createJavaImage(env, (const ZLFileImage&)*image);
|
||||||
env->SetObjectArrayElement(box, 0, javaImage);
|
env->SetObjectArrayElement(box, 0, javaImage);
|
||||||
|
|
|
@ -89,6 +89,6 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
shared_ptr<const ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
virtual bool readMetaInfo(Book &book) const = 0;
|
virtual bool readMetaInfo(Book &book) const = 0;
|
||||||
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
||||||
virtual bool readModel(BookModel &model) 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:
|
protected:
|
||||||
static void detectEncodingAndLanguage(Book &book, ZLInputStream &stream);
|
static void detectEncodingAndLanguage(Book &book, ZLInputStream &stream);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
FB2CoverReader::FB2CoverReader(const ZLFile &file) : myFile(file) {
|
FB2CoverReader::FB2CoverReader(const ZLFile &file) : myFile(file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<ZLImage> FB2CoverReader::readCover() {
|
shared_ptr<const ZLImage> FB2CoverReader::readCover() {
|
||||||
myReadCoverPage = false;
|
myReadCoverPage = false;
|
||||||
myLookForImage = false;
|
myLookForImage = false;
|
||||||
myImageId.erase();
|
myImageId.erase();
|
||||||
|
|
|
@ -29,7 +29,7 @@ class FB2CoverReader : public FB2Reader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FB2CoverReader(const ZLFile &file);
|
FB2CoverReader(const ZLFile &file);
|
||||||
shared_ptr<ZLImage> readCover();
|
shared_ptr<const ZLImage> readCover();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startElementHandler(int tag, const char **attributes);
|
void startElementHandler(int tag, const char **attributes);
|
||||||
|
@ -42,7 +42,7 @@ private:
|
||||||
bool myLookForImage;
|
bool myLookForImage;
|
||||||
std::string myImageId;
|
std::string myImageId;
|
||||||
int myImageStart;
|
int myImageStart;
|
||||||
shared_ptr<ZLImage> myImage;
|
shared_ptr<const ZLImage> myImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __FB2COVERREADER_H__ */
|
#endif /* __FB2COVERREADER_H__ */
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool FB2Plugin::readModel(BookModel &model) const {
|
||||||
return FB2BookReader(model).readBook();
|
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();
|
return FB2CoverReader(file).readCover();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
bool readMetaInfo(Book &book) const;
|
bool readMetaInfo(Book &book) const;
|
||||||
bool readLanguageAndEncoding(Book &book) const;
|
bool readLanguageAndEncoding(Book &book) const;
|
||||||
bool readModel(BookModel &model) 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() {}
|
inline FB2Plugin::FB2Plugin() {}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <ZLXMLNamespace.h>
|
#include <ZLXMLNamespace.h>
|
||||||
|
|
||||||
#include "OEBBookReader.h"
|
#include "OEBBookReader.h"
|
||||||
|
#include "XHTMLImageFinder.h"
|
||||||
#include "NCXReader.h"
|
#include "NCXReader.h"
|
||||||
#include "../xhtml/XHTMLReader.h"
|
#include "../xhtml/XHTMLReader.h"
|
||||||
#include "../util/MiscUtil.h"
|
#include "../util/MiscUtil.h"
|
||||||
|
@ -94,17 +95,15 @@ void OEBBookReader::startElementHandler(const char *tag, const char **xmlattribu
|
||||||
ZLFile imageFile(myFilePrefix + reference);
|
ZLFile imageFile(myFilePrefix + reference);
|
||||||
myCoverFileName = imageFile.path();
|
myCoverFileName = imageFile.path();
|
||||||
const std::string imageName = imageFile.name(false);
|
const std::string imageName = imageFile.name(false);
|
||||||
/*
|
shared_ptr<const ZLImage> image = XHTMLImageFinder().readImage(imageFile);
|
||||||
final ZLFileImage image = XHTMLImageFinder.getCoverImage(imageFile);
|
if (!image.isNull()) {
|
||||||
if (image != null) {
|
|
||||||
myModelReader.setMainTextModel();
|
myModelReader.setMainTextModel();
|
||||||
myModelReader.addImageReference(imageName, (short)0, true);
|
myModelReader.addImageReference(imageName, (short)0, true);
|
||||||
myModelReader.addImage(imageName, image);
|
myModelReader.addImage(imageName, image);
|
||||||
myModelReader.insertEndOfSectionParagraph();
|
myModelReader.insertEndOfSectionParagraph();
|
||||||
} else {
|
} else {
|
||||||
myCoverFileName = null;
|
myCoverFileName.erase();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
} else if (COVER_IMAGE == type) {
|
} else if (COVER_IMAGE == type) {
|
||||||
ZLFile imageFile(myFilePrefix + reference);
|
ZLFile imageFile(myFilePrefix + reference);
|
||||||
myCoverFileName = imageFile.path();
|
myCoverFileName = imageFile.path();
|
||||||
|
@ -154,14 +153,18 @@ bool OEBBookReader::readBook(const ZLFile &file) {
|
||||||
myModelReader.setMainTextModel();
|
myModelReader.setMainTextModel();
|
||||||
myModelReader.pushKind(REGULAR);
|
myModelReader.pushKind(REGULAR);
|
||||||
|
|
||||||
|
bool firstFile = true;
|
||||||
for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) {
|
for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) {
|
||||||
if (it != myHtmlFileNames.begin()) {
|
const ZLFile xhtmlFile(myFilePrefix + *it);
|
||||||
myModelReader.insertEndOfSectionParagraph();
|
if (firstFile && myCoverFileName == xhtmlFile.path()) {
|
||||||
} else if (*it == myCoverFileName) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!firstFile) {
|
||||||
|
myModelReader.insertEndOfSectionParagraph();
|
||||||
|
}
|
||||||
XHTMLReader xhtmlReader(myModelReader);
|
XHTMLReader xhtmlReader(myModelReader);
|
||||||
xhtmlReader.readFile(ZLFile(myFilePrefix + *it), *it);
|
xhtmlReader.readFile(xhtmlFile, *it);
|
||||||
|
firstFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateTOC();
|
generateTOC();
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
OEBCoverReader::OEBCoverReader() {
|
OEBCoverReader::OEBCoverReader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<ZLImage> OEBCoverReader::readCover(const ZLFile &file) {
|
shared_ptr<const ZLImage> OEBCoverReader::readCover(const ZLFile &file) {
|
||||||
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
||||||
myReadState = READ_NOTHING;
|
myReadState = READ_NOTHING;
|
||||||
myImage.reset();
|
myImage.reset();
|
||||||
|
|
|
@ -31,7 +31,7 @@ class OEBCoverReader : public ZLXMLReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OEBCoverReader();
|
OEBCoverReader();
|
||||||
shared_ptr<ZLImage> readCover(const ZLFile &file);
|
shared_ptr<const ZLImage> readCover(const ZLFile &file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startElementHandler(const char *tag, const char **attributes);
|
void startElementHandler(const char *tag, const char **attributes);
|
||||||
|
@ -41,7 +41,7 @@ private:
|
||||||
void createImage(const char *href);
|
void createImage(const char *href);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
shared_ptr<ZLImage> myImage;
|
shared_ptr<const ZLImage> myImage;
|
||||||
std::string myPathPrefix;
|
std::string myPathPrefix;
|
||||||
std::string myCoverXHTML;
|
std::string myCoverXHTML;
|
||||||
std::string myCoverId;
|
std::string myCoverId;
|
||||||
|
|
|
@ -128,7 +128,7 @@ bool OEBPlugin::readModel(BookModel &model) const {
|
||||||
return OEBBookReader(model).readBook(opfFile(file));
|
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));
|
return OEBCoverReader().readCover(opfFile(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
bool readMetaInfo(Book &book) const;
|
bool readMetaInfo(Book &book) const;
|
||||||
bool readLanguageAndEncoding(Book &book) const;
|
bool readLanguageAndEncoding(Book &book) const;
|
||||||
bool readModel(BookModel &model) 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__ */
|
#endif /* __OEBPLUGIN_H__ */
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
static const std::string TAG_IMG = "img";
|
static const std::string TAG_IMG = "img";
|
||||||
static const std::string TAG_IMAGE = "image";
|
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();
|
myImage.reset();
|
||||||
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
||||||
readDocument(file);
|
readDocument(file);
|
||||||
|
|
|
@ -29,14 +29,14 @@ class ZLImage;
|
||||||
class XHTMLImageFinder : public ZLXMLReader {
|
class XHTMLImageFinder : public ZLXMLReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<ZLImage> readImage(const ZLFile &file);
|
shared_ptr<const ZLImage> readImage(const ZLFile &file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startElementHandler(const char *tag, const char **attributes);
|
void startElementHandler(const char *tag, const char **attributes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string myPathPrefix;
|
std::string myPathPrefix;
|
||||||
shared_ptr<ZLImage> myImage;
|
shared_ptr<const ZLImage> myImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __XHTMLIMAGEFINDER_H__ */
|
#endif /* __XHTMLIMAGEFINDER_H__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue