1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

native fb2 images support (in progress)

This commit is contained in:
Nikolay Pultsin 2012-03-27 02:56:19 +01:00
parent a213154b62
commit 42e15f1a0b
4 changed files with 22 additions and 23 deletions

View file

@ -22,7 +22,7 @@
#include <ZLInputStream.h>
#include <ZLStringUtil.h>
//#include <ZLBase64EncodedImage.h>
#include <ZLFileImage.h>
#include <ZLTextParagraph.h>
@ -37,17 +37,18 @@ FB2BookReader::FB2BookReader(BookModel &model) : myModelReader(model) {
mySectionDepth = 0;
myBodyCounter = 0;
myReadMainText = false;
//myCurrentImage = 0;
myProcessingImage = false;
myCurrentImageStart = -1;
mySectionStarted = false;
myInsideTitle = false;
}
void FB2BookReader::characterDataHandler(const char *text, size_t len) {
if ((len > 0) && (myProcessingImage || myModelReader.paragraphIsOpen())) {
if ((len > 0) && (!myCurrentImageId.empty() || myModelReader.paragraphIsOpen())) {
std::string str(text, len);
if (myProcessingImage) {
myImageBuffer.push_back(str);
if (!myCurrentImageId.empty()) {
if (myCurrentImageStart == -1) {
myCurrentImageStart = getCurrentPosition();
}
} else {
myModelReader.addData(str);
if (myInsideTitle) {
@ -183,13 +184,13 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
{
const std::string hrefName = xlinkNamespace() + ":href";
const char *ref = attributeValue(xmlattributes, hrefName.c_str());
//const char *vOffset = attributeValue(xmlattributes, "voffset");
//char offset = (vOffset != 0) ? atoi(vOffset) : 0;
const char *vOffset = attributeValue(xmlattributes, "voffset");
char offset = (vOffset != 0) ? atoi(vOffset) : 0;
if ((ref != 0) && (*ref == '#')) {
++ref;
if ((myCoverImageReference != ref) ||
(myParagraphsBeforeBodyNumber != myModelReader.model().bookTextModel()->paragraphsNumber())) {
//myModelReader.addImageReference(ref);
myModelReader.addImageReference(ref, offset, false);
}
if (myInsideCoverpage) {
myCoverImageReference = ref;
@ -202,9 +203,7 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
static const std::string STRANGE_MIME_TYPE = "text/xml";
const char *contentType = attributeValue(xmlattributes, "content-type");
if ((contentType != 0) && (id != 0) && (STRANGE_MIME_TYPE != contentType)) {
//myCurrentImage = new ZLBase64EncodedImage(contentType);
myCurrentImageId.assign(id);
myProcessingImage = true;
}
break;
}
@ -302,14 +301,16 @@ void FB2BookReader::endElementHandler(int tag) {
myModelReader.addControl(myHyperlinkType, false);
break;
case _BINARY:
if (!myImageBuffer.empty() && !myCurrentImageId.empty() /*&& myCurrentImage != 0*/) {
//myCurrentImage->addData(myImageBuffer);
//myModelReader.addImage(myCurrentImageId, myCurrentImage);
myImageBuffer.clear();
myCurrentImageId.clear();
//myCurrentImage = 0;
if (!myCurrentImageId.empty() && myCurrentImageStart != -1) {
myModelReader.addImage(myCurrentImageId, new ZLFileImage(
myModelReader.model().book()->file(),
"base64",
myCurrentImageStart,
getCurrentPosition()
));
}
myProcessingImage = false;
myCurrentImageId.clear();
myCurrentImageStart = -1;
break;
case _BODY:
myModelReader.popKind();