1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +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

@ -9,10 +9,10 @@ litres: author photos
DONE rtf: images DONE rtf: images
* rtf: underline & strikethrough * rtf: underline & strikethrough
* native fb2 plugin: images * native fb2 plugin: images
* native fb2 plugin: links
* native fb2 plugin: underline * native fb2 plugin: underline
* native fb2 plugin: strikethrough * native fb2 plugin: strikethrough
* native fb2 plugin: cover * native fb2 plugin: cover
* native fb2 plugin: cover in text
* rtf: cover? * rtf: cover?
* better brightness setting: no black screen, brightness "lower than system" (decrease color brightness) * better brightness setting: no black screen, brightness "lower than system" (decrease color brightness)

View file

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

View file

@ -24,7 +24,6 @@
#include "../../bookmodel/BookReader.h" #include "../../bookmodel/BookReader.h"
class BookModel; class BookModel;
//class ZLBase64EncodedImage;
class FB2BookReader : public FB2Reader { class FB2BookReader : public FB2Reader {
@ -46,10 +45,8 @@ private:
bool myInsidePoem; bool myInsidePoem;
BookReader myModelReader; BookReader myModelReader;
//ZLBase64EncodedImage *myCurrentImage; int myCurrentImageStart;
std::string myCurrentImageId; std::string myCurrentImageId;
bool myProcessingImage;
std::vector<std::string> myImageBuffer;
bool mySectionStarted; bool mySectionStarted;
bool myInsideTitle; bool myInsideTitle;

View file

@ -31,6 +31,7 @@ public class ZLFileImage extends ZLSingleImage {
public static final String ENCODING_NONE = ""; public static final String ENCODING_NONE = "";
public static final String ENCODING_HEX = "hex"; public static final String ENCODING_HEX = "hex";
public static final String ENCODING_BASE64 = "base64";
public static ZLFileImage byUrlPath(String urlPath) { public static ZLFileImage byUrlPath(String urlPath) {
try { try {