mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
do not skip text from ePub cover files
This commit is contained in:
parent
c9505c21f9
commit
1feb61a896
4 changed files with 61 additions and 40 deletions
|
@ -109,38 +109,14 @@ void OEBBookReader::startElementHandler(const char *tag, const char **xmlattribu
|
|||
if (title != 0) {
|
||||
myGuideTOC.push_back(std::make_pair(std::string(title), reference));
|
||||
}
|
||||
if (type != 0) {
|
||||
if (COVER == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::map<std::string,std::string>::const_iterator it =
|
||||
myHrefToMediatype.find(reference);
|
||||
const std::string mimeType =
|
||||
it != myHrefToMediatype.end() ? it->second : std::string();
|
||||
shared_ptr<const ZLImage> image;
|
||||
if (ZLStringUtil::stringStartsWith(mimeType, "image/")) {
|
||||
image = new ZLFileImage(imageFile, "", 0);
|
||||
} else {
|
||||
image = XHTMLImageFinder().readImage(imageFile);
|
||||
}
|
||||
if (!image.isNull()) {
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, (short)0, true);
|
||||
myModelReader.addImage(imageName, image);
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
} else {
|
||||
myCoverFileName.erase();
|
||||
}
|
||||
} else if (COVER_IMAGE == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, 0, true);
|
||||
myModelReader.addImage(imageName, new ZLFileImage(imageFile, "", 0));
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
}
|
||||
if ((type != 0) && (COVER == type || COVER_IMAGE == type)) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
myCoverFileType = type;
|
||||
const std::map<std::string,std::string>::const_iterator it =
|
||||
myHrefToMediatype.find(reference);
|
||||
myCoverMimeType =
|
||||
it != myHrefToMediatype.end() ? it->second : std::string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,6 +133,34 @@ void OEBBookReader::startElementHandler(const char *tag, const char **xmlattribu
|
|||
}
|
||||
}
|
||||
|
||||
void OEBBookReader::addCoverImage() {
|
||||
if (COVER == myCoverFileType) {
|
||||
ZLFile imageFile(myCoverFileName);
|
||||
shared_ptr<const ZLImage> image;
|
||||
if (ZLStringUtil::stringStartsWith(myCoverMimeType, "image/")) {
|
||||
image = new ZLFileImage(imageFile, "", 0);
|
||||
} else {
|
||||
image = XHTMLImageFinder().readImage(imageFile);
|
||||
}
|
||||
if (!image.isNull()) {
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, (short)0, true);
|
||||
myModelReader.addImage(imageName, image);
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
} else {
|
||||
myCoverFileName.erase();
|
||||
}
|
||||
} else if (COVER_IMAGE == myCoverFileType) {
|
||||
ZLFile imageFile(myCoverFileName);
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, 0, true);
|
||||
myModelReader.addImage(imageName, new ZLFileImage(imageFile, "", 0));
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
}
|
||||
}
|
||||
|
||||
void OEBBookReader::endElementHandler(const char *tag) {
|
||||
std::string tagString = ZLUnicodeUtil::toLower(tag);
|
||||
|
||||
|
@ -193,6 +197,8 @@ bool OEBBookReader::readBook(const ZLFile &file) {
|
|||
myHtmlFileNames.clear();
|
||||
myNCXTOCFileName.erase();
|
||||
myCoverFileName.erase();
|
||||
myCoverFileType.erase();
|
||||
myCoverMimeType.erase();
|
||||
myTourTOC.clear();
|
||||
myGuideTOC.clear();
|
||||
myState = READ_NONE;
|
||||
|
@ -208,10 +214,13 @@ bool OEBBookReader::readBook(const ZLFile &file) {
|
|||
bool firstFile = true;
|
||||
for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) {
|
||||
const ZLFile xhtmlFile(myFilePrefix + *it);
|
||||
if (firstFile && myCoverFileName == xhtmlFile.path()) {
|
||||
continue;
|
||||
}
|
||||
if (!firstFile) {
|
||||
if (firstFile) {
|
||||
if (myCoverFileName == xhtmlFile.path()) {
|
||||
xhtmlReader.setMarkFirstImageAsCover();
|
||||
} else {
|
||||
addCoverImage();
|
||||
}
|
||||
} else {
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
}
|
||||
xhtmlReader.readFile(xhtmlFile, *it);
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
const std::vector<std::string> &externalDTDs() const;
|
||||
|
||||
void generateTOC(const XHTMLReader &xhtmlReader);
|
||||
void addCoverImage();
|
||||
|
||||
private:
|
||||
enum ReaderState {
|
||||
|
@ -63,6 +64,8 @@ private:
|
|||
std::vector<std::string> myHtmlFileNames;
|
||||
std::string myNCXTOCFileName;
|
||||
std::string myCoverFileName;
|
||||
std::string myCoverFileType;
|
||||
std::string myCoverMimeType;
|
||||
std::vector<std::pair<std::string,std::string> > myTourTOC;
|
||||
std::vector<std::pair<std::string,std::string> > myGuideTOC;
|
||||
};
|
||||
|
|
|
@ -218,8 +218,9 @@ void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattribut
|
|||
return;
|
||||
}
|
||||
|
||||
ZLLogger::Instance().println("CSS", "style file: " + reader.myPathPrefix + MiscUtil::decodeHtmlURL(href));
|
||||
shared_ptr<ZLInputStream> cssStream = ZLFile(reader.myPathPrefix + MiscUtil::decodeHtmlURL(href)).inputStream();
|
||||
const std::string cssFilePath = reader.myPathPrefix + MiscUtil::decodeHtmlURL(href);
|
||||
ZLLogger::Instance().println("CSS", "style file: " + cssFilePath);
|
||||
shared_ptr<ZLInputStream> cssStream = ZLFile(cssFilePath).inputStream();
|
||||
if (cssStream.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
@ -307,8 +308,9 @@ void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattribu
|
|||
endParagraph(reader);
|
||||
}
|
||||
const std::string imageName = imageFile.name(false);
|
||||
bookReader(reader).addImageReference(imageName, 0, false);
|
||||
bookReader(reader).addImageReference(imageName, 0, reader.myMarkNextImageAsCover);
|
||||
bookReader(reader).addImage(imageName, new ZLFileImage(imageFile, "", 0));
|
||||
reader.myMarkNextImageAsCover = false;
|
||||
if (flag) {
|
||||
beginParagraph(reader);
|
||||
}
|
||||
|
@ -516,6 +518,11 @@ void XHTMLReader::fillTagTable() {
|
|||
}
|
||||
|
||||
XHTMLReader::XHTMLReader(BookReader &modelReader) : myModelReader(modelReader) {
|
||||
myMarkNextImageAsCover = false;
|
||||
}
|
||||
|
||||
void XHTMLReader::setMarkFirstImageAsCover() {
|
||||
myMarkNextImageAsCover = true;
|
||||
}
|
||||
|
||||
bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName) {
|
||||
|
@ -588,7 +595,6 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
|
|||
shared_ptr<ZLTextStyleEntry> entry = myStyleParser->parseString(style);
|
||||
myModelReader.addStyleEntry(*entry);
|
||||
myStyleEntryStack.push_back(entry);
|
||||
} else {
|
||||
}
|
||||
myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore);
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
bool readFile(const ZLFile &file, const std::string &referenceName);
|
||||
const std::string &fileAlias(const std::string &fileName) const;
|
||||
const std::string normalizedReference(const std::string &reference) const;
|
||||
void setMarkFirstImageAsCover();
|
||||
|
||||
private:
|
||||
XHTMLTagAction *getAction(const std::string &tag);
|
||||
|
@ -104,6 +105,7 @@ private:
|
|||
READ_BODY
|
||||
} myReadState;
|
||||
int myBodyCounter;
|
||||
bool myMarkNextImageAsCover;
|
||||
|
||||
friend class XHTMLTagAction;
|
||||
friend class XHTMLTagStyleAction;
|
||||
|
@ -113,6 +115,7 @@ private:
|
|||
friend class XHTMLTagParagraphAction;
|
||||
friend class XHTMLTagBodyAction;
|
||||
friend class XHTMLTagRestartParagraphAction;
|
||||
friend class XHTMLTagImageAction;
|
||||
};
|
||||
|
||||
#endif /* __XHTMLREADER_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue