mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
RTF images support: finished
This commit is contained in:
parent
cbcfe14f18
commit
4d90732a37
3 changed files with 31 additions and 15 deletions
|
@ -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;
|
||||
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<std::string, RtfCommand*>::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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -50,6 +50,7 @@ public class HexInputStream extends InputStream {
|
|||
++skipped;
|
||||
}
|
||||
}
|
||||
if (skipped < 2 * n) {
|
||||
fillBuffer();
|
||||
available = myBufferLength;
|
||||
if (available == -1) {
|
||||
|
@ -57,6 +58,7 @@ public class HexInputStream extends InputStream {
|
|||
}
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
myBufferLength = available;
|
||||
myBufferOffset = offset;
|
||||
return n;
|
||||
|
@ -103,6 +105,7 @@ public class HexInputStream extends InputStream {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (ready < len) {
|
||||
fillBuffer();
|
||||
available = myBufferLength;
|
||||
if (available == -1) {
|
||||
|
@ -110,6 +113,7 @@ public class HexInputStream extends InputStream {
|
|||
}
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
myBufferLength = available;
|
||||
myBufferOffset = offset;
|
||||
return len;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue