diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp index 4ff799a4d..61432d95d 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp @@ -38,6 +38,9 @@ RtfReader::~RtfReader() { RtfCommand::~RtfCommand() { } +void RtfDummyCommand::run(RtfReader&, int*) const { +} + void RtfNewParagraphCommand::run(RtfReader &reader, int*) const { reader.newParagraph(); } @@ -96,6 +99,7 @@ void RtfDestinationCommand::run(RtfReader &reader, int*) const { reader.myState.Destination = myDestination; if (myDestination == RtfReader::DESTINATION_PICTURE) { reader.myState.ReadDataAsHex = true; + reader.myNextImageMimeType.clear(); } reader.switchDestination(myDestination, true); } @@ -158,6 +162,7 @@ void RtfReader::fillKeywordMap() { for (const char **i = keywordsToSkip; *i != 0; ++i) { addAction(*i, skipCommand); } + addAction("shppict", new RtfDummyCommand()); addAction("info", new RtfDestinationCommand(RtfReader::DESTINATION_INFO)); addAction("title", new RtfDestinationCommand(RtfReader::DESTINATION_TITLE)); addAction("author", new RtfDestinationCommand(RtfReader::DESTINATION_AUTHOR)); @@ -260,8 +265,10 @@ bool RtfReader::parseDocument() { dataStart = ptr + 1; if (imageStartOffset >= 0) { - int imageSize = myStream->offset() + (ptr - end) - imageStartOffset; - insertImage(myNextImageMimeType, myFileName, imageStartOffset, imageSize); + if (!myNextImageMimeType.empty()) { + const int imageSize = myStream->offset() + (ptr - end) - imageStartOffset; + insertImage(myNextImageMimeType, myFileName, imageStartOffset, imageSize); + } imageStartOffset = -1; } @@ -399,7 +406,7 @@ bool RtfReader::parseDocument() { } void RtfReader::processKeyword(const std::string &keyword, int *parameter) { - bool wasSpecialMode = mySpecialMode; + const bool wasSpecialMode = mySpecialMode; mySpecialMode = false; if (myState.Destination == RtfReader::DESTINATION_SKIP) { return; @@ -408,15 +415,15 @@ void RtfReader::processKeyword(const std::string &keyword, int *parameter) { std::map::const_iterator it = ourKeywordMap.find(keyword); if (it == ourKeywordMap.end()) { - if (wasSpecialMode) + if (wasSpecialMode) { myState.Destination = RtfReader::DESTINATION_SKIP; + } return; } it->second->run(*this, parameter); } - void RtfReader::processCharData(const char *data, size_t len, bool convert) { if (myState.Destination != RtfReader::DESTINATION_SKIP) { addCharData(data, len, convert); diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h index bd0b89667..428f69e2e 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h @@ -130,6 +130,11 @@ public: virtual void run(RtfReader &reader, int *parameter) const = 0; }; +class RtfDummyCommand : public RtfCommand { +public: + void run(RtfReader &reader, int *parameter) const; +}; + class RtfNewParagraphCommand : public RtfCommand { public: void run(RtfReader &reader, int *parameter) const; diff --git a/src/org/geometerplus/zlibrary/core/util/HexInputStream.java b/src/org/geometerplus/zlibrary/core/util/HexInputStream.java index bf17cd2f8..ec1bec5bf 100644 --- a/src/org/geometerplus/zlibrary/core/util/HexInputStream.java +++ b/src/org/geometerplus/zlibrary/core/util/HexInputStream.java @@ -50,12 +50,14 @@ public class HexInputStream extends InputStream { ++skipped; } } - fillBuffer(); - available = myBufferLength; - if (available == -1) { - return skipped / 2; + if (skipped < 2 * n) { + fillBuffer(); + available = myBufferLength; + if (available == -1) { + return skipped / 2; + } + offset = 0; } - offset = 0; } myBufferLength = available; myBufferOffset = offset; @@ -103,12 +105,14 @@ public class HexInputStream extends InputStream { } } } - fillBuffer(); - available = myBufferLength; - if (available == -1) { - return ready == 0 ? -1 : ready; + if (ready < len) { + fillBuffer(); + available = myBufferLength; + if (available == -1) { + return ready == 0 ? -1 : ready; + } + offset = 0; } - offset = 0; } myBufferLength = available; myBufferOffset = offset;