mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
cover loading in fb2 native plugin
This commit is contained in:
parent
79a06410ae
commit
1f63a57f17
12 changed files with 88 additions and 57 deletions
|
@ -17,9 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <ZLFile.h>
|
||||
#include <ZLImage.h>
|
||||
//#include <ZLBase64EncodedImage.h>
|
||||
#include <ZLFileImage.h>
|
||||
|
||||
#include "FB2CoverReader.h"
|
||||
|
||||
|
@ -30,8 +28,12 @@ FB2CoverReader::FB2CoverReader(const ZLFile &file) : myFile(file) {
|
|||
|
||||
shared_ptr<ZLImage> FB2CoverReader::readCover() {
|
||||
myReadCoverPage = false;
|
||||
myImageReference.erase();
|
||||
myLookForImage = false;
|
||||
myImageId.erase();
|
||||
myImageStart = -1;
|
||||
|
||||
readDocument(myFile);
|
||||
|
||||
return myImage;
|
||||
}
|
||||
|
||||
|
@ -45,7 +47,7 @@ void FB2CoverReader::startElementHandler(int tag, const char **attributes) {
|
|||
const std::string hrefName = xlinkNamespace() + ":href";
|
||||
const char *ref = attributeValue(attributes, hrefName.c_str());
|
||||
if (ref != 0 && *ref == '#' && *(ref + 1) != '\0') {
|
||||
myImageReference = ref + 1;
|
||||
myImageId = ref + 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -53,8 +55,8 @@ void FB2CoverReader::startElementHandler(int tag, const char **attributes) {
|
|||
{
|
||||
const char *id = attributeValue(attributes, "id");
|
||||
const char *contentType = attributeValue(attributes, "content-type");
|
||||
if (id != 0 && contentType != 0 && myImageReference == id) {
|
||||
//myImage = new ZLBase64EncodedImage(contentType);
|
||||
if (id != 0 && contentType != 0 && myImageId == id) {
|
||||
myLookForImage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,18 +68,13 @@ void FB2CoverReader::endElementHandler(int tag) {
|
|||
myReadCoverPage = false;
|
||||
break;
|
||||
case _DESCRIPTION:
|
||||
if (myImageReference.empty()) {
|
||||
if (myImageId.empty()) {
|
||||
interrupt();
|
||||
}
|
||||
break;
|
||||
case _BINARY:
|
||||
if (!myImage.isNull()) {
|
||||
if (!myImageBuffer.empty()) {
|
||||
//((ZLBase64EncodedImage&)*myImage).addData(myImageBuffer);
|
||||
myImageBuffer.clear();
|
||||
} else {
|
||||
myImage = 0;
|
||||
}
|
||||
if (!myImageId.empty() && myImageStart >= 0) {
|
||||
myImage = new ZLFileImage(myFile, "base64", myImageStart, getCurrentPosition() - myImageStart);
|
||||
interrupt();
|
||||
}
|
||||
break;
|
||||
|
@ -85,7 +82,8 @@ void FB2CoverReader::endElementHandler(int tag) {
|
|||
}
|
||||
|
||||
void FB2CoverReader::characterDataHandler(const char *text, size_t len) {
|
||||
if (len > 0 && !myImage.isNull()) {
|
||||
myImageBuffer.push_back(std::string(text, len));
|
||||
if (len > 0 && myLookForImage) {
|
||||
myImageStart = getCurrentPosition();
|
||||
myLookForImage = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue